Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The Strat breakouts indicator

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

    The Strat breakouts indicator

    I'm trying to make an indicator using a strategy cause its easier and theres no Indicator Builder program.
    All I'm trying to do is paint/draw an arrow where the current candle has broken above/below the previous candle (on the 15minute charts)
    NinjaTrader sometimes works, but usually doesnt.
    I started to make a custom series but then thought I wouldnt need it.
    What am I doing wrong?
    Thanks





    Click image for larger version  Name:	Untitled.png Views:	0 Size:	741.5 KB ID:	1244943





    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class JonsTheStratIndicatorStrategy : Strategy
        {
    
            private Series<double> Green;
            private Series<double> Red;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"";
                    Name                                        = "JonsTheStratIndicatorStrategy";
                    Calculate                                    = Calculate.OnBarClose;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 0;
                    StartBehavior                                = StartBehavior.WaitUntilFlat;
                    TimeInForce                                    = TimeInForce.Day;
                    TraceOrders                                    = false;
                    RealtimeErrorHandling                        = RealtimeErrorHandling.IgnoreAllErrors;
                    StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                            = 1;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;
                }
                else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Minute, 15);
                }
                else if (State == State.DataLoaded)
                {                
                    Green = new Series<double>(this);
                    Red = new Series<double>(this);            
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0)
                    return;
    
                if (CurrentBars[1] < 1)
                    return;
    
    [B] // Set 1
                if (Closes[1][0] > Highs[1][1])
                {
                    Green[0] = 0;
                    BarBrush = Brushes.DarkGreen;
                }
    
                 // Set 2
                if (Closes[1][0] < Lows[1][1])
                {
                    BarBrush = Brushes.Maroon;
                    Red[0] = 0;[/B]
                }
    
            }
        }
    }

    #2
    Hello ezrollin,

    The code you have checks if the close of the current BarsInProgress 1 bar is greater than the high of the previous BarsInProgress 1 bar. This appears to be correct if that is what you want.

    Use Prints to understand behavior.

    Below is a link to a forum post on using print to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121
    Code:
    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
    return;
    
    Print(string.Format("{0} | BarsInProgress: {0}, {1} {2} {3} | Closes[1][0]: {4} > Highs[1][1]: {5}", Time[0], BarsInProgress, Instrument.FullName, BarsArray[BarsInProgress].BarsPeriod.Value, BarsArray[BarsInProgress].BarsPeriod.BarsPeriodType, Closes[1][0], Highs[1][1] ));
    
    if (BarsInProgress == 0 && Closes[1][0] > Highs[1][1])
    {
    Print(string.Format("{0} | BIP 1 close is above previous BIP 1 high", Time[0]));
    }
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm just trying to say that if (On Bar Close) this bar closes lower than the previous bar then its a breakout
      I cant even do that in strategy builder.
      I'm figuring everything is based OnBarClose (cause thats what I chose)
      but I do see in my code that it says bars in progress (I never chose that)


      Comment


        #4
        Hello ezrollin,

        There is a 15 minute data series added. The Strategy Builder is not able to trigger actions on that secondary series and can only use the data from the secondary series when the primary series is updating.

        Your current code is selecting that 15 minute series for data, when the primary series bar closes.

        Were you intending to trigger actions when the 15 minute series bar closes?
        If so, you will need to unlock the script and code by hand.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X