I have one of yours example. It is about stop loss modification
On OnBarUpdate it works but not perfect because it updates every 5 min and sometimes has wrong results
Do you know how to convert your example in OnMarketUpdate?
private int stoplossticks = 5;
private int profittargetticks = 15;
protected override void Initialize()
{ SetStopLoss(CalculationMode.Ticks, stoplossticks);
SetProfitTarget(CalculationMode.Ticks, profittargetticks);
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{ if (Position.MarketPosition == MarketPosition.Flat)
{SetStopLoss(CalculationMode.Ticks, stoplossticks); }
else if (Position.MarketPosition == MarketPosition.Long)
{
// Once the price is greater than entry price+50 ticks, set stop loss to breakeven
if (Close[0] > Position.AvgPrice + 50 * TickSize)
{
SetStopLoss(CalculationMode.Price, Position.AvgPrice);
}
}
if (Close[0] > Close[1] && RSI(14, 3)[0] <= 30)
{
EnterLong();
}
}
I did myself a little bit and doesn't work well
protected override void OnMarketData(MarketDataEventArgs e)
{
if(e.Price >= Position.AvgPrice - (6.0 * TickSize))
SetStopLoss(CalculationMode.Price, Position.AvgPrice - (2.0*TickSize));
if(e.Price >= Position.AvgPrice - (9.0 * TickSize))
SetStopLoss(CalculationMode.Price, Position.AvgPrice - (0*TickSize));
if(e.Price >= Position.AvgPrice - (12.0 * TickSize))
SetStopLoss(CalculationMode.Price, Position.AvgPrice + (1*TickSize));
}
Comment