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

Working on different values than close

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

    Working on different values than close

    I am working on an anticipatory indicator/strategy and this problem should be easily answered. I'm trying to calculate the MACD for the current bar at the high - 8 ticks and low + 8 ticks (Working 8 tick range bars). I want the previous bars calculations still based on the previous closes.

    I'm working from the default MACD; from what I can tell the indicator is recursive and when I change Input[0]

    fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);

    to (Low[0] + 8 * TickSize) for example, it comes close, but it appears that it changes all of the previous bars calculations to (Low + 8) as well, thus not exactly correct. If there is an answer in another post please point me there.

    #2
    Originally posted by wallabee13 View Post
    I am working on an anticipatory indicator/strategy and this problem should be easily answered. I'm trying to calculate the MACD for the current bar at the high - 8 ticks and low + 8 ticks (Working 8 tick range bars). I want the previous bars calculations still based on the previous closes.

    I'm working from the default MACD; from what I can tell the indicator is recursive and when I change Input[0]

    fastEma.Set((2.0 / (1 + Fast)) * Input[0] + (1 - (2.0 / (1 + Fast))) * fastEma[1]);

    to (Low[0] + 8 * TickSize) for example, it comes close, but it appears that it changes all of the previous bars calculations to (Low + 8) as well, thus not exactly correct. If there is an answer in another post please point me there.
    Indicator Plots are based on dataSeries, so even if not recursive, you will still have the problem.

    You are going to have to modify the indicator, by adding separate dataSeries for your two other calculations. The comparison on each bar is then trivial.

    Comment


      #3
      I refuse to believe there isn't someway to call to the MACD of the previous bar, and then assign it values to calculate for the current bar. Even if I have to create an indicator on indicator, that's fine.

      I'm not quite sure what creating another DataSeries would do, given it would be the same periodicity. One would overwrite the other.

      Comment


        #4
        Originally posted by wallabee13 View Post
        I refuse to believe there isn't someway to call to the MACD of the previous bar, and then assign it values to calculate for the current bar. Even if I have to create an indicator on indicator, that's fine.

        I'm not quite sure what creating another DataSeries would do, given it would be the same periodicity. One would overwrite the other.
        Yes, you can call previous values of any Plot. The MACD is based on exponential moving averages, and the recursive calculation in the extant indicator shows this use of the previous value to calculate the current value, as per the most efficient way to calculate EMAs.

        What is hard to do, however, is to change inputs midstream. You seem to be saying that you should be able to directly take the MACD of the Closes, and calculate from it the MACD of the Highs or Lows. While, it may not exactly be impossible, I doubt that it would be efficient, or conveniently debuggable. Much simpler is to use 3 different dataSeries to hold the 3 different calculations.

        DataSeries are independent objects, which even though mutable, will not overwrite each other, unless you explicitly do assignations.

        Comment


          #5
          Originally posted by koganam View Post
          Yes, you can call previous values of any Plot. The MACD is based on exponential moving averages, and the recursive calculation in the extant indicator shows this use of the previous value to calculate the current value, as per the most efficient way to calculate EMAs.

          What is hard to do, however, is to change inputs midstream. You seem to be saying that you should be able to directly take the MACD of the Closes, and calculate from it the MACD of the Highs or Lows. While, it may not exactly be impossible, I doubt that it would be efficient, or conveniently debuggable. Much simpler is to use 3 different dataSeries to hold the 3 different calculations.

          DataSeries are independent objects, which even though mutable, will not overwrite each other, unless you explicitly do assignations.
          I think you are making this harder than it needs to be. I'm not looking to compare the macd of close with the macd of highs...
          I'm just trying to take MACD[1] (of standard closes) and calculate MACD[0] based on a different value than input[0], say low[0]+8 ticks. This would only be an indicator/strategy for the current bar, and would need to be calculateonbarclose=false as I am looking at intrabar values.
          Last edited by wallabee13; 01-29-2012, 03:35 PM.

          Comment


            #6
            Although I'm a newb here I think I know what you are trying to do -- I've wondered this myself -- what would the current MACD value be if the current close were something else to try to figure out if how far the currrent price would have to move in order to change, for instance.

            It sounds like what you're looking for is some sort of hook or callback into the computation so that you could override the value to be used for the final bar, and I think I read them saying that there isn't one. I could totally have that wrong!

            However, not to worry, rolling your own MACD is easy. Here is a snippet of code I wrote outside of NJ. just take a 12 ema, a 26 ema, compute the difference and take the 9 ema of that line.

            decimal[] FastEMA = EMA.Ema(12); // fast line is ema12
            decimal[] SlowEMA = EMA.Ema(26); // slow line is ema26

            // Compute the MACD line as the difference between the fast and the slow
            decimal[] tmpMACDLine = new decimal[FastEMA.Length];

            for (int i = 0; i < FastEMA.Length; i++) MACDLine[i] = FastEMA[i] - SlowEMA[i];

            // Compute the signal line as an EMA of the MACDline
            decimal[] SignalLine = EMA.Ema(9, MACDLine);

            Comment


              #7
              Originally posted by wallabee13 View Post
              I think you are making this harder than it needs to be. I'm not looking to compare the macd of close with the macd of highs...
              I'm just trying to take MACD[1] (of standard closes) and calculate MACD[0] based on a different value than input[0], say low[0]+8 ticks. This would only be an indicator/strategy for the current bar, and would need to be calculateonbarclose=false as I am looking at intrabar values.
              After a bad experience with another user on this forum, I had vowed never to provide a complete indicator coded for anybody for free, but this conundrum you pose was such a challenge, and you were polite enough about it, that I submit this for you.

              I post it showing on an 8-range chart, overlaid with the shipping MACD. You will notice that whenever a candle closes on the high/low, the relevant plot coincides with the MACD, as would be expected.

              In this, you have to manually input the range that you want. It is easily modified to instead automatically use whatever range the chart is using, thus limiting its use to Range charts (and possibly Renko) charts only.
              Attached Files

              Comment


                #8
                Thank You Koganam!!! Exactly what I was looking for. Now I just have to create another and figure out how to modify to calculate the histogram . Any clue how hard that might be? I've had 1 attempt at it so far unsuccessfully.
                Last edited by wallabee13; 01-29-2012, 11:07 PM.

                Comment


                  #9
                  Originally posted by wallabee13 View Post
                  Thank You Koganam!!! Exactly what I was looking for. Now I just have to create another and figure out how to modify to calculate the histogram . Any clue how hard that might be? I've had 1 attempt at it so far unsuccessfully.
                  Take the EMA(9) of either Plot, and the difference between that Plot and the EMA(9) of that Plot will be the histogram.

                  You will need to create another Plot to plot the histogram. If you want to show the MACD signal line (i.e., the EMA(9)), that would be yet another Plot.

                  Comment


                    #10
                    Yeah, thanks, I'm not that dumb. I know the MACD calculations. The problem I was having, which we are still miscommunicating on is I want the histogram based off the actual macd, not the ema of the predicted high (or low) macd, which is what taking the ema of those would create. Had to create conditional sets for the real macd.

                    And thank you for changing the syntax for the ema calculations. That is how I finally saw how to do it.

                    With a couple changes and a lot of debugging, I finally have it. For anybody that is looking for it, here is the code for calculating the macd "future" values given a specific value, i.e. range bars, combining the former code from koganam for the MACD line and this for the histogram. p.s. I use macdupdownv2 to look at, as you can see from the screenshot, it works changing that to regular macd.

                    I don't know if any of this can be combined, frankly, I don't care. Cuz i got it, i got it!! I plotted the true macd line as part of debugging to start with, so I'm pretty sure it doesn't have to be there, but I don't feel like taking the chance on changing it, I'm happy with it.
                    Attached Files
                    Last edited by wallabee13; 01-30-2012, 05:17 PM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PhillT, Today, 02:16 PM
                    1 response
                    1 view
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by Kaledus, Today, 01:29 PM
                    3 responses
                    9 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by frankthearm, Yesterday, 09:08 AM
                    14 responses
                    47 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by gentlebenthebear, Today, 01:30 AM
                    2 responses
                    13 views
                    0 likes
                    Last Post gentlebenthebear  
                    Started by PaulMohn, Today, 12:36 PM
                    2 responses
                    17 views
                    0 likes
                    Last Post PaulMohn  
                    Working...
                    X