- UID
- 2
- 积分
- 2874604
- 威望
- 1387331 布
- 龙e币
- 1487273 刀
- 在线时间
- 13155 小时
- 注册时间
- 2009-12-3
- 最后登录
- 2024-11-24
|
- Input:N1(120),N2(3),N3(5),riskratio(0.2),atrlength(14);
- var:top(0),bot(0),mp(0),inicap(1000000),totalamt(0),lots(0),stoploss(0),stopearn(0),exetripoint(0),entrATR(0),trailatr(0),trail(False),closehl(0),initrail(0);
- totalamt =inicap + (netprofit {+ openpositionprofit});
- if AvgTrueRange(atrlength) <> 0 then lots = ((totalamt/100)*riskratio)/(AvgTrueRange(atrlength)*bigpointvalue);
- mp = marketposition;
- top = Highest(high,N1);
- bot = Lowest(low,N1);
- if mp = 0 then begin //entry model
- if Close > top[1] then buy("buylong") lots shares next bar at market;
- if Close < bot[1] then sellshort("sellshort") lots shares next bar at market;
- end;
- if marketposition <> 0 and barssinceentry = 0 then begin
- entrATR = AvgTrueRange(atrlength);
- exetripoint = Close;
- trail = False;
- if marketposition =1 then
- value1 = text_new(date,time,low - 100,"entry price:"+numtostr(entryprice,0)+ "Atr:"+numtostr(entrATR,0) + "stoploss:" + NumToStr(entryprice - 3*entratr,0))
- else if marketposition =-1 then
- value1 = text_new(date,time,high + 100,"entry price:"+numtostr(entryprice,0)+ "Atr:"+numtostr(entrATR,0) + "stoploss:" + NumToStr(entryprice + 3*entratr,0));
- end;
- //long order
- if marketposition = 1 and barssinceentry > 0 then begin
-
- if Close > exetripoint then begin
- exetripoint = Close;
- trailatr = AvgTrueRange(atrlength);
- end;
-
- if exetripoint > entryprice + 2*entrATR then begin //tril start
- value2 = text_new(date,time,high + 30,"top:"+numtostr(exetripoint,0)+"Atr:"+numtostr(trailatr,0)+"stopearn:"+NumToStr(exetripoint - N3*trailatr,0));
- value3 = tl_new(date[1],time[1],exetripoint[1],date,time,exetripoint);
- end;
-
- sell("L-stopearn") all shares next bar at exetripoint - N3*trailatr stop;
- sell("L-stoploss") all shares next bar at entryprice - N2*entratr stop;
- end;
-
- //short order
- if marketposition = -1 and barssinceentry> 0 then begin
- if Close < exetripoint then begin
- exetripoint = Close;
- trailatr = AvgTrueRange(atrlength);
- end;
-
- if exetripoint < entryprice - 2*entrATR then begin
- value2 = text_new(date,time,low - 30,"bot:"+numtostr(exetripoint,0)+"Atr:"+numtostr(trailatr,0)+"stopearn:"+NumToStr(exetripoint + N3*trailatr,0));
- value3 = tl_new(date[1],time[1],exetripoint[1],date,time,exetripoint);
- end;
- buytocover("S-stopearn") all shares next bar at exetripoint + N3*trailatr stop;
- buytocover("S-stoploss") all shares next bar at entryprice + N2*entratr stop;
- end;
复制代码 |
论坛官方微信、群(期货热点、量化探讨、开户与绑定实盘)
|