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

Prevent Stop from updating on new (condition = true) bar

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

    Prevent Stop from updating on new (condition = true) bar

    Hello all,

    My strategy runs smoothly, except for one annoying little thing, which is that if I am currently in a position and a subsequent bar triggers the same conditions that put me in the market, then a new order will NOT be placed (good), because of my entries per direction rule, however the stop loss will change to the last bar that the conditions were true for (bad).

    How can I prevent an action from triggering while I am in a position, if the action is part of the same condition group?

    My stop code is placed directly above my entry action code, and as far as I can tell it needs to be, because nothing else quite worked properly. My stop is supposed to remain static whilst in a position, until a certain PnL calculation updates it, acting as a profit cushion. My stop does indeed remain static until told otherwise, unless, as I previously stated, the condition is true again on a new bar.

    Halp!

    Thanks.

    #2
    Hello lunardiplomacy,

    Thank you for the post.

    In this situation if this happens on a new bar the position should be updated so you should be able to use:

    Code:
    if(Position.MarketPosition == MarketPosition.Flat)


    Checking for flat would only allow the entry in that situation which otherwise will also prevent the stop from being called again.


    If that does not apply to your situation please let me know and we can review that further.


    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse, thank you for getting back to me in such a timely manner.

      The issue with checking that my position is flat is that these same conditions need to be available for a reversal intrabar (although not exclusively). So this would work when starting from flat, but not in every use case i.e. a reversal situation.

      Comment


        #4
        Hello lunardiplomacy,

        In your reversal case could you do a combination condition like the following? If you are flat or in the opposite position, do the opposite entry:

        Code:
        if(Position.MarketPosition == MarketPosition.Flat || Position.MarketPosition == MarketPosition.Short)
        EnterLong
        
        if(Position.MarketPosition == MarketPosition.Flat || Position.MarketPosition == MarketPosition.Long)
        EnterShort

        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          Yeah, that works. Not sure why I didn't try that.

          Thanks, Jesse!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Barry Milan, Yesterday, 10:35 PM
          4 responses
          15 views
          0 likes
          Last Post Barry Milan  
          Started by DanielSanMartin, Yesterday, 02:37 PM
          2 responses
          13 views
          0 likes
          Last Post DanielSanMartin  
          Started by DJ888, 04-16-2024, 06:09 PM
          4 responses
          12 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          11 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          8 views
          0 likes
          Last Post nandhumca  
          Working...
          X