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

  • NinjaTrader_PaulH
    replied
    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.

    Leave a comment:


  • gretzkyless
    replied
    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.

    Leave a comment:


  • NinjaTrader_PaulH
    replied
    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.

    Leave a comment:


  • gretzkyless
    started a topic Conditional formatting

    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.

Latest Posts

Collapse

Topics Statistics Last Post
Started by carnitron, Today, 08:42 PM
0 responses
5 views
0 likes
Last Post carnitron  
Started by strategist007, Today, 07:51 PM
0 responses
6 views
0 likes
Last Post strategist007  
Started by StockTrader88, 03-06-2021, 08:58 AM
44 responses
3,974 views
3 likes
Last Post jhudas88  
Started by rbeckmann05, Today, 06:48 PM
0 responses
8 views
0 likes
Last Post rbeckmann05  
Started by rhyminkevin, Today, 04:58 PM
4 responses
58 views
0 likes
Last Post dp8282
by dp8282
 
Working...
X