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=[
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)
Inventors quantify - small dreamsEMA 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).