protected override void OnBarUpdate()
{
return;
double emaHigh = EMA(High, EmaPeriod)[0];
double emaLow = EMA(Low, EmaPeriod)[0];
if (Close[0] > emaHigh)
{ //entry code here...}
else if (Close[0] < emaLow)
{ //entry code here...}
}
Under Set.defaults i am using Calculate = Calculate.OnBarClose
I also have two other functions:
1) CalculateUnrealizedPL()
2) ModifyStopLoss() - This moves the stoploss to BE once the price hits a trigger value which is a certain amount into the green
Both these functions are called in onMarketUpdate()
protected override void OnMarketData(MarketDataEventArgs e)
{
return;
// Loop through positions and calculate unrealized P/L
if (!stopLossesModified)
{
{
if (unrealizedPL >= BreakevenThreshold)
{
ModifyStopLosses(position);
}
The issue i am having is that it is only moving the stoploss if the candle closes beyond the trigger value, but i want it to move the stoploss immediately when it hits the trigger value. I know that if i cange calculate to OnEachTick it would do that, but then the entry/exit critera are affected when i change that. Is there a way that i can kep the onbarupdate code using calculate.onBarClose while using OnEachTick for the onmarket data conditions? Or any other way to achieve movement of stoploss based on real time touch of the trigger price instead of only after a bar close beyond it?

Comment