Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 love2code2trade, 04-17-2024, 01:45 PM
          4 responses
          36 views
          0 likes
          Last Post love2code2trade  
          Started by alifarahani, Today, 09:40 AM
          2 responses
          13 views
          0 likes
          Last Post alifarahani  
          Started by junkone, Today, 11:37 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by pickmyonlineclass, Today, 12:23 PM
          0 responses
          1 view
          0 likes
          Last Post pickmyonlineclass  
          Started by frankthearm, Yesterday, 09:08 AM
          12 responses
          44 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X