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

Conditional formatting

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

    Conditional formatting

    I have figured out how to have one indicator trigger and then a signal plots when the second indicator triggers. The problem I'm having is the number of bars. I'm not sure how to code x number of bars back.

    Below is what I'm trying to do...
    Trigger - MACD_DiNapoli crosses up
    Signal for trade entry - Small trigger lines cross up.

    CODE TO MAKE THIS HAPPEN
    if
    (CrossAbove(MACD_DiNapoli(8.3897, 17.5185, 9.0503), MACD_DiNapoli(8.3897, 17.5185, 9.0503).Avg, 1))
    {
    condition1true = true;
    }

    if
    (condition1true == true && CrossAbove(RyanTriggerLinesSmall(20, 5).Plot1_Up, RyanTriggerLinesSmall(20, 5).Plot2_Up, 1)
    {
    DrawArrowUp("UpAarrow" + CurrentBar, true, 0, Low[0] - (offset * TickSize)-0.30, Color.Green);
    condition1true = false;
    }

    The problem is, sometimes the small trigger lines cross up many bars after MACD crosses up. I want to limit the number of bars back to 2. What am I missing? Please advise.

    #2
    Hello gretzkyless,

    Thanks for your post.

    If I understand correctly the issue is that the Macd crosses and you can have a variable number of bars that occur before the small triggers may cross and you want to limit the number of bars to two between the macd cross and the small trigger cross. So my answer will reflect that understanding.

    What would work is to remove the bool condition1true and use an integer variable that will hold the current bar number at the time of the macd cross and then test in the other condition to see that no more 2 bars have passed.

    if
    (CrossAbove(MACD_DiNapoli(8.3897, 17.5185, 9.0503), MACD_DiNapoli(8.3897, 17.5185, 9.0503).Avg, 1))
    {
    triggerBar = CurrentBar; // Save the bar number where this condition occurred
    }

    if
    (((CurrentBar - triggerBar ) <= 2) && CrossAbove(RyanTriggerLinesSmall(20, 5).Plot1_Up, RyanTriggerLinesSmall(20, 5).Plot2_Up, 1)
    {
    DrawArrowUp("UpAarrow" + CurrentBar, true, 0, Low[0] - (offset * TickSize)-0.30, Color.Green);
    }

    Here is a clarification of CurrentBar: http://www.ninjatrader.com/support/h...currentbar.htm

    Please let me know if I can be of further assistance.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul. You read my mind


      Will work on using the current bar as suggested to get the outcome I want.

      As a follow-up question, statement, I'm assuming that the more conditions I add, I would continue to use the current bar, but update as needed for each condition. Will find out shortly.

      Comment


        #4
        Hello gretzkyless,

        The use of the triggerBar is to set when the first condition occurred so that you can evaluate in the 2nd condition: have 2 or less bars occurred since the first condition was true? So you would only change the number of 2 if you wanted to increase the number of allowable bars between condition 1 and condition 2.

        You can certainly use the same code elsewhere that you need to keep the bars between conditions as a condition, just be careful to use a different variable name for triggerBar.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Johnny Santiago, 10-11-2019, 09:21 AM
        95 responses
        6,193 views
        0 likes
        Last Post xiinteractive  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        2 responses
        11 views
        0 likes
        Last Post xiinteractive  
        Started by Irukandji, Today, 09:34 AM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by RubenCazorla, Today, 09:07 AM
        1 response
        5 views
        0 likes
        Last Post RubenCazorla  
        Started by TraderBCL, Today, 04:38 AM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X