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

CCI Prediction

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

    CCI Prediction

    Hello all,
    I would like to ask you about some calculation. I work with Range bars chart.
    I try to do indicator which can do "prediction" of new CCI position based on possible close value of range bar. Let say I have range bar value 6. It means every range bar has length 6 ticks on my YM chart. It means High-Low = 6 ticks.
    Example: New bar opens on price 15006. Possible close prices in this moment are on 15012 Close (Upper) and 15000 Close (Lower). I attached pic where you can see situation, where possible close positions are on 16091 (upper close) and 16081 (for lower close) - I have one tick shift for both..it means that real values are 16091 and 16080..but it doesnt matter in this case. I would like to calculate possible position/value of CCI(14) when bar closes on both position...see atteched pic below (lower blue rectangle).
    I looked at your CCI indicator - how values are calculated. I tried to do on my own..based on your calculation model. I think the only one thing I have to do is to calculate last Typical price for current bar with boht close prices - lower and upper and then calculate CCI. But it doesnt work well. Sometimes I can see lower and upper CCI values but current CCI value is NOT between them !! Current CCI value must lie between my lower and upper CCI values and must end exactly at one of them.

    I use code below:

    in Initialize:
    internalTypicalUp = new DataSeries(this);
    internalTypicalDn = new DataSeries(this);

    OnBarClose:

    if (Historical) return;

    double hiClose = Low[0] + (Bars.Period.Value * Bars.Instrument.MasterInstrument.TickSize); // upper Close of Range bar

    // ---- UPPER ----
    for(int i=1; i<=CCIPeriod; i++) {
    internalTypicalUp.Set(i,Typical[i]);
    }


    _LastTypicalPrice = ( (hiClose + Low[0] + hiClose) / 3.0 ); // Close and High of Range bar will be the same
    internalTypicalUp.Set(0, _LastTypicalPrice);



    mean = 0;
    for (int idx = Math.Min(CurrentBar, CCIPeriod - 1); idx >= 0; idx--)
    mean += Math.Abs(internalTypicalUp[idx] - SMA(internalTypicalUp, CCIPeriod)[0]);
    _value = (internalTypicalUp[0] - SMA(internalTypicalUp, CCIPeriod)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(CCIPeriod, CurrentBar + 1))));
    // it is your CCI code, just interaTypicalUp DataSeries is used insted of Typical

    DrawLine("CCILinesUP",false,1,CCI(14)[1],0,_value,Color.Green,DashStyle.Dot,2);
    // draw line from previous CCI value to new predicated value

    The same calculation for lower value.

    Would you be so kind and help me somehow with right calculation ??
    Thank you very much.
    Alex
    Attached Files

    #2
    I do believe you're on the right track in terms of how you'd "predict" the CCI, but I'm not quite sure I follow completely how you're predicting the close value for a range bar. The close can happen anywhere within that 6 tick range and there are several scenarios that would play out for the next bar.

    The CCI will complicate things as you need to know the High/Low/Close value so you'd have to be able to 'predict' these values as well, which I'm having a hard time figuring out how you'd do this easily with the range bars. A Renko bar for example would be easy to do as the open/low and close/high would always be the same...

    Was the screen you provided from the code you posted above? Or was that manually drawn? Do you have a working example of how you're predicting at what value the range bar will close?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Hello Mathew,
      thank you very much for you post

      Screenshot was drawn manually, but I have working example of course. No prob to send it to you.

      Range bars can NOT have close anywhere if I got their idea right. I think next range bar is drawn once distance between high and low exceeds set value..for example 6. So range bar can not have upper wick when close above open. Therefor there is just one scenario how it would look like...no upper wick, high = close, open is anywhere and lower wick is in maximum 6 tick distance from close and vica versa for bar where close is below open. DOJI range bar exists either just with lower wick or just upper wick. In time frame there is no possibility to do CCI prediction in my opinion.
      So in this idea I think Im able to do cci prediction on range bars. And because typical price doesnt depend on open price I have clear rules - I hope
      What do you think about it ??
      Thank you.
      Regards,
      Alex

      Comment


        #4
        I misunderstood you were trying to predict an entire bar ahead. Ok, so in your case, we already know the open value so your logic makes sense. Let me play with this idea now and I'll get back to you.
        MatthewNinjaTrader Product Management

        Comment


          #5
          cci predictor

          Aloha,
          Try using the cci forecaster DE v7 in NT7 indicators. Along with the cci 4 range bar indicator load up a chart with these indicators. This is a predictor for range bars cci close.
          Last edited by jungo; 11-28-2013, 12:33 AM.

          Comment


            #6
            Originally posted by Alexik30 View Post
            Hello all,
            I would like to ask you about some calculation. I work with Range bars chart.
            I try to do indicator which can do "prediction" of new CCI position based on possible close value of range bar. Let say I have range bar value 6. It means every range bar has length 6 ticks on my YM chart. It means High-Low = 6 ticks.
            Example: New bar opens on price 15006. Possible close prices in this moment are on 15012 Close (Upper) and 15000 Close (Lower). I attached pic where you can see situation, where possible close positions are on 16091 (upper close) and 16081 (for lower close) - I have one tick shift for both..it means that real values are 16091 and 16080..but it doesnt matter in this case. I would like to calculate possible position/value of CCI(14) when bar closes on both position...see atteched pic below (lower blue rectangle).
            I looked at your CCI indicator - how values are calculated. I tried to do on my own..based on your calculation model. I think the only one thing I have to do is to calculate last Typical price for current bar with boht close prices - lower and upper and then calculate CCI. But it doesnt work well. Sometimes I can see lower and upper CCI values but current CCI value is NOT between them !! Current CCI value must lie between my lower and upper CCI values and must end exactly at one of them.

            I use code below:

            in Initialize:
            internalTypicalUp = new DataSeries(this);
            internalTypicalDn = new DataSeries(this);

            OnBarClose:

            if (Historical) return;

            double hiClose = Low[0] + (Bars.Period.Value * Bars.Instrument.MasterInstrument.TickSize); // upper Close of Range bar

            // ---- UPPER ----
            for(int i=1; i<=CCIPeriod; i++) {
            internalTypicalUp.Set(i,Typical[i]);
            }


            _LastTypicalPrice = ( (hiClose + Low[0] + hiClose) / 3.0 ); // Close and High of Range bar will be the same
            internalTypicalUp.Set(0, _LastTypicalPrice);



            mean = 0;
            for (int idx = Math.Min(CurrentBar, CCIPeriod - 1); idx >= 0; idx--)
            mean += Math.Abs(internalTypicalUp[idx] - SMA(internalTypicalUp, CCIPeriod)[0]);
            _value = (internalTypicalUp[0] - SMA(internalTypicalUp, CCIPeriod)[0]) / (mean == 0 ? 1 : (0.015 * (mean / Math.Min(CCIPeriod, CurrentBar + 1))));
            // it is your CCI code, just interaTypicalUp DataSeries is used insted of Typical

            DrawLine("CCILinesUP",false,1,CCI(14)[1],0,_value,Color.Green,DashStyle.Dot,2);
            // draw line from previous CCI value to new predicated value

            The same calculation for lower value.

            Would you be so kind and help me somehow with right calculation ??
            Thank you very much.
            Alex
            At first glance, your logic looks correct.

            The only issue that I see so far would be the introduction and propagation of rounding errors. Try rounding _LastTypicalPrice to TickSize.
            Code:
            _LastTypicalPrice = Instrument.MasterInstrument.Round2TickSize( _LastTypicalPrice)

            Comment


              #7
              koganam: Thank you for your note. I know I can round this value to TickSize precision, but if you see Typical values, they have lots of decimals. So I dont suppose that cause my problem.
              But I was thinking if problem wouldnt be in that fact, that new range bar starts drawing after prevoius bar exceeds set range value (6 in my case). It means new bar starts when distance from prevoius low/high is 7 ticks in facts. But my algorithm supposes that it happens on distance 6 !
              I dont know if my explanation is clear due to my poor english Sorry for that.

              Comment


                #8
                Originally posted by Alexik30 View Post
                koganam: Thank you for your note. I know I can round this value to TickSize precision, but if you see Typical values, they have lots of decimals. So I dont suppose that cause my problem.
                But I was thinking if problem wouldnt be in that fact, that new range bar starts drawing after prevoius bar exceeds set range value (6 in my case). It means new bar starts when distance from prevoius low/high is 7 ticks in facts. But my algorithm supposes that it happens on distance 6 !
                I dont know if my explanation is clear due to my poor english Sorry for that.
                Actually what you have written makes no assumptions about where the bar opens, only what looks correct about the low and potential close of the bar. Also the picture that you have shown shows correct behavior. Can you post an actual picture where your results are not as expected?

                Comment


                  #9
                  It looks like when volatility is higher there is some calc problem. In premarket everything worked well, but in "main session" there are differences. I have another code for calculation - much more complicated (not mine) and this code show correct values.
                  Damn, where could I have the problem ??
                  See pics. For ex. Pic E - current CCI value is out of my calculated range, but cci value fits on lower cci prediction (not mine). But two bars later (pic F1 and F2) both CCIs fit accurately.
                  Do you have any idea ??
                  Thank you for you help.
                  Alex
                  Attached Files

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by f.saeidi, Yesterday, 12:14 PM
                  9 responses
                  23 views
                  0 likes
                  Last Post f.saeidi  
                  Started by Tim-c, Today, 03:54 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post Tim-c
                  by Tim-c
                   
                  Started by FrancisMorro, Today, 03:24 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post FrancisMorro  
                  Started by Segwin, 05-07-2018, 02:15 PM
                  10 responses
                  1,772 views
                  0 likes
                  Last Post Leafcutter  
                  Started by Rapine Heihei, 04-23-2024, 07:51 PM
                  2 responses
                  31 views
                  0 likes
                  Last Post Max238
                  by Max238
                   
                  Working...
                  X