I have a simple OnUpdate() function that does the following
if (BarsInProgress == 0) {
if (IsFirstTickOfBar && Open[0] < EMA1[0] && Close[0] > EMA1[0])
{
EnterLong(2)
ExitLongStopMarket(Close[0] - 10);
}
}
I also have the same function with one more condition.
if (BarsInProgress == 0) {
if (Position.MarketPosition == MarketPosition.Flat) {
if (IsFirstTickOfBar && Open[0] < EMA1[0] && Close[0] > EMA1[0])
{
EnterLong(2)
ExitLongStopMarket(Close[0] - 10);
}
}
}
If I run the first one, the Stop is recalculated on each bar so it basically stops out if the price goes below the previous bar's close - 10
If I run the second one... my stop never hits. Is this because EnterLongStopMarket() needs to be set on each bar update? I thought if I call this function once, the stop order should exist forever until
1. it is hit
2. I close my long position
3. I go short so the long stop should be canceled because I exited all longs.
How do I call ExitLongStopMarket() just once and have the stop order exist for more than just one bar?
Comment