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

low/ high series

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

    low/ high series

    Hello,
    I'm trying to get values after High(low) is equal to currentHigh(low). I thought to use bool variable to set the condition. condition is true when High(low) is equal to currentHigh(low) and turn false when price from currentdaylow reaches generate a new CDH or when price from CDH generate a new CDL.
    i tried the code below but after the first candle of the day close the iteration.I would like the indicator repeats the iteration for all day not just 1 time. could some good soul give some illuminations please?


    {if(CurrentBar<1)
    return;
    // if (Time[0].TimeOfDay < new TimeSpan(9, 0, 0))
    // return;
    else if(CurrentBar>0)
    low = false;
    if(Low[0] == CurrentDayOHL1.CurrentLow[0])
    {

    low = true;
    i=0;
    while(true)
    { i++;
    if(High[0]==CurrentDayOHL1.CurrentHigh[0])
    Print(Close[0].ToString()+" HIGH "+Time[0].ToString());
    break;

    }
    }
    low = false;
    if(High[0] == CurrentDayOHL1.CurrentHigh[0])
    {
    high = true;
    j = 0;
    while(true)
    {
    j++;
    if(Low[0] == CurrentDayOHL1.CurrentLow[0])
    Print(Close[0].ToString()+" LOW "+Time[0].ToString());
    break;
    }

    }
    high = false;
    return;


    }
    }
    Last edited by zteck; 08-25-2017, 09:33 AM.

    #2
    Hello zteck,

    Thanks for writing in to our Support team.

    In the code you provided, you are using breaks to exit your while statements so that on the first iteration of the while loop, you increment the i variable by one, then check:
    if(High[0]==CurrentDayOHL1.CurrentHigh[0])
    Print(Close[0].ToString()+" HIGH "+Time[0].ToString());

    Since you do not have the break contained in curly braces, the break statement always executes after your if check regardless if it evaluates to true or false and takes you out of that loop.

    I also want to point out that you are not tying your low or high bool to your while statement, so it is always evaluating as true and never gets set to false. You can set up your while statement in such a way that it stops executing after a defined point ( i < 10 for example). In this way, you will no longer need to include the break to exit your loop.

    Additionally, the amount of times that OnBarUpdate() is called will be determined by the Calculate property in your script. For example, OnBarClose will only cause OnBarUpdate() to be called once at the close of each bar. If you are not including this code within the OnBarUpdate() method, it would not be called with the same frequency as is defined by the Calculate property.

    You can read more about the Calculate settings in our help guide here:
    http://ninjatrader.com/support/helpG.../calculate.htm

    Please let me know if I may be of any further assistance.
    Alan S.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by pechtri, 06-22-2023, 02:31 AM
    9 responses
    122 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by frankthearm, 04-18-2024, 09:08 AM
    16 responses
    66 views
    0 likes
    Last Post NinjaTrader_Clayton  
    Started by habeebft, Today, 01:18 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by benmarkal, Today, 12:52 PM
    2 responses
    14 views
    0 likes
    Last Post benmarkal  
    Started by f.saeidi, Today, 01:38 PM
    1 response
    8 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X