Pompideu (Ci below vol bracket)

My idea for the day is utilizing the spike below the volatility bracket of the 7-sample consolidation indicator for a well determined entry point to start defying a move.

It is so simple, that it is almost elegant. You would need to have it as the first indicator below to have the plots show right.

#property copyright "Copyright © 2009, David Moser, Copyright © 2019, Macdulio"
#property link      "https://forexfore.blog"
#property description "Choppiness indicator with daily reversal signals"

// This Indicator is NEVER to be SOLD individually 
// This Indicator is NEVER to be INCLUDED as part of a collection that is SOLD

//---- common control defaults
#property indicator_separate_window
#property indicator_minimum 24
#property indicator_maximum 64
#property indicator_buffers 3
#property indicator_color1 Cyan
#property indicator_color2 Yellow
#property indicator_color3 Crimson
#property indicator_width1 3
#property indicator_style1 0
#property indicator_color2 Navy
#property indicator_width2 1
#property indicator_style2 0
#property indicator_color3 Navy
#property indicator_width3 1
#property indicator_style3 0
#property indicator_level1  34
#property indicator_level2  53
#property indicator_levelstyle 2
#property indicator_levelcolor Maroon
 
//---- indicator parameters
// Main Parameters
extern int ChoppinessPeriod=7;        // Number of bars to evaluation CI
extern int SmoothingPeriod=1;          // Number of bars to apply SMA
extern int StdDevPeriod=7;            // Number of bars to evaluate Standard Deviation of the CI
extern bool StdDevFollowPrice=false;   // True, StdDev bars follow price, False, StdDev bars centered on 50
extern bool EnableAlertOnHigh=false;   // Alert setting for entering time of choppiness
extern double AlertHighVal=62;       // Default value based on fib numbers
extern bool EnableAlertOnLow=false;    // Alert setting for entering time of trending
extern double AlertLowVal=34;        // Default value based on fib numbers
extern int MaxCalcBars=100;           // Limit calculations back this many bars
extern bool plot_reminders = false;
//---- indicator buffers
double ExtMapBuffer[];
double CI[];
double StdDevHiBuffer[];
double StdDevLoBuffer[];
double IntMapBuffer[];
double IntStdDevBuffer[];
extern bool plot_CI_divergences = true;
//---- variables
string symbol = Symbol();
string TimeFrame;
datetime LastAlert=0;
datetime LowFractalTime_1, LowFractalTime_2;
datetime UpFractalTime_1, UpFractalTime_2;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
 
   IndicatorBuffers(5);
   SetIndexStyle(0,DRAW_LINE,EMPTY,5);
   SetIndexBuffer(0,ExtMapBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,StdDevHiBuffer);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,StdDevLoBuffer);
   SetIndexBuffer(3,IntMapBuffer);
   SetIndexBuffer(4,IntStdDevBuffer);
   
   if (ChoppinessPeriod<2) ChoppinessPeriod = 2;   // Any lower and this indicator isn't relevant
   if (SmoothingPeriod<1) SmoothingPeriod = 1;     // Avoid configuration errors
   if (StdDevPeriod<2) StdDevPeriod = 2;           // Any lower and the Standard Deviation isn't relevant
   if (MaxCalcBars>10000) MaxCalcBars = 10000;     // Any higher and may adversely affect performance on multi-chart setups
   
   SetIndexDrawBegin(0,ChoppinessPeriod+SmoothingPeriod);
   SetIndexDrawBegin(1,ChoppinessPeriod+SmoothingPeriod+StdDevPeriod);
   SetIndexDrawBegin(2,ChoppinessPeriod+SmoothingPeriod+StdDevPeriod);
   
   string short_name="Choppiness Index ("+ChoppinessPeriod+","+SmoothingPeriod+","+StdDevPeriod+")";
   IndicatorShortName(short_name);

   switch (Period())
     {
     case     1: TimeFrame = "M1";  break;
     case     5: TimeFrame = "M5";  break;
     case    15: TimeFrame = "M15"; break;
     case    30: TimeFrame = "M30"; break;
     case    60: TimeFrame = "H1";  break;
     case   240: TimeFrame = "H4";  break;
     case  1440: TimeFrame = "D1";  break;
     case 10080: TimeFrame = "W1";  break;
     case 43200: TimeFrame = "MN";  break;
   }

//---- initial zero
   for(int i=0;i<=Bars;i++) ExtMapBuffer[i]=0;  // Smoothed & visible main indicator line
   for(i=0;i<=Bars;i++) StdDevHiBuffer[i]=0;    // Upper StdDev band, visible
   for(i=0;i<=Bars;i++) StdDevLoBuffer[i]=0;    // Lower StdDev band, visible
   for(i=0;i<=Bars;i++) IntMapBuffer[i]=0;      // Raw CI, not smoothed, not visible
   for(i=0;i<=Bars;i++) IntStdDevBuffer[i]=0;   // Raw StdDev of Smoothed & visible main indicator line (ExtMapBuffer)

   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
  ArrayResize(CI, Bars);
  ArrayInitialize(CI, EMPTY_VALUE); 
  int counted_bars=IndicatorCounted();
  int i, i2,j2, z,limit;
  double bufferTemp1, bufferTemp2;

  if (counted_bars<0) return(-1); 
  if (counted_bars>0) counted_bars--; 
  limit=Bars-counted_bars;
  if (limit>MaxCalcBars) limit=MaxCalcBars;
  
  for (i=limit-1; i>=0; i--) 
    {
    IntMapBuffer[i] = ChoppinessIndex(ChoppinessPeriod,i);
    bufferTemp1 = 0;
    for(int j=0; j<SmoothingPeriod; j++) { z=i+j; bufferTemp1 += IntMapBuffer[z]; }
    ExtMapBuffer[i] = bufferTemp1 / SmoothingPeriod;
    IntStdDevBuffer[i] = StdDev(i,StdDevPeriod);
    bufferTemp1 = 0;
    bufferTemp2 = 0;
    for(int n=0; n<StdDevPeriod; n++)
      {
      z=i+n;
      if (StdDevFollowPrice)
        {
        bufferTemp1 += ExtMapBuffer[z];
        bufferTemp2 += ExtMapBuffer[z];
        }
      else
        {
        bufferTemp1 += 50;
        bufferTemp2 += 50;
        }
      bufferTemp1 += IntStdDevBuffer[i]*2;
      bufferTemp2 -= IntStdDevBuffer[i]*2;
      }
    StdDevHiBuffer[i] = bufferTemp1 / StdDevPeriod;
    StdDevLoBuffer[i] = bufferTemp2 / StdDevPeriod;
    }

    if (EnableAlertOnHigh)
      if (LastAlert != Time[0])
        if ((ExtMapBuffer[1]>AlertHighVal) && (ExtMapBuffer[2]<AlertHighVal))
          {
          LastAlert = Time[0]; // No more alerts on the current bar
          Alert(Symbol()+","+TimeFrame+":Choppiness greater than "+DoubleToStr(AlertHighVal,1));
          }
    
    if (EnableAlertOnLow)
      if (LastAlert != Time[0])
        if ((ExtMapBuffer[1]<AlertLowVal) && (ExtMapBuffer[2]>AlertLowVal))
          {
          LastAlert = Time[0]; // No more alerts on the current bar
          Alert(Symbol()+","+TimeFrame+":Choppiness less than "+DoubleToStr(AlertLowVal,1));
          }

  for (i = 310 ; i >= 0; i--) 
      CI[i]=ChoppinessIndex(7,i);


deletetxt1("Take");

deletetxt1("Push");

 if ( Period()==30 && (
   (ChoppinessIndex240(7,1)>53 && ChoppinessIndex240(7,0)<53)
  || (ChoppinessIndex240(7,2)>53 && ChoppinessIndex240(7,1)<53)
  || (ChoppinessIndex240(7,3)>53 && ChoppinessIndex240(7,2)<53)
   || (ChoppinessIndex240(7,4)>53 && ChoppinessIndex240(7,3)<53)
   || (ChoppinessIndex240(7,5)>53 && ChoppinessIndex240(7,4)<53)
    || (ChoppinessIndex240(7,6)>53 && ChoppinessIndex240(7,5)<53)
     || (ChoppinessIndex240(7,7)>53 && ChoppinessIndex240(7,6)<53)
  )){
 ObjectCreate("Takeni",OBJ_TEXT, 1, Time[14], 64);
                 ObjectSetText("Takeni", "4H in Push - Do not close Hedge until ", 23, "Arial Black", clrWhite);

 ObjectCreate("Pushi",OBJ_TEXT, 1, Time[14], 54);
                 ObjectSetText("Pushi", "Red Tail New Low/High and CI4H<36", 23, "Arial Black", clrPurple);
}

if (plot_reminders){
   ObjectCreate("Taken",OBJ_TEXT, 1, Time[14], 64);
                 ObjectSetText("Taken", "Take a position", 33, "Arial Black", clrWhite);

 ObjectCreate("Push",OBJ_TEXT, 1, Time[14], 54);
                 ObjectSetText("Push", "Push Against OB/OS Line", 23, "Arial Black", clrMoccasin);}
                 

i=1;

deletetxt1("HLLN");

while (i<100 && !(ChoppinessIndexD(7,i)<38 && ChoppinessIndexD(7,i+1)>38 && iLow(symbol,1440,i+1)>iLow(symbol,1440,i+2) && iLow(symbol,1440,i+2)>iLow(symbol,1440,i+3) && iLow(symbol,1440,i+3)>iLow(symbol,1440,i+4)))
   i++;
   
if (ChoppinessIndexD(7,i)<38 && ChoppinessIndexD(7,i+1)>38 && iLow(symbol,1440,i+1)>iLow(symbol,1440,i+2) && iLow(symbol,1440,i+2)>iLow(symbol,1440,i+3) && iLow(symbol,1440,i+3)>iLow(symbol,1440,i+4) && i<100)   {
               
               
               ObjectCreate( "HLLN"+IntegerToString(i), OBJ_HLINE, 0, Time[0], iHigh(symbol,1440,iHighest(symbol,1440,MODE_HIGH,6,i-1)) );
               ObjectSet("HLLN"+IntegerToString(i), OBJPROP_COLOR, clrWhite );
               ObjectSet("HLLN"+IntegerToString(i), OBJPROP_STYLE, 4 );
               
               
               for (j=1; j<=7; j++) {
               
               ObjectCreate( "HLLNj"+IntegerToString(j), OBJ_HLINE, 0, Time[0],  iHigh(symbol,1440,iHighest(symbol,1440,MODE_HIGH,6,i-1))-160*j*Point );
               ObjectSet("HLLNj"+IntegerToString(j), OBJPROP_COLOR, clrWhite );
               ObjectSet("HLLNj"+IntegerToString(j), OBJPROP_STYLE, 4 );
               }
               
               
                 for (j=1; j<=6; j++) {
               
               ObjectCreate( "HLLNjj"+IntegerToString(j), OBJ_HLINE, 0, Time[0],  iHigh(symbol,1440,iHighest(symbol,1440,MODE_HIGH,6,i-1))+160*j*Point );
               ObjectSet("HLLNjj"+IntegerToString(j), OBJPROP_COLOR, clrPink );
               ObjectSet("HLLNjj"+IntegerToString(j), OBJPROP_STYLE, 4 );
               }
           
               
               }     

i=1;               

while (i<100 && !(ChoppinessIndexD(7,i)<38 && ChoppinessIndexD(7,i+1)>38 && iLow(symbol,1440,i+1)<iLow(symbol,1440,i+2) && iLow(symbol,1440,i+2)<iLow(symbol,1440,i+3) && iLow(symbol,1440,i+3)<iLow(symbol,1440,i+4)))
   i++;


if (ChoppinessIndexD(7,i)<38 && ChoppinessIndexD(7,i+1)>38 && iLow(symbol,1440,i+1)<iLow(symbol,1440,i+2) && iLow(symbol,1440,i+2)<iLow(symbol,1440,i+3) && iLow(symbol,1440,i+3)<iLow(symbol,1440,i+4) && i<100)   {
               
               
               ObjectCreate( "HLLNx"+IntegerToString(i), OBJ_HLINE, 0, Time[0], iLow(symbol,1440,iLowest(symbol,1440,MODE_LOW,6,i-1)) );
               ObjectSet("HLLNx"+IntegerToString(i), OBJPROP_COLOR, clrYellow );
               ObjectSet("HLLNx"+IntegerToString(i), OBJPROP_STYLE, 4 );
               
               
               for (j=1; j<=7; j++) {
               
               ObjectCreate( "HLLNjx"+IntegerToString(j), OBJ_HLINE, 0, Time[0],  iLow(symbol,1440,iLowest(symbol,1440,MODE_LOW,6,i-1))+160*j*Point );
               ObjectSet("HLLNjx"+IntegerToString(j), OBJPROP_COLOR, clrYellow );
               ObjectSet("HLLNjx"+IntegerToString(j), OBJPROP_STYLE, 4 );
               }
               
               
                  for (j=1; j<=6; j++) {
               
               ObjectCreate( "HLLNjxx"+IntegerToString(j), OBJ_HLINE, 0, Time[0],  iLow(symbol,1440,iLowest(symbol,1440,MODE_LOW,6,i-1))-160*j*Point );
               ObjectSet("HLLNjxx"+IntegerToString(j), OBJPROP_COLOR, clrOrange );
               ObjectSet("HLLNjxx"+IntegerToString(j), OBJPROP_STYLE, 4 );
               }
               
           
               
               }     
                           
                 

deletetxt1("bNNN");

if (plot_CI_divergences){ 

i2=1;
   while (i2<300 ){
    i=i2+2; 
      if (Low[i2]<Low[i2+2] && Low[i2+2]<Low[i2+3] && CI[i2]<CI[i2+1] && CI[i2-1]>CI[i2] && CI[i2]<45) 
         while (i<i2+30){
               if (CI[i2]>CI[i] && CI[i]<CI[i-1] && CI[i]<CI[i+1] && CI[i]<33 && Low[i]<Low[i+1] && Low[i+1]<Low[i+2] && Low[i2]<Low[i2+2] && Low[i2+2]<Low[i2+3] && CI[i2]<CI[i2+1] && CI[i2-1]>CI[i2] && CI[i2]<45 ) break;
      i++;}
    if (CI[i2]>CI[i] && CI[i]<CI[i-1] && CI[i]<CI[i+1] && CI[i]<33 && Low[i]<Low[i+1] && Low[i+1]<Low[i+2] && Low[i2]<Low[i2+1] && Low[i2+2]<Low[i2+3] && CI[i2]<CI[i2+1] && CI[i2-1]>CI[i2] && CI[i2]<45 ) break;
     i2++;}  


if (i2<300 &&  High[i]>High[i+2] && High[i+2]>High[i+3] ) {UpFractalTime_2=iTime(NULL, 0,i2);    UpFractalTime_1=iTime(NULL, 0,i);    }


 if (i<300 && i<i2+30)   {ObjectDelete(0,"bNNN3_2");
     ObjectCreate(0,"bNNNm3_2",OBJ_TREND,1,UpFractalTime_1,CI[i],UpFractalTime_2,CI[i2]);
    ObjectSetInteger(0,"bNNNm3_2",OBJPROP_RAY_RIGHT,false);
         ObjectSet("bNNNm3_2",OBJPROP_COLOR,indicator_color3);
         ObjectSet("bNNNm3_2",OBJPROP_WIDTH,8); 
         ObjectSet("bNNNm3_2",OBJPROP_BACK,1); }



j2=1;
   while (j2<300 ){
    j=j2+2; 
      if (Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45) 
         while (j<j2+30){
               if (CI[j2]>CI[j] && CI[j]<CI[j-1] && CI[j]<CI[j+1] && CI[j]<33 && Low[j]<Low[j+1] && Low[j+1]<Low[j+2] && Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45 ) break;
      j++;}
    if (CI[j2]>CI[j] && CI[j]<CI[j-1] && CI[j]<CI[j+1] && CI[j]<33 && Low[j]<Low[j+1] && Low[j+1]<Low[j+2] && Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45 ) break;
     j2++;}  


if (j2<300 &&  Low[j]<Low[j+2] && Low[j+2]<Low[j+3] ) {LowFractalTime_2=iTime(NULL, 0,j2);    LowFractalTime_1=iTime(NULL, 0,j);    }


 if (j<300 && j<j2+30)   {ObjectDelete(0,"bNNN3_2");
     ObjectCreate(0,"bNNN3_2",OBJ_TREND,1,LowFractalTime_1,CI[j],LowFractalTime_2,CI[j2]);
    ObjectSetInteger(0,"bNNN3_2",OBJPROP_RAY_RIGHT,false);
         ObjectSet("bNNN3_2",OBJPROP_COLOR,indicator_color2);
         ObjectSet("bNNN3_2",OBJPROP_WIDTH,8); 
         ObjectSet("bNNN3_2",OBJPROP_BACK,1); }
         
         
int keepj2 = j2;         


j2=keepj2+30;
   while (j2<300 ){
    j=j2+2; 
      if (Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45) 
         while (j<j2+30){
               if (CI[j2]>CI[j] && CI[j]<CI[j-1] && CI[j]<CI[j+1] && CI[j]<33 && Low[j]<Low[j+1] && Low[j+1]<Low[j+2] && Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45 ) break;
      j++;}
    if (CI[j2]>CI[j] && CI[j]<CI[j-1] && CI[j]<CI[j+1] && CI[j]<33 && Low[j]<Low[j+1] && Low[j+1]<Low[j+2] && Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45 ) break;
     j2++;}  


if (j2<300 &&  Low[j]<Low[j+1] && Low[j+1]<Low[j+2] ) {LowFractalTime_2=iTime(NULL, 0,j2);    LowFractalTime_1=iTime(NULL, 0,j);    }


 if (j<300 && j<j2+30)   {ObjectDelete(0,"bNNN3_3");
     ObjectCreate(0,"bNNN3_3",OBJ_TREND,1,LowFractalTime_1,CI[j],LowFractalTime_2,CI[j2]);
    ObjectSetInteger(0,"bNNN3_3",OBJPROP_RAY_RIGHT,false);
         ObjectSet("bNNN3_3",OBJPROP_COLOR,indicator_color2);
         ObjectSet("bNNN3_3",OBJPROP_WIDTH,8); 
         ObjectSet("bNNN3_3",OBJPROP_BACK,1); }
       
       
keepj2 = j2;         


j2=keepj2+30;
   while (j2<300 ){
    j=j2+2; 
      if (Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45) 
         while (j<j2+32){
               if (CI[j2]>CI[j] && CI[j]<CI[j-1] && CI[j]<CI[j+1] && CI[j]<33 && Low[j]<Low[j+1] && Low[j+1]<Low[j+2] && Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45 ) break;
      j++;}
    if (CI[j2]>CI[j] && CI[j]<CI[j-1] && CI[j]<CI[j+1] && CI[j]<33 && Low[j]<Low[j+1] && Low[j+1]<Low[j+2] && Low[j2]<Low[j2+2] && Low[j2+2]<Low[j2+3] && CI[j2]<CI[j2+1] && CI[j2-1]>CI[j2] && CI[j2]<45 ) break;
     j2++;}  


if (j2<300 &&  Low[j]<Low[j+1] && Low[j+1]<Low[j+2] ) {LowFractalTime_2=iTime(NULL, 0,j2);    LowFractalTime_1=iTime(NULL, 0,j);    }


 if (j<300 && j<j2+32)   {ObjectDelete(0,"bNNN3_4");
     ObjectCreate(0,"bNNN3_4",OBJ_TREND,1,LowFractalTime_1,CI[j],LowFractalTime_2,CI[j2]);
    ObjectSetInteger(0,"bNNN3_4",OBJPROP_RAY_RIGHT,false);
         ObjectSet("bNNN3_4",OBJPROP_COLOR,indicator_color2);
         ObjectSet("bNNN3_4",OBJPROP_WIDTH,8); 
         ObjectSet("bNNN3_4",OBJPROP_BACK,1); }
         


}

deletetxt1("hOPITAL");

if (Period()==1440){
for(i=200; i>=1; i--){
   if (ExtMapBuffer[i]<StdDevLoBuffer[i] && ExtMapBuffer[i+1]>StdDevLoBuffer[i+1]){
      if (MathAbs(Close[i+1]-iLow(NULL,0,iLowest(NULL,0,MODE_LOW,3,i)))<MathAbs(Close[i+1]-iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,3,i))) )
         {ObjectCreate("hOPITAL"+IntegerToString(i), OBJ_TEXT, 1, Time[i+2], 60);  
                ObjectSetText("hOPITAL"+IntegerToString(i), "Buy Below:", 10, "Arial Black",  clrNavy);
                ObjectCreate("hOPITALl"+IntegerToString(i), OBJ_TEXT, 1, Time[i+2], 40);  
                ObjectSetText("hOPITALl"+IntegerToString(i), NormalizeDouble(iLow(NULL,0,iLowest(NULL,0,MODE_LOW,2,i)),4), 16, "Arial Black",  clrNavy);
         }
          if (MathAbs(Close[i+1]-iLow(NULL,0,iLowest(NULL,0,MODE_LOW,3,i)))>MathAbs(Close[i+1]-iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,3,i))) )
         {ObjectCreate("hOPITAL"+IntegerToString(i), OBJ_TEXT, 1, Time[i+2], 60);  
                ObjectSetText("hOPITAL"+IntegerToString(i), "Sell Above:", 10, "Arial Black",  clrNavy);
                ObjectCreate("hOPITALl"+IntegerToString(i), OBJ_TEXT, 1, Time[i+2], 40);  
                ObjectSetText("hOPITALl"+IntegerToString(i), NormalizeDouble(iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,2,i)),4), 16, "Arial Black",  clrNavy);
         }
   }}

}


  return(0);
  }
  
  
double ChoppinessIndex(int period, int bar)
  {
    double Low0 = 0, High0 = 0, Close1 = 0;
    double TrueRangeLow = 0, TrueRangeHigh = 0, TrueRangeSum = 0, Input = 0;
    double PeriodTrueRangeLow = 999999999, PeriodTrueRangeHigh = 0, PeriodTrueRange = 0;

    for(int k=bar; k<bar+period; k++)
    {
      Low0   = iLow(NULL,0,k);
      High0  = iHigh(NULL,0,k);
      Close1 = iClose(NULL,0,k+1);

      if (Low0<Close1)  TrueRangeLow  = Low0;  else TrueRangeLow  = Close1;
      if (High0>Close1) TrueRangeHigh = High0; else TrueRangeHigh = Close1;
      
      if (TrueRangeLow <PeriodTrueRangeLow)  PeriodTrueRangeLow  = TrueRangeLow;  // find true low of period
      if (TrueRangeHigh>PeriodTrueRangeHigh) PeriodTrueRangeHigh = TrueRangeHigh; // find true high of period

      TrueRangeSum += TrueRangeHigh;
      TrueRangeSum -= TrueRangeLow;
    }

    PeriodTrueRange = PeriodTrueRangeHigh - PeriodTrueRangeLow;
    if (PeriodTrueRange==0) PeriodTrueRange = MathPow(10, -12); // avoid possibility of division by zero
    Input = TrueRangeSum / PeriodTrueRange;
    return ((logN(Input, 10, MathPow(10, -12)) / logN(period, 10, MathPow(10, -12))) * 100);
  }


double ChoppinessIndexD(int period, int bar)
  {
    double Low0 = 0, High0 = 0, Close1 = 0;
    double TrueRangeLow = 0, TrueRangeHigh = 0, TrueRangeSum = 0, Input = 0;
    double PeriodTrueRangeLow = 999999999, PeriodTrueRangeHigh = 0, PeriodTrueRange = 0;

    for(int k=bar; k<bar+period; k++)
    {
      Low0   = iLow(NULL,1440,k);
      High0  = iHigh(NULL,1440,k);
      Close1 = iClose(NULL,1440,k+1);

      if (Low0<Close1)  TrueRangeLow  = Low0;  else TrueRangeLow  = Close1;
      if (High0>Close1) TrueRangeHigh = High0; else TrueRangeHigh = Close1;
      
      if (TrueRangeLow <PeriodTrueRangeLow)  PeriodTrueRangeLow  = TrueRangeLow;  // find true low of period
      if (TrueRangeHigh>PeriodTrueRangeHigh) PeriodTrueRangeHigh = TrueRangeHigh; // find true high of period

      TrueRangeSum += TrueRangeHigh;
      TrueRangeSum -= TrueRangeLow;
    }

    PeriodTrueRange = PeriodTrueRangeHigh - PeriodTrueRangeLow;
    if (PeriodTrueRange==0) PeriodTrueRange = MathPow(10, -12); // avoid possibility of division by zero
    Input = TrueRangeSum / PeriodTrueRange;
    return ((logN(Input, 10, MathPow(10, -12)) / logN(period, 10, MathPow(10, -12))) * 100);
  }


double ChoppinessIndex240(int period, int bar)
  {
    double Low0 = 0, High0 = 0, Close1 = 0;
    double TrueRangeLow = 0, TrueRangeHigh = 0, TrueRangeSum = 0, Input = 0;
    double PeriodTrueRangeLow = 999999999, PeriodTrueRangeHigh = 0, PeriodTrueRange = 0;

    for(int k=bar; k<bar+period; k++)
    {
      Low0   = iLow(NULL,240,k);
      High0  = iHigh(NULL,240,k);
      Close1 = iClose(NULL,240,k+1);

      if (Low0<Close1)  TrueRangeLow  = Low0;  else TrueRangeLow  = Close1;
      if (High0>Close1) TrueRangeHigh = High0; else TrueRangeHigh = Close1;
      
      if (TrueRangeLow <PeriodTrueRangeLow)  PeriodTrueRangeLow  = TrueRangeLow;  // find true low of period
      if (TrueRangeHigh>PeriodTrueRangeHigh) PeriodTrueRangeHigh = TrueRangeHigh; // find true high of period

      TrueRangeSum += TrueRangeHigh;
      TrueRangeSum -= TrueRangeLow;
    }

    PeriodTrueRange = PeriodTrueRangeHigh - PeriodTrueRangeLow;
    if (PeriodTrueRange==0) PeriodTrueRange = MathPow(10, -12); // avoid possibility of division by zero
    Input = TrueRangeSum / PeriodTrueRange;
    return ((logN(Input, 10, MathPow(10, -12)) / logN(period, 10, MathPow(10, -12))) * 100);
  }  

double logN(double x, double base, double epsilon)
  {
    double integer = 0.0;
    if ((x < 1) || (base < 1)) return(0);

    while (x < 1)
    {
      integer -= 1;
      x *= base;
    }
  
    while (x >= base)
    {
      integer += 1;
      x /= base;
    }
  
    double partial = 0.5;
    x *= x;
    double decimal = 0.0;

    while (partial > epsilon)
    {
      if (x >= base)
      {
        decimal += partial;
        x = x / base;
      }
      partial *= 0.5;
      x *= x;
    }
    
    return (integer + decimal);
  } 


double StdDev(int shift, int samples)
  {
  double x0=0, x1=0, x2=0;
  for (int m=0; m<samples; m++)
    {
    x0 = ExtMapBuffer[m+shift];
    x1 += x0;
    x2 += MathPow(x0,2);
    }
  return(MathSqrt((x2-(x1*x1/samples))/(samples-1))); // minimum samples is 2, enforced in the init section
  }
  
    void deletetxt1(string text){
   for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--){
      string   on = ObjectName(iObj);
      if(StringFind(on, text) == 0)  ObjectDelete(on);
}  }