Announcement

Collapse
No announcement yet.

CCI in Chart with multiplr trading days

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

  • CCI in Chart with multiplr trading days

    Greetings:

    I'm running the standard CCI study with a 20 bar length in a 1 minute chart that includes multiple days. Unfortunately, the study "looks back" to the bars from the previous day at the beginning of each day, skewing the results. Does someone have any code I could insert into an efs study to force the CCI study to only use intraday data?

    Thanks,
    Warren

  • #2
    Code question

    I running the following EFS study:

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("CCI");
    setCursorLabelName("CCI", 0);
    setDefaultBarFgColor(Color.blue, 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(1,0);
    addBand(100, PS_SOLID, 1, Color.black,"Upper");
    addBand(-100, PS_SOLID, 1, Color.black,"Lower");
    }

    var xPrice = null;
    var xAvgPrice = null;

    function main(Length){

    if(Length==null) Length = 20;

    if(xPrice==null) xPrice = close();
    if(xAvgPrice==null) xAvgPrice = sma(Length,xPrice);

    if(xPrice.getValue(-Length)==null||xAvgPrice.getValue(-Length)==null) return;

    var Sum = 0;

    for (i=0; i<Length; i++){
    Sum += Math.abs(xPrice.getValue(-i)-xAvgPrice.getValue(0));
    }

    var MeanDevPrice = Sum/Length;
    var CCI = (xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*0.015);

    return CCI;
    }

    Does anyone have any code I can insert that would limit the data used to the current day only in a multiday chart?

    Thanks

    Comment


    • #3
      Re: Code question

      Warren
      The simplest solution is to use that study and just return null for the first Length x 2 bars [ie the number of bars required to prime the study] of each day. To do this create a global variable which you use to store your counter eg



      You then reset the counter on the first bar of each day and increase it by 1 on each subsequent bar.
      Then just interrupt the execution of the efs up until you reached the desired counter value [all this logic can be inserted after you initialize the studies]



      The result will be the same as restarting the study each day with the added benefit that you do not have to rewrite the entire study [which would otherwise be required]
      Alex


      Originally posted by Vailskier
      I running the following EFS study:

      function preMain() {
      setPriceStudy(false);
      setStudyTitle("CCI");
      setCursorLabelName("CCI", 0);
      setDefaultBarFgColor(Color.blue, 0);
      setPlotType(PLOTTYPE_LINE,0);
      setDefaultBarThickness(1,0);
      addBand(100, PS_SOLID, 1, Color.black,"Upper");
      addBand(-100, PS_SOLID, 1, Color.black,"Lower");
      }

      var xPrice = null;
      var xAvgPrice = null;

      function main(Length){

      if(Length==null) Length = 20;

      if(xPrice==null) xPrice = close();
      if(xAvgPrice==null) xAvgPrice = sma(Length,xPrice);

      if(xPrice.getValue(-Length)==null||xAvgPrice.getValue(-Length)==null) return;

      var Sum = 0;

      for (i=0; i<Length; i++){
      Sum += Math.abs(xPrice.getValue(-i)-xAvgPrice.getValue(0));
      }

      var MeanDevPrice = Sum/Length;
      var CCI = (xPrice.getValue(0)-xAvgPrice.getValue(0))/(MeanDevPrice*0.015);

      return CCI;
      }

      Does anyone have any code I can insert that would limit the data used to the current day only in a multiday chart?

      Thanks

      Comment

      Working...
      X