思路 :以甲醇为例 最新价大于2500 开空5 手,平仓间隔是 15,19,24,31,40。第一次的开仓减仓是按照这个间隔去完成,但是开第二次后减仓会直接按照最后的价格减去平仓间隔,
错误是 如果第一次开仓在2670开仓,清仓完的价格是2541,第二次开仓价格是2584 第一次平仓应该是2584-15,但是公式跑出来的是 2541-15
这个如何重置lastprice ,让第二次开仓的 LastPrice = FirstPrice 然后再进行循环
--------------------------------------------------------------------------------
Params
Integer Lots(5);
Integer firststep(15);
Integer firstTrades(1);
Integer newprice(2500);
Vars
Bool FirstEntryCon;
Series<Numeric> FirstPrice; // 第一次开仓价格
Series<Numeric> LastPrice; // 最后一次开仓价格
Series<Numeric> i;
Series<Numeric> j(1);
Numeric MinPoint; // 一个最小变动单位,也就是一跳
Series<Numeric> TakeProfitSet;
Series<Numeric> TakeProfitTrades;
If(MarketPosition == 0 && FirstEntryCon)
{
FirstPrice = Open;
LastPrice = FirstPrice;
SellShort(Lots,FirstPrice);
i = 5 ;
Commentary(\"FirstPrice = \" + Text(FirstPrice));
}
If(MarketPosition == -1 )
{
While( shortCurrentContracts >0 && Low <= LastPrice - IntPart(firststep*minpoint*power(1.3,j-1)) ) // 减仓
{
LastPrice = LastPrice - IntPart(firststep*minpoint*power(1.3,j-1)) ;
TakeProfitTrades = IntPart(firstTrades * Power(1.3,j-1))*minpoint;
BuyToCover(firstTrades ,LastPrice);
i = i - firstTrades ;
j = 6-i ;
Commentary(\"j = \" + Text(j));
Commentary(\"i = \" + Text(i));
Commentary(\"LastPrice = \" + Text(LastPrice));
}
}
这种代码逻辑分析诊断的问题建议投稿等直播