信号闪烁

highprice = Highest(high[1], IntPart(0.5 * Length));

lowprice  = Lowest(low[1],   IntPart(0.5 * Length));

malong =  (high > highprice and highprice > highprice[IntPart(0.5 * Length)] and highprice[IntPart(0.5 * Length)] > highprice[IntPart(1 * Length)]) ;

mashort = (low < lowprice and lowprice < lowprice[IntPart(0.5 * Length)] and lowprice[IntPart(0.5 * Length)] < lowprice[IntPart(1 * Length)]);

if (malong)

{

Flag = -1;

StartIndex = CurrentBar;

Commentary(\"Long\");

}

if (mashort)

{

Flag = 1;

StartIndex = CurrentBar;

Commentary(\"Short\");

}

Commentary(\"CurrentBar - StartIndex222:\" + Text(CurrentBar - StartIndex));

Commentary(\"BarsSinceEntry:\" + Text(BarsSinceEntry));

//信号连续触发,信号持仓周期增加

if(Flag == 1 and CurrentBar - StartIndex == Waitbar + nextbar )

{

Buy(1, Enterprice);

LossPrice = Enterprice - 100 * MinMove() * PriceScale();

ProfitLossFlag = False;

}

if(Flag == -1  and CurrentBar - StartIndex == Waitbar + nextbar )

{

SellShort(1, Enterprice);

LossPrice = Enterprice + 100 * MinMove() * PriceScale();

Commentary(\"OPenPrice:\" + Text(OPenPrice));

ProfitLossFlag = False;

}


if (MarketPosition == 1  and  (BarsSinceEntry >= Closebar + nextbar - Waitbar )   )

{

Sell(1,Enterprice);

}

if (MarketPosition == -1  and  (BarsSinceEntry >= Closebar + nextbar - Waitbar )   )

{

BuyToCover(1,Enterprice);

}

代码如上所示,进行一个简单测试,为什么这样还是会有信号闪烁的问题(主要是开仓信号)?

【信号闪烁】信号不闪烁的方法
信号闪烁
信号闪烁
信号闪烁
关于信号闪烁
信号闪烁
关于信号闪烁
信号闪烁问题
信号闪烁
信号闪烁问题

如果看逻辑无法看出来,那就用print或者fileappend完整输出所有的开仓条件值,然后根据日志来查是哪个表达式出问题。

https://www.tbquant.net/TrainDetail?id=480

这一期主要讲了输出日志的技巧及诊断的思路过程