So I see three possibilities:
1) I execute the ExitShortStopMarket immediately after the entry. However, the entry may not have filled, so in this case it will be ignored, and this "if" Entry statement will never be entered again as shown below, because I don't want it to.
2) I execute the ExitShortStopMarket in the "if" statement as shown in my code below, but this fails to enter because MarketPosition.Short is never turning true (even though my account reflects a successful entry).
3) I execute the ExitShortStopMarket on every bar update after entry. I don't want to try this, because I don't know if it will repeat these stop orders throughout the rest of the bar. Is there some description of what the behavior would be if I am short 100 shares, then this executes repeatedly (multiple hundreds of times) to Exit those 100 shares in a stop order?
Please advise how to get around this problem and get my Stop Exit orders to work! Thanks
protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBars[0] < 1) return; if (State == State.Realtime) { if (IsFirstTickOfBar) { TradeCounter = 0; } if (TradeCounter < 1 && Position.MarketPosition == MarketPosition.Flat) { TriggerPrice = Close[0]; NumShares = Convert.ToInt32(PosSize/TriggerPrice); TradeCounter++; EnterShortLimit(NumShares, TriggerPrice); } if (TradeCounter == 1 && Position.MarketPosition == MarketPosition.Short) { TradeCounter++; ExitShortStopMarket(NumShares, TriggerPrice*1.2); } } }
Comment