I am newbie in the programming and facing issue with developing my first strategy. I was wondering if someone can help me. In my strategy I want to use two different types of stops (Initial Stop and Trailing Stop) as well as Profit Target. Unfortunately, only Trailing Stop and Profit Target seem to work so far. If the position does not move in my favour, instead of triggering Initial Stop Loss, Trailing Stop is triggered, even though Initial Stop is tighter. Please help me. Here is my code:
protected override void Initialize()
{
Add(ATRTrailingStop(ATR_Multiple, ATR_Period));
SetStopLoss("", CalculationMode.Ticks, StopLoss, false);
SetProfitTarget("", CalculationMode.Ticks, ProfitTarget);
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(Close, ATRTrailingStop(ATR_Multiple, ATR_Period), 1))
{
EnterLong(DefaultQuantity, "");
}
// Condition set 2
if (CrossBelow(Close, ATRTrailingStop(ATR_Multiple, ATR_Period), 1))
{
EnterShort(DefaultQuantity, "");
}
// Reset the stoploss when all positions are closed
if (Position.MarketPosition == MarketPosition.Flat)
{
SetStopLoss(CalculationMode.Price, ATRTrailingStop(1.5, 10)[0]);
}
// Modify the stoploss when there is an open position
if (Position.MarketPosition == MarketPosition.Long
|| Position.MarketPosition == MarketPosition.Short);
{
SetStopLoss(CalculationMode.Price, ATRTrailingStop(atrTrailing_Multip, atrTrailing_Period)[0]);
}
}
Thank you in advance for any help!
Konstantin
Comment