I am trying to create a scale out strategy. It takes a set target off 1st then 2nd when a certain indicator level is hit. The 3rd exit needs to be triggered when stochastic reached OB or OS conditions (target 2 criteria). I think the 3rd stoploss is getting reset and is not activating. Please help. Do I need to iOrder management?
Thanks!
#region Stoploss reset, ATR Stop set, ATRTrailStop & Breakeven (BE) // Resets the stop loss to the original value when all positions are closed if (Position.MarketPosition == MarketPosition.Flat) { //Set initial stop - ATR Stop in ticks int StopLoss = Convert.ToInt32(Math.Round( ATR(ATRStopPeriod)[0] * ATRStopMulti / TickSize)); SetStopLoss("SWING LONG1", CalculationMode.Ticks, StopLoss, false); SetStopLoss("SWING LONG2", CalculationMode.Ticks, StopLoss, false); SetStopLoss("SWING LONG3", CalculationMode.Ticks, StopLoss, false); SetStopLoss("SWING SHORT1", CalculationMode.Ticks, StopLoss, false); SetStopLoss("SWING SHORT2", CalculationMode.Ticks, StopLoss, false); SetStopLoss("SWING SHORT3", CalculationMode.Ticks, StopLoss, false); SetProfitTarget("SWING LONG1", CalculationMode.Ticks, T1ticks); SetProfitTarget("SWING SHORT1", CalculationMode.Ticks, T1ticks); } // If a long position is open, allow for stop loss modification to breakeven else if (Position.MarketPosition == MarketPosition.Long) { // Once the price is greater than entry price +BETrigger ticks, set stop loss to breakeven + 1 if (Close[0] > Position.AvgPrice + BETrigger * TickSize) { SetStopLoss("SWING LONG1", CalculationMode.Price, Position.AvgPrice + 1 * TickSize, false); SetStopLoss("SWING LONG2", CalculationMode.Price, Position.AvgPrice + 1 * TickSize, false); SetStopLoss("SWING LONG3", CalculationMode.Price, Position.AvgPrice + 1 * TickSize, false); } // If a long position is open, use ATRTrailingStop after Stochastic .K moves into OB if ((Close[0] > ATRTrailingStop(ATRTSmulti, ATRTSperiod)[0]) && (Stochastics(5, LgPeriodK, LgStochSmooth).K[(BarsSinceEntry("SWING LONG3"))] > LgStochUp)) { SetStopLoss("SWING LONG3", CalculationMode.Price, ATRTrailingStop(ATRTSmulti, ATRTSperiod)[0], false); } } // If a short position is open, allow for stop loss modification to breakeven else if (Position.MarketPosition == MarketPosition.Short) { // Once the price is greater than entry price +BETrigger ticks, set stop loss to breakeven + 1 if (Close[0] < Position.AvgPrice - BETrigger * TickSize) { SetStopLoss("SWING SHORT1", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false); SetStopLoss("SWING SHORT2", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false); SetStopLoss("SWING SHORT3", CalculationMode.Price, Position.AvgPrice - 1 * TickSize, false); } // If a short position is open, use ATRTrailingStop after Stochastic .K moves into OS if ((Close[0] < ATRTrailingStop(ATRTSmulti, ATRTSperiod)[0]) && (Stochastics(5, ShtPeriodK, ShtStochSmooth).K[(BarsSinceEntry("SWING SHORT3"))] < ShtStochLow)) { SetStopLoss("SWING SHORT3", CalculationMode.Price, ATRTrailingStop(ATRTSmulti, ATRTSperiod)[0], false); } }
Comment