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

Variable for bars lookback

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

    Variable for bars lookback

    I am looking for a way to use a variable (or something similar) to vary the number of bars to look back. I've been using something like the code below but it very limited and uses excessive code.

    && TMT_MPL_MACDBB(20, 12, 1, 45, 5).MACDPlot[0] > 1
    && TMT_MPL_MACDBB(20, 12, 1, 45, 5).MACDPlot[1] > 1
    && TMT_MPL_MACDBB(20, 12, 1, 45, 5).MACDPlot[2] > 1
    && TMT_MPL_MACDBB(20, 12, 1, 45, 5).MACDPlot[3] > 1

    Any help would be appreciated....

    Thanks

    #2
    Hello mlarocco,

    Thank you for the post.

    One way to be less verbose is to use a FOR loop in some way to check the condition. Keep in mind, the following example is not the same as applying the AND operator to all four conditions. ANDing all of the statements ensures that every condition evaluates to true, then the IF block executes. You could do something like the following:

    Code:
    bool myflag = false;
    
    for(int i = 0; i < 4; ++i){
    
            if(myflag == false){
            
                if(TMT_MPL_MACDBB(20, 12, 1, 45, 5).MACDPlot[i] > 1)
                   myflag = true;
    
             }
    
             if(myflag == true){
                //do something
                break;
              }
    
    }
    This would be the only way to write fewer indicator constructors.

    Please let me know if I may be of any further assistance.
    Last edited by NinjaTrader_ChrisL; 09-13-2017, 05:02 PM.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks, I will try that

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by pmachiraju, 11-01-2023, 04:46 AM
      8 responses
      148 views
      0 likes
      Last Post rehmans
      by rehmans
       
      Started by mattbsea, Today, 05:44 PM
      0 responses
      5 views
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      33 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      5 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,282 views
      0 likes
      Last Post Leafcutter  
      Working...
      X