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 cre8able, Today, 03:20 PM
          0 responses
          5 views
          0 likes
          Last Post cre8able  
          Started by Fran888, 02-16-2024, 10:48 AM
          3 responses
          47 views
          0 likes
          Last Post Sam2515
          by Sam2515
           
          Started by martin70, 03-24-2023, 04:58 AM
          15 responses
          114 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by The_Sec, Today, 02:29 PM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by jeronymite, 04-12-2024, 04:26 PM
          2 responses
          32 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X