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

3 Questions for Strategy Builder - Math Calculations and using OR

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

    3 Questions for Strategy Builder - Math Calculations and using OR

    A couple of quick (hopefully) questions:

    1. How can we do math formulas using Strategy Builder... ie. how can we make a condition such if the current price is at least less than 7 ticks away from the pivot point, S1, S2 or R1 or R2 don't take the trade? or for another example, Exit when the profit is 2 x the 4 Bar ATR?

    2. How to Exit a position off of an indicator and a set amount of profit or loss... ie. RSI crossing its avg AND a set amount of profit or loss in the current position... (like say, 12 ticks loss on a futures contrac)t has occurred? Both conditions must be true or the trade stays open?

    or instead of having 12 ticks... say 3 x the ATR that way it's dynamic depending on that day's action?

    3. For the conditions in Strategy Builder... can you have an OR type of condition... this OR That... rather than it being ALL or any one of the conditions.

    #2
    Hello TicksBandit,

    The Strategy Builder in NinjaTrader 8 is not able to do compound assignments and is only able to do simple assignments.

    For any scripts that require complex logic, these must be unlocked and coded manually.


    In your unlocked script, you can call an indicator, do math with this and use this as a price for an exit order.

    For example:

    double stopPrice = Instrument.MasterInstrument.RoundToTickSize( SMA(5)[0] - 3 * TickSize );

    if (stopPrice < GetCurrentBid())
    {
    EnterLongStopMarket( stopPrice );
    }

    This would ensure that the sma minus 3 ticks (and rounded to the nearest valid tick price) is less than the bid and then would place an exit stop market order at the sma minus 3 ticks.


    Yes, in the Strategy Builder select 'If Any' on the upper left drop-down and this will make the conditions compared with ors (||) instead of ands (&&).
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Wow, thanks for the real quick response times!

      On the OR question... can you have it AND as well as OR in the strategy builder ie. This AND that AND this OR that. In other words... say, have 3 conditions that must be true and the last one can be an "OR" condition - such as the 4th condition can be this OR That... but the other 3 conditions before it all must be true.

      Comment


        #4
        Hello TicksBandit,

        Unfortunately, you would need separate condition sets for that.
        All of the conditions in a set can be separated with ors or can be separated with ands, but its not possible mix these in a single set.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Can you give me a quick code snippet for the ATR question I had (ie. use a stop and profit target that is 3 * ATR) and another cod snipper in relation to the Pivot Points, S1, S2... (don't take trade if the current price is within 1.5 ATR of the next Pivot Point, R1 or R2 pivot points. Thanks.

          Comment


            #6
            Hello TicksBandit,

            I forgot about the groups ability in the Strategy Builder.

            You can create subgroups that use 'If Any' and separate these groups with 'If All'.

            Below is a publicly available link to the help guide.



            With the ATR you are wanting to add this to a value correct?

            For example:

            double closePlusAtr = Close[0] + Instrument.MasterInstrument.RoundToTickSize(3 * ATR(14)[0]);

            Print(closePlusAtr);
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by hurleydood, 09-12-2019, 10:45 AM
            14 responses
            1,091 views
            0 likes
            Last Post Board game geek  
            Started by cre8able, Yesterday, 04:16 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by cre8able, Yesterday, 04:22 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by stafe, 04-15-2024, 08:34 PM
            5 responses
            28 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by StrongLikeBull, Yesterday, 04:05 PM
            1 response
            12 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X