ক্রোকোডাইল লাইন ট্রেডিং সিস্টেম পাইথন সংস্করণ

লেখক:ভাল, তৈরিঃ 2020-05-07 14:33:19, আপডেটঃ 2023-11-06 19:40:42

img

সংক্ষিপ্তসার

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

কুমির রেখা কি?

img

ক্রোকোডিল লাইন আসলে তিনটি বিশেষ চলমান গড়, যা নীল রেখার চোয়াল, লাল রেখার দাঁত এবং সবুজ রেখার উপরের ঠোঁটের সাথে মিলে যায়। চোয়ালটি একটি 13 পিরিয়ড চলমান গড় এবং ভবিষ্যতে 8 বার সরানো হয়। দাঁতটি একটি 8 পিরিয়ড চলমান গড় এবং ভবিষ্যতে 5 বার সরানো হয়। উপরের ঠোঁটটি একটি 5 পিরিয়ড চলমান গড় এবং ভবিষ্যতে 3 বার সরানো হয়।

কুমির রেখার নীতি

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

ক্রকডিল যত বেশি ঘুমায়, তত বেশি ক্ষুধার্ত হবে যখন সে জেগে উঠবে, তাই একবার সে জেগে উঠলে, এটি তার মুখটি প্রশস্তভাবে খুলবে। যদি উপরের ঠোঁট দাঁতের উপরে থাকে এবং দাঁত চোয়ালের উপরে থাকে তবে এটি নির্দেশ করে যে বাজারটি একটি ষাঁড়ের বাজারে প্রবেশ করেছে এবং ক্রকডিলগুলি গরুর মাংস খেতে চলেছে। যদি উপরের ঠোঁট দাঁতের নীচে থাকে এবং দাঁত চোয়ালের নীচে থাকে তবে এটি নির্দেশ করে যে বাজারটি একটি ভালুকের বাজারে প্রবেশ করেছে এবং ক্রকডিলগুলি ভালুকের মাংস খেতে চলেছে। এটি পূর্ণ না হওয়া পর্যন্ত, এটি আবার মুখ বন্ধ করবে (ধারণ করুন এবং লাভ করুন) ।

ক্রোকোডিল লাইন গণনার সূত্র

উপরের ঠোঁট = REF(SMA(VAR1,5,1),3) দাঁত = REF ((SMA ((VAR1,8,1),5) Chin = REF(SMA(VAR1,13,1)

ক্রোকোডিল কৌশল গঠন

ধাপ ১ঃ কৌশলগত কাঠামো লিখুন

# Strategy main function
def onTick():
     pass

# Program entry
def main ():
     while True: # Enter infinite loop mode
         onTick() # execute strategy main function
         Sleep(1000) # sleep for 1 second

FMZ পোলিং মোড ব্যবহার করে, একটি হল onTick ফাংশন, এবং অন্যটি হল প্রধান ফাংশন, যেখানে onTick ফাংশনটি প্রধান ফাংশনে অসীম লুপে কার্যকর করা হয়।

ধাপ ২ঃ পাইথন লাইব্রেরি আমদানি করুন

import talib
import numpy as np

এসএমএ ফাংশনটি আমাদের কৌশলতে ব্যবহৃত হয়। এসএমএ হল গাণিতিক গড়। তালিব লাইব্রেরিতে ইতিমধ্যে প্রস্তুত সজ্জিত এসএমএ ফাংশন রয়েছে, তাই সরাসরি তালিব পাইথন লাইব্রেরিটি আমদানি করুন এবং তারপরে এটি সরাসরি কল করুন। কারণ এই ফাংশনটি কল করার সময়, আপনাকে numpy ফর্ম্যাট পরামিতিগুলি পাস করতে হবে, তাই আমাদের কৌশলটির শুরুতে এই দুটি পাইথন লাইব্রেরি আমদানি করতে আমদানি ব্যবহার করতে হবে।

ধাপ 3: কে-লাইন অ্যারে ডেটা রূপান্তর করুন

# Convert the K-line array into an array of highest price, lowest price, and closing price, for conversion to numpy.array
def get_data(bars):
    arr = []
    for i in bars:
        arr.append(i['Close'])
    return arr

এখানে আমরা একটি get_data ফাংশন তৈরি করেছি, এই ফাংশনের উদ্দেশ্য হল সাধারণ কে-লাইন অ্যারেটিকে নাম্পি ফর্ম্যাট ডেটাতে প্রক্রিয়াকরণ করা। ইনপুট প্যারামিটারটি একটি কে-লাইন অ্যারে, এবং আউটপুট ফলাফলটি নাম্পি ফর্ম্যাটে প্রক্রিয়াকৃত ডেটা।

ধাপ ৪ঃ অবস্থান তথ্য সংগ্রহ করুন

# Get the number of positions
def get_position ():
     # Get position
     position = 0 # The number of assigned positions is 0
     position_arr = _C (exchange.GetPosition) # Get array of positions
     if len (position_arr)> 0: # If the position array length is greater than 0
         for i in position_arr:
             if i ['ContractType'] == 'rb000': # If the position symbol is equal to the subscription symbol
                 if i ['Type']% 2 == 0: # If it is long position
                     position = i ['Amount'] # Assigning a positive number of positions
                 else:
                     position = -i ['Amount'] # Assigning a negative number of positions
     return position

পজিশন স্ট্যাটাস কৌশল লজিক জড়িত। আমাদের প্রথম দশটি পাঠ সবসময় ভার্চুয়াল অবস্থান ব্যবহার করেছে, কিন্তু একটি বাস্তব ট্রেডিং পরিবেশে এটি বাস্তব অবস্থান তথ্য পেতে ফাংশন GetPosition ব্যবহার করা ভাল, সহঃ অবস্থান দিক, অবস্থান লাভ এবং ক্ষতি, অবস্থান সংখ্যা, ইত্যাদি

৫ম ধাপঃ তথ্য সংগ্রহ করুন

exchange.SetContractType('rb000') # Subscribe the futures varieties
     bars_arr = exchange.GetRecords() # Get K line array
     if len(bars_arr) < 22: # If the number of K lines is less than 22
         return

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

ধাপ ৬ঃ তথ্য গণনা করুন

np_arr = np.array (get_data (bars_arr)) # Convert closing price array
sma13 = talib.SMA (np_arr, 130) [-9] # chin
sma8 = talib.SMA (np_arr, 80) [-6] # teeth
sma5 = talib.SMA (np_arr, 50) [-4] # upper lip
current_price = bars_arr [-1] ['Close'] # latest price

তালিব লাইব্রেরি ব্যবহার করে এসএমএ গণনা করার আগে, আপনাকে সাধারণ কে-লাইন অ্যারেটিকে নম্পি ডেটাতে প্রক্রিয়াকরণের জন্য নম্পি লাইব্রেরি ব্যবহার করতে হবে। তারপরে আলাদাভাবে ক্রোকোডাইল লাইনের চোয়াল, দাঁত এবং উপরের ঠোঁট পান। এছাড়াও, অর্ডার দেওয়ার সময় দামের পরামিতিটি পাস করা দরকার, যাতে আমরা কে-লাইন অ্যারেতে বন্ধের দাম ব্যবহার করতে পারি।

ধাপ ৭ঃ অর্ডার দিন

position = get_position ()
if position == 0: # If there is no position
     if current_price> sma5: # If the current price is greater than the upper lip
         exchange.SetDirection ("buy") # Set the trading direction and type
         exchange.Buy (current_price + 1, 1) # open long position order
     if current_price <sma13: # If the current price is less than the chin
         exchange.SetDirection ("sell") # Set the trading direction and type
         exchange.Sell (current_price-1, 1) # open short position order
    
if position> 0: # If you have long positions
     if current_price <sma8: # If the current price is less than teeth
         exchange.SetDirection ("closebuy") # Set the trading direction and type
         exchange.Sell (current_price-1, 1) # close long position

if position <0: # If you have short position
     if current_price> sma8: # If the current price is greater than the tooth
         exchange.SetDirection ("closesell") # Set the trading direction and type
         exchange.Buy (current_price + 1, 1) # close short position

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

সম্পূর্ণ কৌশল

'' 'backtest
start: 2019-01-01 00:00:00
end: 2020-01-01 00:00:00
period: 1h
exchanges: [{"eid": "Futures_CTP", "currency": "FUTURES"}]
'' '

import talib
import numpy as np


# Convert the K-line array into an array of highest price, lowest price, and closing price, used to convert to numpy.array type data
def get_data (bars):
    arr = []
    for i in bars:
        arr.append (i ['Close'])
    return arr


# Get the number of positions
def get_position ():
    # Get position
    position = 0 # The number of assigned positions is 0
    position_arr = _C (exchange.GetPosition) # Get array of positions
    if len (position_arr)> 0: # If the position array length is greater than 0
        for i in position_arr:
            if i ['ContractType'] == 'rb000': # If the position symbol is equal to the subscription symbol
                if i ['Type']% 2 == 0: # If it is long
                    position = i ['Amount'] # Assign a positive number of positions
                else:
                    position = -i ['Amount'] # Assign a negative number of positions
    return position
    
    

# Strategy main function
def onTick ():
    # retrieve data
    exchange.SetContractType ('rb000') # Subscribe to futures varieties
    bars_arr = exchange.GetRecords () # Get K line array
    if len (bars_arr) <22: # If the number of K lines is less than 22
        return
    
    # Calculation
    np_arr = np.array (get_data (bars_arr)) # Convert closing price array
    sma13 = talib.SMA (np_arr, 130) [-9] # chin
    sma8 = talib.SMA (np_arr, 80) [-6] # teeth
    sma5 = talib.SMA (np_arr, 50) [-4] # upper lip
    current_price = bars_arr [-1] ['Close'] # latest price

    position = get_position ()
    if position == 0: # If there is no position
        if current_price> sma5: # If the current price is greater than the upper lip
            exchange.SetDirection ("buy") # Set the trading direction and type
            exchange.Buy (current_price + 1, 1) # open long position order
        if current_price <sma13: # If the current price is less than the chin
            exchange.SetDirection ("sell") # Set the trading direction and type
            exchange.Sell (current_price-1, 1) # open short position order
        
    if position> 0: # If you have long positions
        if current_price <sma8: # If the current price is less than teeth
            exchange.SetDirection ("closebuy") # Set the trading direction and type
            exchange.Sell (current_price-1, 1) # close long position

    if position <0: # If you have short positions
        if current_price> sma8: # If the current price is greater than the tooth
            exchange.SetDirection ("closesell") # Set the trading direction and type
            exchange.Buy (current_price + 1, 1) # close short position

            
# Program main function
def main ():
    while True: # loop
        onTick () # execution strategy main function
        Sleep (1000) # sleep for 1 second

কনফিগারেশন ছাড়াই সম্পূর্ণ কৌশল কপি করতে নিচের লিঙ্কে সরাসরি ক্লিক করুনঃhttps://www.fmz.com/strategy/199025

শেষ

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


সম্পর্কিত

আরো