我是一个策略编写的初学者,编写了一个图形化交易策略,由于效率低想将这个图形交易策略改为后台交易,请帮忙,谢谢。
VARIABLE:maxprofit=0;
DIFF:=EMA(CLOSE,S) - EMA(CLOSE,P);
DEA:=EMA(DIFF,M);
MACD:=2*(DIFF-DEA);
开多条件:=CROSS(MACD,0) and MACD>T1;
开空条件:=CROSS(0,MACD) and MACD<T2;
平空条件:=CROSS(MACD,0) and MACD>T3;
平多条件:=CROSS(0,MACD) AND MACD<T4;
平空:SELLSHORT(平空条件,0,NEXTOPEN);
平多:SELL(平多条件,0,NEXTOPEN);
开多:BUY(开多条件,50%,MARKET);
开空:BUYSHORT(开空条件,50%,MARKET);
IF (开多条件=1) THEN BEGIN
开多:BUY(开多平空条件,50%,NEXTOPEN);
maxprofit:=0;
end
IF (开空条件=1) THEN BEGIN
开空:BUYSHORT(开空平多条件,50%,NEXTOPEN);
maxprofit:=0;
end
WIN:=0;
zywin1:=0;
zywin2:=0;
//多头止损
if holding > 0 and enterbars >= 0 then
begin
win:=(LOW-enterprice)/enterprice*100;
end
if win < -0.3 and holding > 0 then
begin
止损多头:SELL(1,0,nextopen);
end
//空头止损
if holding < 0 and enterbars >= 0 then
begin
win:=(enterprice-HIGH)/enterprice*100;
end
if win < -0.3 and holding < 0 then
begin
止损空头:SELLSHORT(1,0,nextopen);
end
当前资产:ASSET,NOAXIS,COLORGRAY;
if holding > 0 and enterbars >= 0 then
begin
zywin1:=(h-enterprice)/enterprice*100;
if zywin1 > maxprofit then
begin
maxprofit:=zywin1;
end
if maxprofit > 1 then
begin
zywin3:=(c-enterprice)/enterprice*100;
zywin2:=(1-(zywin3/maxprofit))*100;
end
end
if holding < 0 and enterbars >= 0 then
begin
zywin1:=(enterprice-l)/enterprice*100;
if zywin1 > maxprofit then
begin
maxprofit:=zywin1;
end
if maxprofit > 3.5 then
begin
zywin3:=(enterprice-c)/enterprice*100;
zywin2:=(1-(zywin3/maxprofit))*100;
end
end