मगरमच्छ लाइन ट्रेडिंग सिस्टम पायथन संस्करण

लेखक:अच्छाई, बनाया गयाः 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) चिन = REF(SMA(VAR1,13,1)

मगरमच्छ रणनीति रचना

चरण 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 फ़ंक्शन को मुख्य फ़ंक्शन में अनंत लूप में निष्पादित किया जाता है।

चरण 2: पायथन लाइब्रेरी आयात करें

import talib
import numpy as np

SMA फ़ंक्शन हमारी रणनीति में प्रयोग किया जाता है. SMA अंकगणितीय औसत है. talib लाइब्रेरी में पहले से ही तैयार SMA फ़ंक्शन हैं, इसलिए सीधे talib Python लाइब्रेरी आयात करें और फिर इसे सीधे कॉल करें. क्योंकि इस फ़ंक्शन को कॉल करते समय, आपको numpy प्रारूप पैरामीटर में पास करने की आवश्यकता होती है, इसलिए हमें रणनीति की शुरुआत में इन दो पायथन लाइब्रेरी आयात करने के लिए आयात का उपयोग करने की आवश्यकता है.

चरण 3: K-लाइन सरणी डेटा परिवर्तित करें

# 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 फ़ंक्शन बनाया है, इस फ़ंक्शन का उद्देश्य साधारण K-लाइन सरणी को numpy प्रारूप डेटा में संसाधित करना है। इनपुट पैरामीटर एक K-लाइन सरणी है, और आउटपुट परिणाम numpy प्रारूप में संसाधित डेटा है.

चरण 4: स्थान डेटा प्राप्त करें

# 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

स्थिति की स्थिति में रणनीति तर्क शामिल है. हमारे पहले दस पाठों ने हमेशा आभासी पदों का उपयोग किया है, लेकिन एक वास्तविक व्यापारिक वातावरण में वास्तविक स्थिति की जानकारी प्राप्त करने के लिए गेटपोजीशन फ़ंक्शन का उपयोग करना सबसे अच्छा है, जिसमें शामिल हैंः स्थिति दिशा, स्थिति लाभ और हानि, पदों की संख्या, आदि।

चरण 5: डेटा प्राप्त करें

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

डेटा प्राप्त करने से पहले, आपको पहले संबंधित वायदा किस्मों की सदस्यता के लिए SetContractType फ़ंक्शन का उपयोग करना चाहिए। FMZ सभी चीनी कमोडिटी वायदा किस्मों का समर्थन करता है। वायदा प्रतीक की सदस्यता लेने के बाद, आप K-लाइन डेटा प्राप्त करने के लिए GetRecords फ़ंक्शन का उपयोग कर सकते हैं, जो एक सरणी लौटाता है।

चरण 6: आंकड़ों की गणना करें

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

तालिब लाइब्रेरी का उपयोग करके एसएमए की गणना करने से पहले, आपको साधारण के-लाइन सरणी को नम्पी डेटा में संसाधित करने के लिए नम्पी लाइब्रेरी का उपयोग करने की आवश्यकता है। फिर मगरमच्छ रेखा की ठोड़ी, दांत और ऊपरी होंठ को अलग से प्राप्त करें। इसके अलावा, ऑर्डर देते समय मूल्य पैरामीटर को पारित करने की आवश्यकता है, इसलिए हम के-लाइन सरणी में समापन मूल्य का उपयोग कर सकते हैं।

चरण 7: ऑर्डर दें

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

अंत

मगरमच्छ ट्रेडिंग नियम की सबसे बड़ी भूमिका यह है कि यह हमें ट्रेडिंग करते समय बाजार के समान दिशा बनाए रखने में मदद करता है, भले ही वर्तमान बाजार मूल्य कैसे बदलता है, और समेकन बाजार दिखाई देने तक लाभ प्राप्त करना जारी रखता है। मगरमच्छ रेखा का उपयोग अन्य एमएसीडी और केडीजे संकेतकों के साथ भी किया जा सकता है।


संबंधित

अधिक