等级: 专业版
- 注册:
- 2022-1-11
- 曾用名:
|
楼主 |
发表于 2024-9-23 17:02
|
显示全部楼层
搞不出来,请帮忙把这段代码翻译成金字塔能用的,谢谢
1、启动ATR Ratchet 的条件:(1)、盈利已经达到1个ATR。
2、然后确定起始价格:盈利达到1个ATR那一个bar时10周期的低点,即从达到1个ATR盈利时当天BAR往前数9个BAR,在这10个BAR内的最低点做为起始价格。
3、根据持仓天数N来乘一个基础的ATR增加量(M:0.05)若是持仓有15个 BAR,则ATR止盈需要抬升的数值是M*N即 15 个bar * 0.05个ATR增量即 = 0.75个ATR。
4、如何超过maxperiod(20)周期仍然没有盈利达到1个atr,则清仓。
MC平台的代码如下:
Input:
len(15),{atr initial period}
m1(0.05),{start set foot}
m2(10),{inicost number}
maxperiod(20);{over this bars if profit not bigger than 1 atr,then exit}
var:
tp(0),{highest of price after entry}
spacep(0),{the value point of profit}
inicost(0),
ratchet(0),
stopline(0),
barn(0);
value1 = atr(len);
if barssinceentry = 0 then begin
tp = entryprice;
end;
if marketposition =1 then begin
if barssinceentry>=1 then begin
if high >tp then tp = high;
end;
spacep = tp - entryprice;
if spacep[1] < 1*value1[1] and spacep > 1*value1 then begin {find the bar of profit point bigger than 1*atr,then set the initial start cost}
inicost = Lowest(low,m2);
barn = BarNumber;
Value6=Text_New(Date,Time,High+10,"START RATCHET");
end;
if spacep > 1*value1 then begin //START RATCHET MODEL
ratchet = barssinceentry * m1*value1; {ratchet point}
stopline =inicost + ratchet; {the stop line}
sell("ratchet-out1") all shares next bar at stopline stop;
if BarNumber>barn then begin
value2 = tl_new(date[1],time[1],stopline[1],date,time,stopline);
end;
end;
if barssinceentry >=maxperiod and spacep < 1*value1 then sell("time-out1") all shares next bar at market;
if marketposition = 0 then TL_delete(value2);
end; |
|