Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculating % change in price over period

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

    Calculating % change in price over period

    First, full disclosure, I'm new to programming and working to have a better understanding of it, and frankly maybe a bit in over my head, but I'm determined to figure this out. So I want to say thank you in advance to anyone that can help.

    That being said, I want to build a strategy based on a percent change in price in a given range. Whereas I'm looking for a reversal in price in a given area based on Fibs. That being said, my first order of business is to calculate the percent change in price, however, I'm not really seeing how I can accomplish this in the strategy builder itself.

    My approach has been to identify the low and high over a period of bars and record these values into a variable. Where such I was hoping to calculate the percentage change of a new low or high of the retracement, be it a long or short against the original distance of the low and high. Mathematically, the formula would be High - Low_a = X; X - (High - Low_b) / X = Y; Y x 100 = % change. But again, I'm not seeing how to accomplish this within the strategy builder.

    ie. Low = 1606.1, High = 1614.3, Low_b = 1609.9
    1614.3 - 1606.1 = 8.2
    1614.3 - 1609.9 = 4.4
    (4.4 / 8.2 = 0.537)*100 = 53.66%

    I've searched youtube and this forum for similar discussions, however, I've not been able to find anything. Any help, and or direction would be appreciated.

    #2
    Hello Lowerlevel1,

    The Strategy Builder is not capable of math in any place other than with offsets.

    For custom math, the strategy would need to be unlocked and coded by hand.

    Are you wanting the percent from the high to the low as a percent of the high?

    ((High[0] - Low[0]) / High[0]) * 100

    Are you wanting the percent change from the previous bar?

    ((Close[0] - Close[1]) / Close[0]) * 100
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Lowerlevel1,
      The StrategyBuilder (SB) is not really designed for more advanced calculations. However, the coding challenge you described can still be managed in the SB if you really push it to its limit.
      Consider to add Custom Series in SB. This trick will allow you to perform divisions of custom values in SB !!!
      Initiate/Update these Custom Series as needed. Don't forget to reset them back to zero from time to time (e.g. every day) and then start over. Otherwise, you will get only very few trades.
      DeltASeries[0] = HighASeries[0] - LowASeries[0]
      DeltBSeries[0] = HighASeries[0] - LowBSeries[0]
      PercentSeries[0] = DeltBSeries[0] / DeltASeries[0].
      That division is the critical part. Once you have this, the rest is easy.
      You could compare the PercentSeries to some sort of threshold (e.g. Input MinPercent), etc., and then fire off your trades.
      Print to Output Window could look like the attached (NQ 12-2020, 60 Min), with daily reset of all vars/series on the first bar.
      Have fun.
      NT-Roland
      Attached Files
      Last edited by NT-Roland; 10-25-2020, 05:00 PM.

      Comment


        #4
        Originally posted by NT-Roland View Post
        Hi Lowerlevel1,
        The StrategyBuilder (SB) is not really designed for more advanced calculations. However, the coding challenge you described can still be managed in the SB if you really push it to its limit.
        Consider to add Custom Series in SB. This trick will allow you to perform divisions of custom values in SB !!!
        Initiate/Update these Custom Series as needed. Don't forget to reset them back to zero from time to time (e.g. every day) and then start over. Otherwise, you will get only very few trades.
        DeltASeries[0] = HighASeries[0] - LowASeries[0]
        DeltBSeries[0] = HighASeries[0] - LowBSeries[0]
        PercentSeries[0] = DeltBSeries[0] / DeltASeries[0].
        That division is the critical part. Once you have this, the rest is easy.
        You could compare the PercentSeries to some sort of threshold (e.g. Input MinPercent), etc., and then fire off your trades.
        Print to Output Window could look like the attached (NQ 12-2020, 60 Min), with daily reset of all vars/series on the first bar.
        Have fun.
        NT-Roland
        Thank you NT-Roland. I'll give that a shot. I'm new to programming and working through it by trial and error and doing some online study courses. I'm determined to figure it out though. I have some things in my head that I'd like to get on the screen to see how they would pan out. I guess in all due time.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by liadmz, Today, 03:39 PM
        0 responses
        3 views
        0 likes
        Last Post liadmz
        by liadmz
         
        Started by artson, Today, 03:29 PM
        0 responses
        2 views
        0 likes
        Last Post artson
        by artson
         
        Started by NinjaTrader_ChrisL, Today, 03:06 PM
        0 responses
        6 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by sandman, Today, 02:45 PM
        2 responses
        10 views
        0 likes
        Last Post sandman
        by sandman
         
        Started by grande846, Today, 01:04 PM
        4 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Working...
        X