I would like to trail my stop loss to the low or high of the following bar, my setup is the following:
EnterShort(Convert.ToInt32(Sellqty), "Sell1");
Stop_Price1 = Position.AveragePrice + (High[2]-Position.AveragePrice);
SetStopLoss("Sell1", CalculationMode.Price, Stop_Price1, false);
So my stop loss at the begining of the order is place at the low or high of the second previous bar of the trigger bar
Once the current bar closes I want that the stop loss trails to the low or high of the next bar, so there´s always 3 bars in between my stop loss and the current price.
I tried to do this
EnterShort(Convert.ToInt32(Sellqty), "Sell1");
Stop_Price1 = Position.AveragePrice + (High[2]-Position.AveragePrice);
SetStopLoss("Sell1", CalculationMode.Price, Stop_Price1, false);
Stop_Trigger = (Position.AveragePrice - (Close[-1])) ;
protected override void OnMarketData(MarketDataEventArgs marketDataUpdate)
{
// Print some data to the Output window
if (marketDataUpdate.MarketDataType == MarketDataType.Last)
{
if ((Position.MarketPosition == MarketPosition.Long)
&& (Times[0][0].TimeOfDay >= Hora_inicio.TimeOfDay)
&& (Times[0][0].TimeOfDay <= Hora_final.TimeOfDay)
&& (Stop_Price1 != 0)
&& (UseBreakeven == true)
&& (marketDataUpdate.Price >= Stop_Trigger))
{
Stop_Price1 = (marketDataUpdate.Price - (marketDataUpdate.Price-Low[2])) ;
Stop_Trigger = (marketDataUpdate.Price + (Close[0])) ;
SetStopLoss("Buy1", CalculationMode.Price, Stop_Price1, false);
Print("Setting Stop ="+Stop_Price1);
}
}
if (marketDataUpdate.MarketDataType == MarketDataType.Last)
{
if ((Position.MarketPosition == MarketPosition.Short)
&& (Times[0][0].TimeOfDay >= Hora_inicio.TimeOfDay)
&& (Times[0][0].TimeOfDay <= Hora_final.TimeOfDay)
&& (Stop_Price1 != 0)
&& (UseBreakeven == true)
&& (marketDataUpdate.Price <= Stop_Trigger))
{
Stop_Price1 = (marketDataUpdate.Price + (High[2]-marketDataUpdate.Price)) ;
Stop_Trigger = (marketDataUpdate.Price - (Close[0])) ;
SetStopLoss("Sell1", CalculationMode.Price, Stop_Price1, false);
}
But it didn´t work
Thank you
Comment