如果用apply stop的話,我是這樣寫的,但applystop卻默認所有的stop price都是R1ProfitPoint和R1LossPoint
Buy1 = C > O; //It's just a example
Sell1 = C > Ref(C, -1); //It's just a example
Short1 = O > C; //It's just a example
Cover1 = C < Ref(C, -1); //It's just a example
R1ProfitPoint = 150;
R1LossPoint = 70;
Buy2 = H > Ref(H, -1); //It's just a example
Sell2 = C > Ref(C, -1); //It's just a example
Short2 = L > Ref(L, -1); //It's just a example
Cover2 = C < Ref(C, -1); //It's just a example
R2ProfitPoint = 200;
R2LossPoint = 90;
BuyCondition = 0;
SellCondition = 0;
ShortCondition = 0;
CoverCondition = 0;
PositionHold = 0;
ProfitPoint = 0;
LossPoint = 0;
R1 = 0;
R2 = 0;
for (i = 0; i < BarCount; i++)
{
if (Buy1[i] AND PositionHold == 0)
{
BuyCondition[i] = 1;
PositionHold ++;
ProfitPoint = R1ProfitPoint;
LossPoint = R1LossPoint;
R1 = 1;
}
else if (Short1[i] AND PositionHold == 0)
{
ShortCondition[i] = 1;
PositionHold --;
R1TradeCount ++;
ProfitPoint = R1ProfitPoint;
LossPoint = R1LossPoint;
R1 = 1;
}
else if (Sell1[i] && PositionHold > 0 AND R1 == 1)
{
SellCondition[i] = 1;
PositionHold = 0;
R1 = 0;
}
else if (Cover1[i] && PositionHold < 0 AND R1 == 1)
{
CoverCondition[i] = 1;
PositionHold = 0;
R1 = 0;
}
else if (Buy2[i] AND PositionHold == 0)
{
BuyCondition[i] = 1;
PositionHold ++;
ProfitPoint = R2ProfitPoint;
LossPoint = R2LossPoint;
R2 = 1;
}
else if (Short2[i] AND PositionHold == 0)
{
ShortCondition[i] = 1;
PositionHold --;
ProfitPoint = R2ProfitPoint;
LossPoint = R2LossPoint;
R2 = 1;
}
else if (Sell2[i] && PositionHold > 0 AND R2 == 1)
{
SellCondition[i] = 1;
PositionHold = 0;
R2 = 0;
}
else if (Cover2[i] && PositionHold < 0 AND R2 == 1)
{
CoverCondition[i] = 1;
PositionHold = 0;
R2 = 0;
}
}
Buy = BuyCondition;
Sell = SellCondition;
Short = ShortCondition;
Cover = CoverCondition;
ApplyStop(stopTypeProfit, stopModePoint, ProfitPoint);
ApplyStop(stopTypeLoss, stopModePoint, LossPoint); |