Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Breakout Strategy

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

    Breakout Strategy

    Hi,

    I am trying to program a strategy to buy on a 20 bar high and sell on a 20 bar low.

    However I can't really get the strategy to execute according to plan... it doesn't seem like it looks at the highest high of the last 20 bars and instead just enters quite randomly...

    Could you please maybe advise on where I am going wrong with this code?

    Code:
    protected override void OnBarUpdate()
            {
                // Condition set 1
                if (EMA(20)[0] > EMA(60)[0]
                    && EMA(60)[0] > EMA(100)[0]
                    && High[0] > MAX(High,20)[1])
                {
                    EnterLong(DefaultQuantity, "Long");
                }
    
                // Condition set 2
                if (Close[0] < MAX(Low,20)[1])
                {
                    ExitLong("Close Short", "Long");
                }
    
                // Condition set 3
                if (EMA(20)[0] < EMA(60)[0]
                    && EMA(60)[0] < EMA(100)[0]
                    && Close[0] < MAX(Low,20)[1])
                {
                    EnterShort(DefaultQuantity, "Short");
                }
    
                // Condition set 4
                if (Close[0] > MAX(High,20)[1])
                {
                    ExitShort("Exit Short", "Short");
                }
            }

    #2
    Hi Nexas,

    Thank you for the post and welcome to the forums!

    For testing the low values you may want to use MIN instead of MAX.
    MAX will return the highest value for the data series, in this case the highest low price.
    Not sure if this is the route you wanted to go or not.

    Could you give a detailed explanation of what you expect your strategy to do?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Thank you for your quick response.

      I tried the MIN which you were quite right about but it still doesn't seem to execute as expected....

      Basically I am using a Renko chart and I want to say that as long as the EMA's are aligned I want to enter once I get a 20 bar breakout.

      So I think it is quite a simple strategy but I wait your advice.

      thanks

      Nexas

      Comment


        #4
        Nexas,

        I would use some debugging tools to see where your strategy may or may not be working.

        First of all you would want to use Print() statements to verify values are what you expect - Debugging your NinjaScript code.

        For strategies add TraceOrders = true to your Initialize() method and you can then view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders

        It may also help to add drawing objects to your chart for signal and condition confirmation - Drawing Objects.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by Nexas View Post
          Hi,

          Thank you for your quick response.

          I tried the MIN which you were quite right about but it still doesn't seem to execute as expected....

          Basically I am using a Renko chart and I want to say that as long as the EMA's are aligned I want to enter once I get a 20 bar breakout.

          So I think it is quite a simple strategy but I wait your advice.

          thanks

          Nexas
          You are using Renko bars.

          You may want to read this thread, which explains why Renko bars give false backtest results, that are essentially useless for validation of trading systems.

          ref: http://www.ninjatrader.com/support/f...ighlight=renko

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          573 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X