পাইথনে একটি ডুয়াল থ্রাস্ট ডিজিটাল মুদ্রা পরিমাণগত ট্রেডিং কৌশল বাস্তবায়ন করুন

লেখক:লিডিয়া, তৈরিঃ ২০২৩-০১-১০ ১৭ঃ০৭ঃ৪৯, আপডেটঃ ২০২৩-০৯-২০ ১০ঃ৫৩ঃ৪৮

img

পাইথনে একটি ডুয়াল থ্রাস্ট ডিজিটাল মুদ্রা পরিমাণগত ট্রেডিং কৌশল বাস্তবায়ন করুন

ডুয়াল থ্রাস্ট ট্রেডিং অ্যালগরিদমের ভূমিকা

ডাবল থ্রাস্ট ট্রেডিং অ্যালগরিদম হল মাইকেল চ্যালেক দ্বারা বিকাশিত একটি বিখ্যাত পরিমাণগত ট্রেডিং কৌশল। এটি সাধারণত ফিউচার, বৈদেশিক মুদ্রা এবং স্টক মার্কেটে ব্যবহৃত হয়। ডাবল থ্রাস্টের ধারণাটি একটি সাধারণ অগ্রগতি ট্রেডিং সিস্টেম। এটি historical ডাবল থ্রাস্ট সিস্টেম ব্যবহার করে historicalতিহাসিক দামের উপর ভিত্তি করে একটি আপডেট ব্যাকট্র্যাকিং সময়কাল তৈরি করে, যা তাত্ত্বিকভাবে এটিকে যে কোনও নির্দিষ্ট সময়ের মধ্যে আরও স্থিতিশীল করে তোলে।

এই নিবন্ধে, আমরা এই কৌশলটির বিশদ যৌক্তিক বিবরণ দিই এবং এই অ্যালগরিদমটি কীভাবে এফএমজেড কোয়ান্ট প্ল্যাটফর্মে বাস্তবায়ন করব তা দেখাই। প্রথমত, আমাদের ট্রেড করার জন্য বিষয়টির historicalতিহাসিক মূল্য নির্বাচন করতে হবে। এই ব্যাপ্তিটি শেষ এন দিনের বন্ধের মূল্য, সর্বোচ্চ মূল্য এবং সর্বনিম্ন মূল্যের ভিত্তিতে গণনা করা হয়। যখন বাজারটি খোলার দাম থেকে একটি নির্দিষ্ট পরিসরে চলে যায়, তখন অবস্থানটি খুলুন।

আমরা দুটি সাধারণ বাজার অবস্থার অধীনে একটি একক ট্রেডিং জোড়ার সাথে এই কৌশলটি পরীক্ষা করেছি, যথা ট্রেন্ড মার্কেট এবং শক মার্কেট। ফলাফলগুলি দেখিয়েছে যে প্রবণতা বাজারে গতির ট্রেডিং সিস্টেম আরও ভাল কাজ করে এবং এটি অস্থির বাজারে কিছু অবৈধ ট্রেডিং সংকেত সক্রিয় করবে। ব্যবধান বাজারে, আমরা আরও ভাল রিটার্ন অর্জনের জন্য পরামিতিগুলি সামঞ্জস্য করতে পারি। পৃথক রেফারেন্স ট্রেডিং লক্ষ্যগুলির তুলনা হিসাবে, আমরা দেশীয় পণ্য ফিউচার বাজারেরও পরীক্ষা করেছি। ফলাফল দেখিয়েছে যে কৌশলটি গড় পারফরম্যান্সের চেয়ে ভাল।

ডিটি কৌশল নীতি

এর যৌক্তিক প্রোটোটাইপ একটি সাধারণ ইনট্রাডে ট্রেডিং কৌশল। ওপেনিং রেঞ্জের অগ্রগতি কৌশলটি উপরের এবং নীচের ট্র্যাকগুলি নির্ধারণের জন্য আজকের উদ্বোধনী মূল্যের সাথে গতকালের পরিসরের একটি নির্দিষ্ট শতাংশ বা বিয়োগের উপর ভিত্তি করে। যখন দামটি উপরের ট্র্যাকটি ক্রস করে, এটি কেনার জন্য তার অবস্থান খুলবে এবং যখন এটি নীচের ট্র্যাকটি ভেঙে দেয়, তখন এটি শর্ট যাওয়ার জন্য তার অবস্থান খুলবে।

কৌশল নীতি

  • ক্লোজিংয়ের পরে, দুটি মান গণনা করা হয়ঃ সর্বোচ্চ মূল্য - ক্লোজিং মূল্য, এবং ক্লোজিং মূল্য - সর্বনিম্ন মূল্য। তারপর দুটি মানের বৃহত্তর নিতে এবং 0.7 দ্বারা মান গুণ করুন। আসুন এটি মান কে কল, যা আমরা ট্রিগার মান কল।

  • পরের দিন বাজার খোলার পর, খোলার মূল্য রেকর্ড করুন এবং যখন দামটি অতিক্রম করে তখন অবিলম্বে কিনুন (খোলার মূল্য + ট্রিগার মান), অথবা যখন দামটি কম হয় তখন শর্ট পজিশন বিক্রি করুন (খোলার মূল্য - ট্রিগার মান) ।

  • এই কৌশলটির কোনও সুস্পষ্ট স্টপ লস নেই। এই সিস্টেমটি একটি বিপরীত সিস্টেম, অর্থাৎ, যখন দাম অতিক্রম করে (খোলার মূল্য + ট্রিগার মান) তখন যদি একটি শর্ট পজিশন অর্ডার থাকে তবে এটি দুটি কেনার অর্ডার প্রেরণ করবে (একটি ভুল অবস্থান বন্ধ করে, অন্যটি সঠিক অবস্থানটি খোলে) । একই কারণে, যদি একটি লং পজিশনের দাম (খোলার মূল্য - ট্রিগার মান) এর চেয়ে কম হয় তবে এটি দুটি বিক্রয় অর্ডার প্রেরণ করবে।

ডিটি কৌশলটির গাণিতিক প্রকাশ

পরিসীমা = সর্বোচ্চ (HH-LC, HC-LL)

লং পজিশন সিগন্যাল গণনার পদ্ধতি হলঃ

ক্যাপ = খোলা + কে১ × রেঞ্জক্যাপ = খোলা + কে১ × রেঞ্জ

শর্ট পজিশনের সিগন্যাল গণনার পদ্ধতি হলঃ

মেঝে = খোলা K2 × Rangefloor = খোলা K2 × Range

যেখানে K1 এবং K2 পরামিতি। যখন K1 K2 এর চেয়ে বড় হয়, তখন লং পজিশন সিগন্যালটি ট্রিগার হয় এবং বিপরীতভাবে। প্রদর্শনের জন্য, আমরা K1=K2=0.5 নির্বাচন করি। প্রকৃত লেনদেনে, আমরা এখনও এই পরামিতিগুলি অনুকূল করতে বা বাজারের প্রবণতা অনুযায়ী পরামিতিগুলি সামঞ্জস্য করতে historicalতিহাসিক ডেটা ব্যবহার করতে পারি। যদি আপনি উত্থানবাদী হন তবে K1 K2 এর চেয়ে কম হওয়া উচিত। যদি আপনি হ্রাসকারী হন তবে K1 K2 এর চেয়ে বড় হওয়া উচিত।

img

এই সিস্টেমটি একটি বিপরীতমুখী সিস্টেম। অতএব, যদি বিনিয়োগকারীরা শর্ট পজিশন ধরে রাখে যখন দামটি উপরের ট্র্যাকটি ক্রস করে, তবে তাদের লং পজিশন খোলার আগে শর্ট পজিশনগুলি বন্ধ করা উচিত। যদি কোনও বিনিয়োগকারী যখন দামটি নীচের ট্র্যাকটি ভেঙে দেয় তখন দীর্ঘ পজিশন ধরে রাখে তবে তাদের নতুন শর্ট পজিশন খোলার আগে দীর্ঘ পজিশনটি বন্ধ করা উচিত।

ডিটি কৌশল উন্নত করাঃ

পরিসীমা সেটিংয়ে, পূর্ববর্তী এন দিনের চারটি মূল্য পয়েন্ট (উচ্চ, খোলা, নিম্ন এবং বন্ধ) চালু করা হয় যাতে পরিসীমাটি একটি নির্দিষ্ট সময়ের মধ্যে অপেক্ষাকৃত স্থিতিশীল হয়, যা দৈনিক প্রবণতা ট্র্যাকিংয়ের জন্য প্রয়োগ করা যেতে পারে।

কৌশলটির লং এবং শর্ট পজিশন খোলার ট্রিগার শর্তগুলি, অসামত্রিক পরিসীমা বিবেচনা করে, দীর্ঘ এবং সংক্ষিপ্ত লেনদেনের রেফারেন্স পরিসীমাটি বিভিন্ন সময়ের সংখ্যা নির্বাচন করা উচিত, যা প্যারামিটার K1 এবং K2 দ্বারাও নির্ধারিত হতে পারে। যখন K1 < K2 হয়, তখন লং পজিশন সংকেতটি তুলনামূলকভাবে সহজেই ট্রিগার করা হয়, যখন K1 > K2 হয়, তখন শর্ট পজিশন সংকেতটি তুলনামূলকভাবে সহজেই ট্রিগার করা হয়।

অতএব, এই কৌশলটি ব্যবহার করার সময়, একদিকে, আপনি ঐতিহাসিক ডেটা ব্যাকটেস্টিংয়ের সেরা পরামিতিগুলি উল্লেখ করতে পারেন। অন্যদিকে, আপনি ভবিষ্যতের বা অন্যান্য প্রধান সময়ের প্রযুক্তিগত সূচকগুলির আপনার বিচারের ভিত্তিতে ধাপে ধাপে K1 এবং K2 সামঞ্জস্য করতে পারেন।

এটি একটি সাধারণ ট্রেডিং পদ্ধতি যেখানে সিগন্যালের জন্য অপেক্ষা করা হয়, বাজারে প্রবেশ করা হয়, আরবিট্রেজ করা হয়, এবং তারপর বাজার থেকে বেরিয়ে আসা হয়, কিন্তু এর প্রভাব চমৎকার।

FMZ Quant প্ল্যাটফর্মে ডিটি কৌশল প্রয়োগ করুন

আমরা খুলছিFMZ.COM, অ্যাকাউন্টে লগ ইন করুন, ড্যাশবোর্ডে ক্লিক করুন, এবং ডকার এবং রোবট স্থাপন করুন।

দয়া করে আমার আগের নিবন্ধটি দেখুন কিভাবে একটি ডকার এবং রোবট স্থাপন করবেনঃhttps://www.fmz.com/bbs-topic/9864.

যারা নিজের ক্লাউড কম্পিউটিং সার্ভার ক্রয় করতে চান তারা এই নিবন্ধটি দেখতে পারেনঃhttps://www.fmz.com/digest-topic/5711.

এরপর, আমরা বাম কলামে কৌশল লাইব্রেরিতে ক্লিক করি এবং কৌশল যোগ করুন ক্লিক করি।

মনে রাখবেন, চিত্রের মত, কৌশল সম্পাদনা পৃষ্ঠার উপরের ডানদিকে পাইথন হিসাবে প্রোগ্রামিং ভাষা নির্বাচন করুনঃ

img

পরবর্তী, আমরা কোড সম্পাদনা পৃষ্ঠায় পাইথন কোড লিখতে হবে. নিম্নলিখিত কোড লাইন দ্বারা লাইন মন্তব্য খুব বিস্তারিত আছে, আপনি বুঝতে আপনার সময় নিতে পারেন.

আমরা OKCoin ফিউচার ব্যবহার করে কৌশলটি পরীক্ষা করব:

import time # Here we need to introduce the time library that comes with python, which will be used later in the program.

class Error_noSupport(BaseException): # We define a global class named ChartCfg to initialize the strategy chart settings. Object has many attributes about the chart function. Chart library: HighCharts.
    def __init__(self): # log out prompt messages
        Log("Support OKCoin Futures only! #FF0000")

class Error_AtBeginHasPosition(BaseException):
    def __init__(self):
        Log("Start with a futures position! #FF0000")

ChartCfg = {
    '__isStock': True, # This attribute is used to control whether to display a single control data series (you can cancel the display of a single data series on the chart). If you specify __isStock: false, it will be displayed as a normal chart.
    'title': { # title is the main title of the chart
        'text': 'Dual Thrust upper and bottom track chart' # An attribute of the title text is the text of the title, here set to 'Dual Thrust upper and bottom track chart' the text will be displayed in the title position.
    },
    'yAxis': { # Settings related to the Y-axis of the chart coordinate.
        'plotLines': [{ # Horizontal lines on the Y-axis (perpendicular to the Y-axis), the value of this attribute is an array, i.e. the setting of multiple horizontal lines.
            'value': 0, # Coordinate value of horizontal line on Y-axis
            'color': 'red', # Color of horizontal line
            'width': 2, # Line width of horizontal line
            'label': {  # Labels on the horizontal line
                'text': 'Upper track', # Text of the label
                'align': 'center' # The display position of the label, here set to center (i.e.: 'center')
            }, 
        }, {       # The second horizontal line ([{...} , {...}] the second element in the array)
            'value': 0, # Coordinate value of horizontal line on Y-axis
            'color': 'green', # Color of horizontal line
            'width': 2,  # Line width of horizontal line
            'label': { # Label
                'text': 'bottom track',
                'align': 'center'
            },
        }]
    },
    'series': [{ # Data series, that is, data used to display data lines, K-lines, tags, and other contents on the chart. It is also an array whose first index is 0.
        'type': 'candlestick', # Type of data series with index 0: 'candlestick' indicates a K-line chart.
        'name': 'Current period',  # Name of the data series
        'id': 'primary', # The ID of the data series, which is used for the related settings of the next data series.
        'data': []  # An array of data series to store specific K-line data
    }, {
        'type': 'flags',  # Data series, type: 'flags', display labels on the chart, indicating going long and going short. Index is 1.
        'onSeries': 'primary',  # This attribute indicates that the label is displayed on id 'primary'.
        'data': []    # The array that holds the label data.
    }] 
}

STATE_IDLE = 0  # Status constants, indicating idle
STATE_LONG = 1 # Status constants, indicating long positions
STATE_SHORT = 2 # Status constants, indicating short positions
State = STATE_IDLE # Indicates the current program status, assigned as idle initially

LastBarTime = 0  # The time stamp of the last column of the K-line (in milliseconds, 1000 milliseconds is equal to 1 second, and the timestamp is the number of milliseconds from January 1, 1970 to the present time is a large positive integer).
UpTrack = 0   # Upper track value
BottomTrack = 0 # Bottom track value
chart = None # It is used to accept the chart control object returned by the Chart API function. Use this object (chart) to call its member function to write data to the chart.
InitAccount = None # Initial account status
LastAccount = None # Latest account status
Counter = { # Counters for recording profit and loss counts
    'w': 0, # Number of wins
    'l': 0  # Number of losses
}

def GetPosition(posType):  # Define a function to store account position information
    positions = exchange.GetPosition() # exchange.GetPosition() is the FMZ Quant official API. For its usage, please refer to the official API document: https://www.fmz.com/api.
    return [{'Price': position['Price'], 'Amount': position['Amount']} for position in positions if position['Type'] == posType] # Return to various position information

def CancelPendingOrders(): # Define a function specifically for withdrawing orders
    while True: # Loop check
        orders = exchange.GetOrders() # If there is a position
        [exchange.CancelOrder(order['Id']) for order in orders if not Sleep(500)] # Withdrawal statement
        if len(orders) == 0: # Logical judgment
            break 

def Trade(currentState,nextState): # Define a function to determine the order placement logic.
    global InitAccount,LastAccount,OpenPrice,ClosePrice # Define the global scope
    ticker = _C(exchange.GetTicker) # For the usage of _C, please refer to: https://www.fmz.com/api.
    slidePrice = 1 # Define the slippage value
    pfn = exchange.Buy if nextState == STATE_LONG else exchange.Sell # Buying and selling judgment logic
    if currentState != STATE_IDLE: # Loop start
        Log(_C(exchange.GetPosition)) # Log information 
        exchange.SetDirection("closebuy" if currentState == STATE_LONG else "closesell") # Adjust the order direction, especially after placing the order.
        while True:
            ID = pfn( (ticker['Last'] - slidePrice) if currentState == STATE_LONG else (ticker['Last'] + slidePrice), AmountOP) # Price limit order, ID=pfn (- 1, AmountOP) is the market price order, ID=pfn (AmountOP) is the market price order.
            Sleep(Interval) # Take a break to prevent the API from being accessed too often and your account being blocked.
            Log(exchange.GetOrder(ID)) # Log information
            ClosePrice = (exchange.GetOrder(ID))['AvgPrice'] # Set the closing price
            CancelPendingOrders() # Call the withdrawal function
            if len(GetPosition(PD_LONG if currentState == STATE_LONG else PD_SHORT)) == 0: # Order withdrawal logic
                break 
        account = exchange.GetAccount() # Get account information
        if account['Stocks'] > LastAccount['Stocks']: # If the current account currency value is greater than the previous account currency value.
            Counter['w'] += 1 # In the profit and loss counter, add one to the number of profits.
        else:
            Counter['l'] += 1 # Otherwise, add one to the number of losses.
        Log(account) # log information
        LogProfit((account['Stocks'] - InitAccount['Stocks']),"Return rates:", ((account['Stocks'] - InitAccount['Stocks']) * 100 / InitAccount['Stocks']),'%')
        Cal(OpenPrice,ClosePrice)
        LastAccount = account 
    
    exchange.SetDirection("buy" if nextState == STATE_LONG else "sell") # The logic of this part is the same as above and will not be elaborated.
    Log(_C(exchange.GetAccount))
    while True:
        ID = pfn( (ticker['Last'] + slidePrice) if nextState == STATE_LONG else (ticker['Last'] - slidePrice), AmountOP) 
        Sleep(Interval)
        Log(exchange.GetOrder(ID)) 
        CancelPendingOrders()
        pos = GetPosition(PD_LONG if nextState == STATE_LONG else PD_SHORT)
        if len(pos) != 0:
            Log("Average price of positions",pos[0]['Price'],"Amount:",pos[0]['Amount'])
            OpenPrice = (exchange.GetOrder(ID))['AvgPrice']
            Log("now account:",exchange.GetAccount())
            break 

def onTick(exchange): # The main function of the program, within which the main logic of the program is processed.
    global LastBarTime,chart,State,UpTrack,DownTrack,LastAccount # Define the global scope
    records = exchange.GetRecords() # For the usage of exchange.GetRecords(), please refer to: https://www.fmz.com/api.
    if not records or len(records) <= NPeriod: # Judgment statements to prevent accidents.
        return 
    Bar = records[-1] # Take the penultimate element of records K-line data, that is, the last bar.
    if LastBarTime != Bar['Time']:
        HH = TA.Highest(records, NPeriod, 'High')  # Declare the HH variable, call the TA.Highest function to calculate the maximum value of the highest price in the current K-line data NPeriod period and assign it to HH.
        HC = TA.Highest(records, NPeriod, 'Close') # Declare the HC variable to get the maximum value of the closing price in the NPeriod period.
        LL = TA.Lowest(records, NPeriod, 'Low') # Declare the LL variable to get the minimum value of the lowest price in the NPeriod period.
        LC = TA.Lowest(records, NPeriod, 'Close') # Declare LC variable to get the minimum value of the closing price in the NPeriod period. For specific TA-related applications, please refer to the official API documentation.
        
        Range = max(HH - LC, HC - LL)  # Calculate the range 
        UpTrack = _N(Bar['Open'] + (Ks * Range))  # The upper track value is calculated based on the upper track factor Ks of the interface parameters such as the opening price of the latest K-line bar.
        DownTrack = _N(Bar['Open'] - (Kx * Range)) # Calculate the down track value
        if LastBarTime > 0: # Because the value of LastBarTime initialization is set to 0, LastBarTime>0 must be false when running here for the first time. The code in the if block will not be executed, but the code in the else block will be executed.
            PreBar = records[-2] # Declare a variable means "the previous Bar" assigns the value of the penultimate Bar of the current K-line to it.
            chart.add(0, [PreBar['Time'], PreBar['Open'], PreBar['High'], PreBar['Low'], PreBar['Close']], -1) # Call the add function of the chart icon control class to update the K-line data (use the penultimate bar of the obtained K-line data to update the last bar of the icon, because a new K-line bar is generated).
        else:  # For the specific usage of the chart.add function, see the API documentation and the articles in the forum. When the program runs for the first time, it must execute the code in the else block. The main function is to add all the K-lines obtained for the first time to the chart at one time.
            for i in range(len(records) - min(len(records), NPeriod * 3), len(records)): # Here, a for loop is executed. The number of loops uses the minimum of the K-line length and 3 times the NPeriod, which can ensure that the initial K-line will not be drawn too much and too long. Indexes vary from large to small.
                b = records[i] # Declare a temporary variable b to retrieve the K-line bar data with the index of records.length - i for each loop.
                chart.add(0,[b['Time'], b['Open'], b['High'], b['Low'], b['Close']]) # Call the chart.add function to add a K-line bar to the chart. Note that if the last parameter of the add function is passed in -1, it will update the last Bar (column) on the chart. If no parameter is passed in, it will add Bar to the last. After executing the loop of i=2 (i-- already, now it's 1), it will trigger i > 1 for false to stop the loop. It can be seen that the code here only processes the bar of records.length - 2, and the last Bar is not processed.                
        chart.add(0,[Bar['Time'], Bar['Open'], Bar['High'], Bar['Low'], Bar['Close']]) # Since the two branches of the above if do not process the bar of records.length - 1, it is processed here. Add the latest Bar to the chart.
        ChartCfg['yAxis']['plotLines'][0]['value'] = UpTrack  # Assign the calculated upper track value to the chart object (different from the chart control object chart) for later display.
        ChartCfg['yAxis']['plotLines'][1]['value'] = DownTrack # Assign lower track value
        ChartCfg['subtitle'] = { # Set subtitle
            'text': 'upper tarck' + str(UpTrack) + 'down track' + str(DownTrack) # Subtitle text setting. The upper and down track values are displayed on the subtitle.
        }
        chart.update(ChartCfg) # Update charts with chart class ChartCfg.
        chart.reset(PeriodShow) # Refresh the PeriodShow variable set according to the interface parameters, and only keep the K-line bar of the number of PeriodShow values.
        
        LastBarTime = Bar['Time'] # The timestamp of the newly generated Bar is updated to LastBarTime to determine whether the last Bar of the K-line data acquired in the next loop is a newly generated one.
    else: # If LastBarTime is equal to Bar.Time, that is, no new K-line Bar is generated. Then execute the code in {..}.
        chart.add(0,[Bar['Time'], Bar['Open'], Bar['High'], Bar['Low'], Bar['Close']], -1) # Update the last K-line bar on the chart with the last Bar of the current K-line data (the last Bar of the K-line, i.e. the Bar of the current period, is constantly changing).        
    LogStatus("Price:", Bar["Close"], "up:", UpTrack, "down:", DownTrack, "wins:", Counter['w'], "losses:", Counter['l'], "Date:", time.time()) # The LogStatus function is called to display the data of the current strategy on the status bar.
    msg = "" # Define a variable msg.
    if State == STATE_IDLE or State == STATE_SHORT: # Judge whether the current state variable State is equal to idle or whether State is equal to short position. In the idle state, it can trigger long position, and in the short position state, it can trigger a long position to be closed and sell the opening position.
        if Bar['Close'] >= UpTrack: # If the closing price of the current K-line is greater than the upper track value, execute the code in the if block.
            msg = "Go long, trigger price:" + str(Bar['Close']) + "upper track" + str(UpTrack) # Assign a value to msg and combine the values to be displayed into a string.
            Log(msg) # message
            Trade(State, STATE_LONG) # Call the Trade function above to trade.
            State = STATE_LONG # Regardless of opening long positions or selling the opening position, the program status should be updated to hold long positions at the moment.
            chart.add(1,{'x': Bar['Time'], 'color': 'red', 'shape': 'flag', 'title': 'long', 'text': msg}) # Add a marker to the corresponding position of the K-line to show the open long position. 
    
    if State == STATE_IDLE or State == STATE_LONG: # The short direction is the same as the above, and will not be repeated. The code is exactly the same.
        if Bar['Close'] <= DownTrack:
            msg = "Go short, trigger price:" + str(Bar['Close']) + "down track" + str(DownTrack)
            Log(msg)
            Trade(State, STATE_SHORT)
            State = STATE_SHORT
            chart.add(1,{'x': Bar['Time'], 'color': 'green', 'shape': 'circlepin', 'title': 'short', 'text': msg})

OpenPrice = 0 # Initialize OpenPrice and ClosePrice
ClosePrice = 0
def Cal(OpenPrice, ClosePrice): # Define a Cal function to calculate the profit and loss of the strategy after it has been run.
    global AmountOP,State
    if State == STATE_SHORT:
        Log(AmountOP,OpenPrice,ClosePrice,"Profit and loss of the strategy:", (AmountOP * 100) / ClosePrice - (AmountOP * 100) / OpenPrice, "Currencies, service charge:", - (100 * AmountOP * 0.0003), "USD, equivalent to:", _N( - 100 * AmountOP * 0.0003/OpenPrice,8), "Currencies")
        Log(((AmountOP * 100) / ClosePrice - (AmountOP * 100) / OpenPrice) + (- 100 * AmountOP * 0.0003/OpenPrice))
    if State == STATE_LONG:
        Log(AmountOP,OpenPrice,ClosePrice,"Profit and loss of the strategy:", (AmountOP * 100) / OpenPrice - (AmountOP * 100) / ClosePrice, "Currencies, service charge:", - (100 * AmountOP * 0.0003), "USD, equivalent to:", _N( - 100 * AmountOP * 0.0003/OpenPrice,8), "Currencies")
        Log(((AmountOP * 100) / OpenPrice - (AmountOP * 100) / ClosePrice) + (- 100 * AmountOP * 0.0003/OpenPrice))

def main(): # The main function of the strategy program. (entry function)
    global LoopInterval,chart,LastAccount,InitAccount # Define the global scope
    if exchange.GetName() != 'Futures_OKCoin':  # Judge if the name of the added exchange object (obtained by the exchange.GetName function) is not equal to 'Futures_OKCoin', that is, the object added is not OKCoin futures exchange object.
        raise Error_noSupport # Throw an exception
    exchange.SetRate(1) # Set various parameters of the exchange.
    exchange.SetContractType(["this_week","next_week","quarter"][ContractTypeIdx])  # Determine which specific contract to trade.
    exchange.SetMarginLevel([10,20][MarginLevelIdx]) # Set the margin rate, also known as leverage.
    
    if len(exchange.GetPosition()) > 0: # Set up fault tolerance mechanism.
        raise Error_AtBeginHasPosition
    CancelPendingOrders()
    InitAccount = LastAccount = exchange.GetAccount()
    LoopInterval = min(1,LoopInterval)
    Log("Trading platforms:",exchange.GetName(), InitAccount)
    LogStatus("Ready...")
    
    LogProfitReset()
    chart = Chart(ChartCfg)
    chart.reset()
    
    LoopInterval = max(LoopInterval, 1)
    while True: # Loop the whole transaction logic and call the onTick function.
        onTick(exchange)
        Sleep(LoopInterval * 1000) # Take a break to prevent the API from being accessed too frequently and the account from being blocked.

কোড লেখার পরে, দয়া করে মনে রাখবেন যে আমরা পুরো কৌশলটি শেষ করিনি। পরবর্তী, আমাদের কৌশল সম্পাদনা পৃষ্ঠায় কৌশলটিতে ব্যবহৃত পরামিতিগুলি যুক্ত করতে হবে। যোগ করার পদ্ধতিটি খুব সহজ। কৌশল লেখার ডায়ালগ বাক্সের নীচে প্লাস চিহ্নটি ক্লিক করুন একের পর এক যোগ করতে।

img

যোগ করার বিষয়বস্তুঃ

img

এখন পর্যন্ত, আমরা অবশেষে কৌশল লেখার কাজ শেষ করেছি। এরপরে, আসুন কৌশলটি ব্যাকটেস্টিং শুরু করি।

কৌশল ব্যাকটেস্টিং

কৌশলটি লেখার পরে, আমাদের প্রথমে যা করতে হবে তা হ'ল এটি historicalতিহাসিক ডেটাতে কীভাবে আচরণ করে তা দেখার জন্য ব্যাকটেস্ট করা। তবে দয়া করে নোট করুন যে ব্যাকটেস্টের ফলাফল ভবিষ্যতের পূর্বাভাসের সমান নয়। ব্যাকটেস্টটি কেবল আমাদের কৌশলটির কার্যকারিতা বিবেচনা করার জন্য একটি রেফারেন্স হিসাবে ব্যবহার করা যেতে পারে। একবার বাজার পরিবর্তন হয়ে গেলে এবং কৌশলটি বড় ক্ষতি হতে শুরু করলে, আমাদের সময়মতো সমস্যাটি খুঁজে বের করা উচিত এবং তারপরে উপরে উল্লিখিত থ্রেশহোল্ডের মতো নতুন বাজার পরিবেশে অভিযোজিত হওয়ার জন্য কৌশলটি পরিবর্তন করা উচিত। যদি কৌশলটির ক্ষতি 10% এর বেশি হয় তবে আমাদের অবিলম্বে কৌশলটির অপারেশন বন্ধ করা উচিত এবং তারপরে সমস্যাটি খুঁজে বের করা উচিত। আমরা থ্রেশহোল্ডটি সামঞ্জস্য করতে শুরু করতে পারি।

কৌশল সম্পাদনা পৃষ্ঠায় ব্যাকটেস্ট ক্লিক করুন। ব্যাকটেস্ট পৃষ্ঠায়, পরামিতিগুলির সমন্বয় বিভিন্ন প্রয়োজন অনুযায়ী সুবিধাজনক এবং দ্রুত সম্পন্ন করা যেতে পারে। বিশেষ করে জটিল যুক্তি এবং অনেক পরামিতি সহ কৌশলটির জন্য, সোর্স কোডে ফিরে যাওয়ার এবং এটি একের পর এক সংশোধন করার প্রয়োজন নেই।

ব্যাকটেস্টের সময় শেষ ছয় মাস। OKCoin ফিউচার এক্সচেঞ্জ যোগ করুন ক্লিক করুন এবং BTC ট্রেডিং লক্ষ্য নির্বাচন করুন।

img

বিটিসির একতরফা প্রবণতার কারণে গত ছয় মাসে এই কৌশলটি ভাল ফল দিয়েছে।

img img

যদি আপনার কোন প্রশ্ন থাকে, আপনি এ একটি বার্তা ছেড়ে দিতে পারেনhttps://www.fmz.com/bbsএটি প্ল্যাটফর্মের কৌশল বা প্রযুক্তি সম্পর্কে হোক না কেন, FMZ Quant প্ল্যাটফর্মের পেশাদাররা আপনার প্রশ্নের উত্তর দিতে প্রস্তুত।


সম্পর্কিত

আরো