Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The condition does not trigger

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

    The condition does not trigger

    I am back after going a long time without writing code, and it may sound super easy. I have not been able to find the problem.

    Can you help me find the reason for not triggering the draw? (I am checking these conditions; the others are working properly).

    I am trying to add a condition for my strategy:

    Primary Timeframe 60 minutes
    Secondary Timeframe 15 minutes

    The condition will run on each tick and on the secondary timeframe:

    If the current high crosses above the previous high, draw a vertical line.

    If the current low crosses below the previous low, draw a vertical line.


    The code I wrote goes like this:

    Code:
    ...
    else if (State == State.Configure)
                {
                    AddDataSeries(Data.BarsPeriodType.Minute, 15);
                }
                else if (State == State.DataLoaded)
                {                
                    MAX1                = MAX(Highs[1], 1);
                    MIN1                = MIN(Lows[1], 1);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0)
                    return;
    
                if (CurrentBars[1] < 1)
                    return;
    
                 // Set 1
                if (CrossAbove(Highs[1], MAX1, 1))
                {
                    Draw.VerticalLine(this, @"max1 Vertical line_1", 0, Brushes.Lime, DashStyleHelper.Solid, 2);
                }
    
                 // Set 2
                if (CrossBelow(Lows[1], MIN1, 1))
                {
                    Draw.VerticalLine(this, @"max1 Vertical line_2", 0, Brushes.Red, DashStyleHelper.Solid, 2);
                }
    
            }
        }​

    #2
    Hello Jorge.andres.o,

    Thanks for your post.

    In the code you shared I see you are checking if you have enough bars for the added secondary series but not for the primary series. Add a CurrentBars condition in your script to make sure you have enough bars for the primary series also.

    CurrentBars - https://ninjatrader.com/support/help...urrentbars.htm
    Make sure you have enough bars - https://ninjatrader.com/support/help...nough_bars.htm

    If a script is not behaving as expected then debugging prints should be added one line above your condition that prints out all values being used in that condition along with the time of the bar to see how the logic is processing.

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    And, see this help guide documentation for more information about working with Multi-Timeframe/Multi-Instrument NinjaScripts: https://ninjatrader.com/support/help...nstruments.htm

    You may also view the SampleMultiTimeframe and SampleMultiInstrument scripts that comes with NinjaTrader. To view the scripts, open a New > NinjaScript Editor window, open the Strategies folder, and double click on the file you want to view the code of.​​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    38 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 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