I would like to add a simple trailing stop instead, when the profit reach a certain amount in currency (like $100) the trailing stop begins, so if the market reversed the trade get closed before I lose the $100 profit.
Can anyone please walk me through how can I achieve that with my current strategy?
Here down is the code for the original trailing stop on my strategy
if (PriceBreakoutRectangularBase(upwardBreakout,VolumeMultiple).Plot0[0] == 1 &&
Position.MarketPosition == MarketPosition.Flat && PositionAccount.MarketPosition == MarketPosition.Flat)
{
EnterLong(6, "Long");
justEntered = true;
}
if (Position.MarketPosition == MarketPosition.Long && justEntered == true)
{
if (trailingStopPct == 0)
{
trailStop = Position.AveragePrice - (chandelierRangeMultiple * ATR(atrPeriod)[0]);
}
else
{
trailStop = Position.AveragePrice - (trailingStopPct * Position.AveragePrice);
}
StopLoss = Position.AveragePrice - (stopLossPct * Position.AveragePrice);
prevValue = Position.AveragePrice;
justEntered = false;
//Print(" TRAIL STOP TRACKING: " + trailStop + " symbol " + Instrument.FullName);
}
if (Position.MarketPosition == MarketPosition.Long)
{
if (High[0] > Position.AveragePrice && High[0] > prevValue)
{
if (trailingStopPct == 0)
{
trailStop = High[0] - chandelierRangeMultiple * ATR(atrPeriod)[0];
}
else
{
trailStop = trailStop + (High[0] - prevValue);
}
prevValue = High[0];
//Print(" TRAIL STOP RAISED: " + trailStop + " PrevValue " + prevValue + " symbol " + Instrument.FullName);
}
//Print(Time[0] + " High " + High[0] + " PrevValue " + prevValue + " symbol " + Instrument.FullName);
}
if (Low[0] <= trailStop && Position.MarketPosition == MarketPosition.Long && Position.AveragePrice < trailStop)
{
Print(" TRAIL STOP HIT: " + trailStop + " " + Close[0] + " symbol " + Instrument.FullName);
// Trailing stop has been hit; do whatever you want here
ExitLong(100,"Trailing Stop" ,"Long");
trailStop = 0;
StopLoss = 0;
prevValue = 0;
}

Comment