Please help me to see the problem of ema cross-signals.

Author: The motherfucker, Created: 2021-11-04 11:34:33, Updated:

There are two ema parameters, ema1 ((A2) and ema2 ((A3), when one of the ema settings is greater than 100, the ema does not match the value of the binan when the fmz is running, which is normal when the ema is less than 100), causing the open signal to advance or delay 5-10 k-roots.

'''backtest start: 2021-11-01 00:00:00 end: 2021-11-02 00:00:00 period: 5m basePeriod: 1m exchanges: [{“eid”:“Futures_Binance”,“currency”:“BTC_USDT”}] args: [[“M”,8],[“A2”,100],[“A3”,200],[“K3”,500],[“K2”,300]] '‘’

def accuracy ((): # get the accuracy of the exchange global BV1, CV1 exchanges[i].SetContractType (swap button) currency1=_C ((exchanges[i].GetCurrency) The ticker1=_C (exchanges[i].GetTicker) account1=_C ((exchanges[i].GetAccount) all_BV1list=[ALICE_USDT,DODO_USDT,UNFI_USDT,LITU_USDT,ZEN_USDT,FIL_USDT,AAVE_USDT,KSM_USDT,EGLD_USDT,TRB_USDT,CRV_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT It is also known as the BAL_USDT, the DOT_USDT, the SNX_USDT, the WAVES_USDT, the RLC_USDT, the BAND_USDT, the KAVA_USDT, the SXP_USDT, the OMG_USDT, the ZRX_USDT, and the ALGO_USDT. It is also known as the EOS_USDT, the QTUM_USDT, the BAT_USDT, the IOTA_USDT, the ONT_USDT, the XTZ_USDT, the EOS_USDT, the XRP_USDT, the ICP_USDT, the NEO_USDT, and the ATOM_USDT. It is also known as the BNB_USDT, the LINK_USDT, the ETC_USDT, the BNB_USDT, the YFII_USDT, the YFI_USDT, the DEFI_USDT, the MKR_USDT, the COMP_USDT, the ZEC_USDT, and the DASH_USDT. The following is a list of the most popular cryptocurrency exchanges in the world: list1=[ALICE_USDT,DODO_USDT,UNFI_USDT,LITU_USDT,ZEN_USDT,FIL_USDT,AAVE_USDT,KSM_USDT,EGLD_USDT,TRB_USDT,CRV_USDT,AAVE_USDT,KSM_USDT,TRB_USDT,TRB_USDT,CRV_USDT,USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USDT,TRB_USD It is also known as the BAL_USDT, the DOT_USDT, the SNX_USDT, the WAVES_USDT, the RLC_USDT, the BAND_USDT, the KAVA_USDT, the SXP_USDT, the OMG_USDT, the ZRX_USDT, and the ALGO_USDT. The following tags are used: THETA_USDT, QTUM_USDT, BAT_USDT, IOTA_USDT, ONT_USDT, XTZ_USDT, EOS_USDT, XRP_USDT list2=[ICP_USDT,NEO_USDT,ATOM_USDT,BNB_USDT,LINK_USDT,ETC_USDT,BNB_USDT] list3=[YFII_USDT,YFI_USDT,DEFI_USDT,MKR_USDT,COMP_USDT,ZEC_USDT,DASH_USDT,XMR_USDT,LTC_USDT,BCH_USDT,ETH_USDT,BTC_USDT] if currency1 in list1: BV1 is equal to 1. if currency1 in list2: BV1 is equal to 2. if currency1 in list3: BV1 is equal to 3. if currency1 not in all_BV1list: BV1 is equal to 0. # Precision pricing If currency1! = YFI_USDT RR1 = str ((ticker1[Last bell]) content1=RR1.split ((".")[-1] Weishu1=len ((content1)) is the name of the CV1 =weishu1 Other: CV1 is equal to 0. global n1 account1=_C (exchange.GetAccount) Wallet Balance=account1 P is equal to 0.01.P0float(walletbalance) n1=round(P/ticker1[“Last”],BV1) if n1==0: n1=n1+10**(-BV1)

def main(): while True: global i for i in range(len(exchanges)): exchanges[i].SetContractType(‘swap’) accuracy() exchanges[i].SetMarginLevel(M) ticker1=_C(exchanges[i].GetTicker) currency1=_C(exchanges[i].GetCurrency) position1=_C(exchanges[i].GetPosition) r=_C(exchanges[i].GetRecords) if r and len®>9: EMA=TA.EMA(r,A2) EMA2=TA.EMA(r,A3) longsignal=EMA[-3]<EMA2[-3] and EMA[-2]>EMA2[-2] shortsignal=EMA[-3]>EMA2[-3] and EMA[-2]<EMA2[-2] if len(position1)==0:

                    if longsignal: #1分钟金叉
                        Log(currency1,'多头信号成立')
                        exchanges[i].SetDirection('buy')
                        exchanges[i].Buy(-1,n1)
                        Log('倒数第二个EMA2:',EMA2[-2],'倒数第三个EMA2:',EMA2[-3])
                        Log('倒数第二个EMA1:',EMA[-2],'倒数第三个EMA1:',EMA[-3])
                        
                        
                    #开空信号
                    if shortsignal: #1分钟死叉
                        Log(currency1,'空头信号成立')
                        exchanges[i].SetDirection('sell')
                        exchanges[i].Sell(-1,n1)
                        Log('倒数第二个EMA2:',EMA2[-2],'倒数第三个EMA2:',EMA2[-3])
                        Log('倒数第二个EMA1:',EMA[-2],'倒数第三个EMA1:',EMA[-3])
                        
                if len(position1)==1:
                    if position1[0]["Type"]==0:
                        if ticker1["Last"]>position1[0].Price+K3:
                            Log(currency1,'多头触发止盈')
                            exchanges[i].SetDirection('closebuy')
                            exchanges[i].Sell(-1,position1[0].Amount)
                            Log('倒数第二个EMA2:',EMA2[-2],'倒数第三个EMA2:',EMA2[-3])
                            Log('倒数第二个EMA1:',EMA[-2],'倒数第三个EMA1:',EMA[-3])
                            
                        if ticker1["Last"]<position1[0].Price-K2:
                            Log(currency1,'多头触发止损')
                            exchanges[i].SetDirection('closebuy')
                            exchanges[i].Sell(-1,position1[0].Amount)
                            Log('倒数第二个EMA2:',EMA2[-2],'倒数第三个EMA2:',EMA2[-3])
                            Log('倒数第二个EMA1:',EMA[-2],'倒数第三个EMA1:',EMA[-3])
                            
                    if position1[0]["Type"]==1:
                        if ticker1["Last"]<position1[0].Price-K3:
                            Log(currency1,'空头触发止盈')
                            exchanges[i].SetDirection('closesell')
                            exchanges[i].Buy(-1,position1[0].Amount)
                            Log('倒数第二个EMA2:',EMA2[-2],'倒数第三个EMA2:',EMA2[-3])
                            Log('倒数第二个EMA1:',EMA[-2],'倒数第三个EMA1:',EMA[-3])
                            
                        if ticker1["Last"]>position1[0].Price+K2:
                            Log(currency1,'空头触发止损')
                            exchanges[i].SetDirection('closesell')
                            exchanges[i].Buy(-1,position1[0].Amount)
                            Log('倒数第二个EMA2:',EMA2[-2],'倒数第三个EMA2:',EMA2[-3])
                            Log('倒数第二个EMA1:',EMA[-2],'倒数第三个EMA1:',EMA[-3])
                            
        Sleep(S)

More

The Little DreamEMA algorithms, which calculate the indicator value of the iterative algorithm and the size of the input data (i.e. the number of K-line columns) are related. The higher the number of line columns, the closer the calculation. You can calculate EMA 100 basically the same, EMA 200 is slightly wrong because EMA 200 calculation requires more line columns (i.e. K-line BAR).