• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 joemiller, Today, 07:33 AM
        0 responses
        6 views
        0 likes
        Last Post joemiller  
        Started by isnercrypto, Today, 06:42 AM
        0 responses
        4 views
        0 likes
        Last Post isnercrypto  
        Started by Coursocied67, Today, 04:02 AM
        0 responses
        4 views
        0 likes
        Last Post Coursocied67  
        Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
        7 responses
        36 views
        0 likes
        Last Post DaveS
        by DaveS
         
        Started by claxxical, Yesterday, 10:00 PM
        0 responses
        9 views
        0 likes
        Last Post claxxical  
        Working...
        X