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

CrossBelow

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

    CrossBelow

    Hello,

    can you please help me with a simple problem with CrossBelow?

    I want the program to start some action when the price is below same trigger. This action should continue in 5 concesutive bars no matter on how the price will move during these 5 bars.

    I used the simple CrossBelow:

    Code:
    [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000](CrossBelow(Closes[[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]], -[/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]800[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000], [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]))[/COLOR]
    {
    Print(Closes[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]][[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);
    };
    [/SIZE][/FONT][/SIZE][/FONT]
    which works only when the condition holds, i.e. action is not done when the price is higher than -800 during following 5 bars.

    Can you please help me on that? Shall I use any other command?
    Stepan

    #2
    Hello Stepan,

    The 5 value in your CrossBelow condition is a lookback. This means it looks for a cross condition anytime in the last 5 bars.

    This action should continue in 5 concesutive bars no matter on how the price will move during these 5 bars.
    I would first look at LeastRecentOccurence to see if it works for you. In example below lookback on cross condition changed to 1, and the LRO lookback is 5.

    int barsAgo = LRO(delegate {return CrossBelow(Closes[1], -800, 1) ;}, 1, 5);

    if (barsAgo > -1)
    {
    DrawDiamond("diamond" + CurrentBar, true,0, High[0], Color.Purple);
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I double checked and you're using a multiseries script, which will not work with LRO, MRO.

      In this case you can custom code something, by working with CurrentBar. I helped another community member with a similar problem in this thread.

      Please review posts 8 - 12 and let me know if you're not able to come up with something.
      Ryan M.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_RyanM View Post
        I double checked and you're using a multiseries script, which will not work with LRO, MRO.

        In this case you can custom code something, by working with CurrentBar. I helped another community member with a similar problem in this thread.

        Please review posts 8 - 12 and let me know if you're not able to come up with something.
        Hi Ryan,

        thank you for your hint. I came up with a code which works exactly as I wanted
        Stepan

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by gentlebenthebear, Today, 01:30 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by Aviram Y, Today, 05:29 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by cls71, Today, 04:45 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by TradeForge, Today, 02:09 AM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by elirion, Today, 01:36 AM
        2 responses
        14 views
        0 likes
        Last Post elirion
        by elirion
         
        Working...
        X