• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
          Patrick H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Erwin Beckers, 11-04-2018, 02:39 AM
          4 responses
          69 views
          2 likes
          Last Post brucerobinson  
          Started by ntbone, Today, 01:25 AM
          0 responses
          2 views
          0 likes
          Last Post ntbone
          by ntbone
           
          Started by bomanpbm, Yesterday, 09:27 PM
          0 responses
          2 views
          0 likes
          Last Post bomanpbm  
          Started by tgn55, Yesterday, 08:47 AM
          0 responses
          8 views
          0 likes
          Last Post tgn55
          by tgn55
           
          Started by ballboy11, 05-04-2019, 10:26 AM
          6 responses
          59 views
          0 likes
          Last Post Kermit
          by Kermit
           
          Working...
          X