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

# bars since last occurence...

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

    #16
    Thanks for sharing Leduc.

    I spend the whole day trying something simpler than the difficulties experienced above and I didn't get it right. (Btw, anyone an idea how to significant reduce the incredible NinjaScript learning curve? )

    Anyway, I've created an indicator which draws an arrow above the bar when the high is higher than the MAX(High, 9) value. So with every new high for an period, there is an visual signal. My problem/question is: how can I calculate the numbers of bars between two signals? (i.e. between two tops)

    I've searched this forum and read the various discussions regarding 'counting' of bars, but I'm even more confused than when I started.

    Here's what I have so far:
    if (CurrentBar < 5)
    return;
    if( High[1] >= MAX(High, 9)[1] && High[0] < MAX(High, 9)[0])
    {
    DrawArrowDown("TopSignal" + CurrentBar, true, 0, High[0] + (Range()[0] / 3), Color.Red);
    }

    I've tried to initialize an new variable in which to store the currentbar value, and in such a way tried to calculate the numbers of bars between that variable and the CurrentBar value. I didn't get that to work.

    Anyone perhaps have an idea which can help me out?

    Regards,

    Comment


      #17
      Hello Jos,

      You may want to look into Most Recent Occurrence and see if it can do this for you.
      Ryan M.NinjaTrader Customer Service

      Comment


        #18
        Originally posted by NinjaTrader_RyanM View Post
        Hello Jos,

        You may want to look into Most Recent Occurrence and see if it can do this for you.
        Thanks Ryan, that is the missing link!

        It works now with this code:
        Code:
        [FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]
        [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] (CurrentBar < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]45[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1])
        [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1];
        [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]( High[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] >= MAX(High, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1])[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] && High[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] < MAX(High, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1])[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]])
        {
        Print(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]].ToString() + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800000][FONT=Courier New][SIZE=1][COLOR=#800000][FONT=Courier New][SIZE=1][COLOR=#800000]" previous bar = new high. High[1] = "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] + High[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]]);
        DrawArrowDown([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800000][FONT=Courier New][SIZE=1][COLOR=#800000][FONT=Courier New][SIZE=1][COLOR=#800000]"TopSignal"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] + CurrentBar, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1], High[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] + (Range()[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] / [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]3[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]), Color.Red);
        [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]int[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] barsAgo = MRO([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]delegate[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] {[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff][FONT=Courier New][SIZE=1][COLOR=#0000ff]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] High[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] >= MAX(High, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1])[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] && High[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]] < MAX(High, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]9[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1])[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]];}, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]2[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1], [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]45[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]);
        Print(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080][FONT=Courier New][SIZE=1][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1]].ToString() + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=1][COLOR=#800000][FONT=Courier New][SIZE=1][COLOR=#800000][FONT=Courier New][SIZE=1][COLOR=#800000]" barsAgo previous top: "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=1][FONT=Courier New][SIZE=1] + barsAgo);
        }
        [/SIZE][/FONT][/SIZE][/FONT]
        Thanks again.

        Regards,

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        17 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        5 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Started by poplagelu, Today, 05:00 AM
        0 responses
        3 views
        0 likes
        Last Post poplagelu  
        Working...
        X