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

Limitation of Strategy Builder in comparing prices

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

    Limitation of Strategy Builder in comparing prices

    How can I calculate the "Range" (High Minus Low) of the last 3 bars and then divide by 3 and compare that average to the last bar using strategy builder?

    I can subtract all of the Lows from all of the Highs but without the benefit of parentheses, I can't divide by 3 or it will only divide the last number by 3.

    Thanks

    Sam

    #2
    Hello Sam,

    Thanks for your post.

    The Strategy Builder is designed to build simple strategies. It is not robust enough to perform complex mathematical operations. The code will need to be unlocked to perform the calculation.

    I would suggest to write your strategy as much as you can in the Strategy Builder, and then to make a copy that you can unlock and edit in the NinjaScript Editor. You can go to the Welcome page of the Strategy Builder, and then place your mouse over your strategy in the Strategy Selector and click Save As to make a copy. Once the copy is made, you can unlock the code and edit the code manually to add your mathematical calculations.

    Something like the following could calculate the average range:

    Code:
    if (CurrentBar < 3)
        return;
    
    double myAvg = ((High[0] - Low[0]) + (High[1] - Low[1]) + (High[2] - Low[2])) / 3;
    The NinjaScript Editor tutorial gives a good transition from using the Strategy Builder to generate code, and using that generated code in an unlocked strategy.

    NinjaScript Editor 401 (publicly available) - https://www.youtube.com/watch?v=BA0W4ECyVdc

    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment


      #3
      Thanks Jim. I had a feeling.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by GussJ, 03-04-2020, 03:11 PM
      11 responses
      3,228 views
      0 likes
      Last Post xiinteractive  
      Started by andrewtrades, Today, 04:57 PM
      1 response
      13 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      7 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      440 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      12 views
      0 likes
      Last Post FAQtrader  
      Working...
      X