Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate Error when enabling strategy in replay

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Ok thank you very much.

    I have a bool set as HappenedAlready == false, so I'll adjust that and see what I get.

    Thank you again. You have been extremely helpful with all of this.
    Chris

    Comment


      #17
      I don't know if you have EntriesPerDirection in use, but that will prevent multiple same side orders at Ninjarrader level.

      I prefer variables myself, and use that as backup so to speak.

      Comment


        #18
        Hello all,

        So I have been able to get the strategy to work and the breakeven works great.

        One issue though. When I add new logic to have the stoploss move to 4 ticks profit once price is 8 ticks of profit, I get a weird amount of order fills that causes 'order rejection' and closes the strategy. Can anyone help me fix the logic so this doesn't happen and the stoploss moves as wanted?

        Here is the breakeven code:
        // Resets the stop loss to the original value when all positions are closed
        if (Position.MarketPosition == MarketPosition.Flat)
        {
        SetStopLoss(CalculationMode.Ticks, StopLossTicks);
        }

        // If a long position is open, allow for stop loss modification to breakeven
        else if (Position.MarketPosition == MarketPosition.Long)
        {
        // Once the price is greater than entry price + 4 ticks, set stop loss to breakeven
        if (Close[0] > Position.AveragePrice + 4 * TickSize)
        {
        Print(Time[0].ToString()+ @"This should be changing SL");
        SetStopLoss(CalculationMode.Price, Position.AveragePrice);
        }
        Now here is my add logic:
        // Resets the stop loss to the original value when all positions are closed
        if (Position.MarketPosition == MarketPosition.Flat)
        {
        SetStopLoss(CalculationMode.Ticks, StopLossTicks);
        }

        // If a long position is open, allow for stop loss modification to breakeven
        else if (Position.MarketPosition == MarketPosition.Long)
        {
        // Once the price is greater than entry price + 4 ticks, set stop loss to breakeven
        if (Close[0] > Position.AveragePrice + 4 * TickSize)
        {
        Print(Time[0].ToString()+ @"This should be changing SL");
        SetStopLoss(CalculationMode.Price, Position.AveragePrice);
        }

        // Once the price is 8 ticks profit and stop loss is at average price, allow for profit lock in
        if (Close[0] > Position.AveragePrice + 8 * TickSize)
        {
        Print(Time[0].ToString()+ @"This should move SL to 4 tick profit");
        SetStopLoss(CalculationMode.Price, Target1);
        }
        }
        Any help would be useful.

        Thank you,
        Chris

        Update:

        So I think a problem is that if while a position is long, and the conditions for a short entry happen, the strategy will try and close the long and then open the short.

        Is there a way to set a bool so that if a position is currently open, wait for current market position to return to flat before trying to initialize another order?

        Thanks again.
        Last edited by chrisca; 01-12-2018, 02:19 PM.

        Comment


          #19
          Hello chrisca,

          Thank you for your patience.

          I would first recommend you ensure the first condition does not interact with the Stop Loss after 8 ticks. For example:
          Code:
          if (Close[0] > Position.AveragePrice + 4 * TickSize && Close[0] < Position.AveragePrice + 8 * TickSize)
          If this does not correct the behavior can you advise what Target1 is set to and what the full rejection message details?

          I look forward to your response.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          56 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          132 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          45 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X