Calling A Market

On the surface you can determine the market type by finding 3 closes above the Weekly Closes above / below the E-59.

This may just work well for a Hedge Fund, but as you can see it is far from the bulk of the move when you connect the 3rd Weekly Close below with the 3rd Weekly Close above.

You can improve on the numbers by scaling in on the 4th week back towards the E-59, but the money taken would be 1/3 to 1/4 of the in the money peak. Of course a good window envelope stretch – like the 3.5x interrupted line would make for a great exit & that would come close to a clean up, the only “1 better” (eleven-a-reef – just learnt this) is making the span from the upper interrupted to the lower one in less than 2 weeks.

What I want you to realize here is that a market gets lost in stages.

Officially, this Bear Phase started on the 15th of August, 2021. That’s about the vertical line.

Before that, there was a move out of the long term overbought – close to the 60% line, than a move back up to the overbought (beyond the blue) and there was a failure of staying up there setting up ever lower highs. This was Stage 1 of losing the bull market.

Now tell me please, what is missing here for losing the bear market for goood? You know, a stage 1 step 2 kind of a thing.

#property copyright "Copyright © 2020, Macdulio"
#property link      "https://forexfore.blog" 
#property description "Comfort Levels Lucid"
#property description "1590 sample range"
#property description "broken down to 10% lines "
#property description "and two gray zones in addition"
#property description "the upper and lower reversalones"
#property description "grasp the concept of embedding"
#property description "and know the power of the oversold/"
#property description "overbought necklines"



//----

#property indicator_chart_window
#property indicator_buffers 19
#property indicator_color1  DarkGray
#property indicator_color2  DarkGray
#property indicator_color3  DarkGray
#property indicator_color4  DarkGray
#property indicator_color5  LightCoral
#property indicator_color6  SteelBlue
#property indicator_color7  DarkSlateGray
#property indicator_color8  DarkSlateGray
#property indicator_color9  OrangeRed
#property indicator_color10  DarkSlateGray
#property indicator_color11  DarkSlateGray
#property indicator_color12  SteelBlue
#property indicator_color13  LightCoral
#property indicator_color14  Gray
#property indicator_color15  Gray
#property indicator_color16  Gray
#property indicator_color17  Gray
#property indicator_color18  Pink
#property indicator_color19  Pink


double weight;
double ATRAVG;  
double ExtMapBuffer[]; 
extern bool put_label_on = true;
extern bool plot_reversal_zones = false;
extern int plotlength = 70;
  string symbol = Symbol();  
  double highs4[], lows4[];
int N;
int i;
//----


double Line1[];
double Line2[];
double Line3[];
double Line4[];
double Line5[];
double Line6[];
double Line7[];
double Line8[];
double Line9[];

double Line05[];
double Line15[];

double Line85[];
double Line95[];

double Line0[];
double Line100[];

double stoch[];
double HighBuffer[];
double LowBuffer[];
double HighBuffer2[];
double LowBuffer2[],LowBuffer3[],LowBuffer4[];
double HighBuffer3[];
double HighBuffer4[];
//+------------------------------------------------------------------+



void init()

  {      


      SetIndexBuffer(0,HighBuffer);
   SetIndexBuffer(1,LowBuffer);   
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexBuffer(2,HighBuffer2);
   SetIndexBuffer(3,LowBuffer2);   
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,3);   

   SetIndexStyle(4, DRAW_LINE, STYLE_DOT, 12);

   SetIndexStyle(5, DRAW_LINE, STYLE_DOT, 12);

   SetIndexStyle(6, DRAW_LINE, STYLE_DOT, 12);

   SetIndexStyle(7, DRAW_LINE, STYLE_DOT, 12);

   SetIndexStyle(8, DRAW_LINE, STYLE_DOT, 12);
   
   SetIndexStyle(9, DRAW_LINE, STYLE_DOT, 12);
   
   SetIndexStyle(10, DRAW_LINE, STYLE_DOT, 12); 
  
   SetIndexStyle(11, DRAW_LINE, STYLE_DOT, 12);

   SetIndexStyle(12, DRAW_LINE, STYLE_DOT, 12);
   
    SetIndexStyle(13, DRAW_LINE, STYLE_DOT, 12); 
    
     SetIndexStyle(14, DRAW_LINE, STYLE_DOT, 12);
   
    SetIndexStyle(15, DRAW_LINE, STYLE_DOT, 12); 
    
     SetIndexStyle(16, DRAW_LINE, STYLE_DOT, 12);
   
    SetIndexStyle(17, DRAW_LINE, STYLE_DOT, 12); 
    
        SetIndexStyle(18, DRAW_LINE, STYLE_DOT, 12); 
    
    
//----  

   SetIndexDrawBegin(4, N);

   SetIndexDrawBegin(5, N);

   SetIndexDrawBegin(6, N);

   SetIndexDrawBegin(7, N);

   SetIndexDrawBegin(8, N);
   
   SetIndexDrawBegin(9, N);
     
   SetIndexDrawBegin(10, N);

   SetIndexDrawBegin(11, N);
   
   SetIndexDrawBegin(12, N);

   SetIndexDrawBegin(13, N);
   
      SetIndexDrawBegin(14, N);

   SetIndexDrawBegin(15, N);
   
      SetIndexDrawBegin(16, N);

   SetIndexDrawBegin(17, N);
   
//----

   SetIndexBuffer(4, Line1);

   SetIndexBuffer(5, Line2);

   SetIndexBuffer(6, Line3);

   SetIndexBuffer(7, Line4);

   SetIndexBuffer(8, Line5);
   
   SetIndexBuffer(9, Line6);
   
   SetIndexBuffer(10, Line7);
      
   SetIndexBuffer(11, Line8);
   
   SetIndexBuffer(12, Line9);
   
   
      SetIndexBuffer(13, Line05);
   
   SetIndexBuffer(14, Line15);
   
   
         SetIndexBuffer(15, Line85);
   
   SetIndexBuffer(16, Line95);
   
   
   
         SetIndexBuffer(17, Line0);
   
   SetIndexBuffer(18, Line100);
   
   
      ArrayResize(HighBuffer3, Bars);   
 ArrayInitialize(HighBuffer3, EMPTY_VALUE);  
ArrayResize(HighBuffer4, Bars);   
 ArrayInitialize(HighBuffer4, EMPTY_VALUE);  
       ArrayResize(LowBuffer3, Bars);   
 ArrayInitialize(LowBuffer3, EMPTY_VALUE);  
ArrayResize(LowBuffer4, Bars);   
 ArrayInitialize(LowBuffer4, EMPTY_VALUE);  
       ArrayResize(highs4, Bars);
   ArrayInitialize(highs4, EMPTY_VALUE);      
    ArrayResize(lows4, Bars);
   ArrayInitialize(lows4, EMPTY_VALUE);       
    ArrayResize(stoch, 1100);
ArrayInitialize(stoch, 0);

 
    return(0);
}

int start()
{
int i,j,k,l;
   double dt14;
   double db14;
   double pacing;
   N = 1590;
   if (Period()==1440) N=1100;
   ATRAVG=(iATR(NULL,1440,14,1)+iATR(NULL,1440,14,2)+iATR(NULL,1440,14,3))/3;
   dt14 = iHigh(NULL,240,iHighest(NULL, 240, MODE_HIGH, N));
   db14 = iLow(NULL,240,iLowest(NULL, 240, MODE_LOW, N));
   pacing = (dt14-db14)*.1;      
     
     
   for(i = 335; i >=0 ; i--)stoch[i]=iStochastic(NULL,0,10,3,3,MODE_SMA,1 ,MODE_SIGNAL,i);        
   
  
  if (plot_reversal_zones){
   for(i = 35; i >=15 ; i--){
        
      LowBuffer[i]= dt14-(dt14-db14)*.15;
             HighBuffer[i]=dt14-(dt14-db14)*.05;  
        LowBuffer2[i]= db14+(dt14-db14)*.05;
            HighBuffer2[i]= db14+(dt14-db14)*.15;  
  
       }     }
     
     
     
    
   for(i = plotlength; i >=0 ; i--)
        {
         Line0[i]=iLow(NULL,0,iLowest(NULL, 0, MODE_LOW, N,i));
         Line100[i]=iHigh(NULL,0,iHighest(NULL, 0, MODE_HIGH, N,i));
         Line05[i] = Line0[i]+(Line100[i]-Line0[i])*.05;
         Line1[i] = Line0[i]+(Line100[i]-Line0[i])*.1;
         Line15[i] = Line0[i]+(Line100[i]-Line0[i])*.15;
         Line2[i] = Line0[i]+(Line100[i]-Line0[i])*.2;
         Line3[i] = Line0[i]+(Line100[i]-Line0[i])*.3;
         Line4[i] = Line0[i]+(Line100[i]-Line0[i])*.4;
         Line5[i] = Line0[i]+(Line100[i]-Line0[i])*.5;
         Line6[i] = Line0[i]+(Line100[i]-Line0[i])*.6;
         Line7[i] = Line0[i]+(Line100[i]-Line0[i])*.7;
         Line8[i] = Line0[i]+(Line100[i]-Line0[i])*.8;   
         Line85[i] = Line0[i]+(Line100[i]-Line0[i])*.85;   
         Line9[i] = Line0[i]+(Line100[i]-Line0[i])*.9;   
         Line95[i] = Line0[i]+(Line100[i]-Line0[i])*.95;
      }     
       
       
deletetxt1("txt 1");
       
                   if (Period()>15){
                   
                   ObjectCreate("txt 1"+Line1[1]+1, OBJ_TEXT, 0, Time[6], Line1[1]-pacing/2+.0005); 
               ObjectSetText("txt 1"+Line1[1]+1, "5%            ", 18, "Arial Black", White); 
                   
            
               ObjectCreate("txt 1"+Line1[1], OBJ_TEXT, 0, Time[6], Line1[1]+.0005); 
               ObjectSetText("txt 1"+Line1[1], "10%            ", 18, "Arial Black", Crimson); 
     
     
               ObjectCreate("txt 1"+Line2[1]+1, OBJ_TEXT, 0, Time[6], Line2[1]-pacing/2+.0005); 
               ObjectSetText("txt 1"+Line2[1]+1, "15%            ", 18, "Arial Black", White); 
     
                  ObjectCreate("txt 1"+Line2[1], OBJ_TEXT, 0, Time[6], Line2[1]+.0005); 
               ObjectSetText("txt 1"+Line2[1], "20%            ", 18, "Arial Black", Brown); 
        
        
                  ObjectCreate("txt 1"+Line3[1], OBJ_TEXT, 0, Time[6], Line3[1]+.0005); 
               ObjectSetText("txt 1"+Line3[1], "30%            ", 18, "Arial Black", Gray); 
           
                  ObjectCreate("txt 1"+Line4[1], OBJ_TEXT, 0, Time[6], Line4[1]+.0005); 
               ObjectSetText("txt 1"+Line4[1], "40%            ", 18, "Arial Black", Gray); 
            
            
                   ObjectCreate("txt 1"+Line5[1], OBJ_TEXT, 0, Time[6], Line5[1]+.0005); 
               ObjectSetText("txt 1"+Line5[1], "50%            ", 18, "Arial Black", Orange);
               
               
                      ObjectCreate("txt 1"+Line6[1], OBJ_TEXT, 0, Time[6], Line6[1]+.0005); 
               ObjectSetText("txt 1"+Line6[1], "60%            ", 18, "Arial Black", Gray); 
               
               
                    ObjectCreate("txt 1"+Line7[1], OBJ_TEXT, 0, Time[6], Line7[1]+.0005); 
               ObjectSetText("txt 1"+Line7[1], "70%            ", 18, "Arial Black", Gray);  
            
            
                  ObjectCreate("txt 1"+Line8[1], OBJ_TEXT, 0, Time[6], Line8[1]+.0005); 
               ObjectSetText("txt 1"+Line8[1], "80%            ", 18, "Arial Black", Brown); 
               
                ObjectCreate("txt 1"+Line8[1]+1, OBJ_TEXT, 0, Time[6], Line8[1]+pacing/2+.0005); 
               ObjectSetText("txt 1"+Line8[1]+1, "85%            ", 18, "Arial Black", White); 
               
            
               ObjectCreate("txt 1"+Line9[1], OBJ_TEXT, 0, Time[6], Line9[1]+.0005); 
               ObjectSetText("txt 1"+Line9[1], "90%            ", 18, "Arial Black", Crimson); 
               
               ObjectCreate("txt 1"+Line9[1]+1, OBJ_TEXT, 0, Time[6], Line9[1]+pacing/2+.0005); 
               ObjectSetText("txt 1"+Line9[1]+1, "95%            ", 18, "Arial Black", White); 
            
               
               }
            
            
             i=0;
   while (!(ChoppinessIndex(12*4,i+1)<53 && ChoppinessIndex(12*4,i)>53))    
   i++;
   
   
   weight=(iHigh(NULL,15,i)+iLow(NULL,15,i))/2;
 
 string text;   
 
 deletetxt1("xxt 5");
    
   if (Close[0]>weight) text=" R1:"+NormalizeDouble(iLow(NULL,1440,0)+ATRAVG,4)+" RSI8:"+DoubleToString(NormalizeDouble(iRSI(Symbol(),30,8,PRICE_MEDIAN,0),5),3); 
   else text=" S1:"+NormalizeDouble(iHigh(NULL,1440,0)-ATRAVG,4)+" RSI8:"+DoubleToString(NormalizeDouble(iRSI(Symbol(),30,8,PRICE_MEDIAN,0),5),3);
   
   
    ObjectCreate("xxt 5"+"GREATERX", OBJ_TEXT, 0, Time[10], NormalizeDouble(iLow(NULL,1440,0)+ATRAVG,4)+.0005); 
               ObjectSetText("xxt 5"+"GREATERX", " R1="+NormalizeDouble(iLow(NULL,1440,0)+ATRAVG,4), 24, "Arial Black", White); 
    ObjectCreate("xxt 5"+"GREATER", OBJ_TEXT, 0, Time[10], NormalizeDouble(iLow(NULL,1440,0)+ATRAVG,4)+.0005); 
               ObjectSetText("xxt 5"+"GREATER", "  R1="+NormalizeDouble(iLow(NULL,1440,0)+ATRAVG,4), 24, "Arial Black", Black); 
    ObjectCreate("xxt 5"+"SMALLERX", OBJ_TEXT, 0, Time[10], NormalizeDouble(iHigh(NULL,1440,0)-ATRAVG,4)+.0005); 
               ObjectSetText("xxt 5"+"SMALLERX", " S1="+NormalizeDouble(iHigh(NULL,1440,0)-ATRAVG,4), 24, "Arial Black", White);            
     ObjectCreate("xxt 5"+"SMALLER", OBJ_TEXT, 0, Time[10], NormalizeDouble(iHigh(NULL,1440,0)-ATRAVG,4)+.0005); 
               ObjectSetText("xxt 5"+"SMALLER", "  S1="+NormalizeDouble(iHigh(NULL,1440,0)-ATRAVG,4), 24, "Arial Black", Black);   

            
       
        


  for( i=80; i>=0; i--) {  
       LowBuffer3[i]=EMPTY_VALUE;
    HighBuffer3[i]=EMPTY_VALUE;
     LowBuffer4[i]=EMPTY_VALUE;
    HighBuffer4[i]=EMPTY_VALUE;
             if ((iHigh(NULL,60,i+3)-iLow(NULL,60,i))>ATRAVG/3 ||  (iHigh(NULL,60,i)-iLow(NULL,60,i+3))>ATRAVG/3 ) {
                  if (iHigh(NULL,60,i)>iHigh(NULL,60,i+3)) {LowBuffer3[i]=iHigh(NULL,60,i);
                                           HighBuffer3[i]=iHigh(NULL,60,i)+(iHigh(NULL,60,i)-iLow(NULL,60,i+3))*.55;  }
                  else if (iHigh(NULL,60,i)<iHigh(NULL,60,i+3)) {HighBuffer4[i]=iLow(NULL,60,i);
                        LowBuffer4[i]=iLow(NULL,60,i)-(iHigh(NULL,60,i+3)-iLow(NULL,60,i))*.55;  }
}
}


   k=1;
     while (!(stoch[k]>stoch[k+1] && stoch[k+2]>stoch[k+1]) && k<150)
      k++;
    l=1;
     while (!(stoch[l]<stoch[l+1] && stoch[l+2]<stoch[l+1]) && l<100)
      l++;
      


deletetxt1("L8");

if (put_label_on){  
  
ObjectCreate(0,"L888"+0, OBJ_RECTANGLE_LABEL, 0, 0,0);
 
  ObjectSet("L888"+0,OBJPROP_CORNER,0);
  ObjectSet("L888"+0,OBJPROP_XDISTANCE,10);
  ObjectSet("L888"+0,OBJPROP_YDISTANCE,180);
  
  ObjectSet("L888"+0,OBJPROP_XSIZE,315);
  ObjectSet("L888"+0,OBJPROP_YSIZE,135);
    ObjectSetInteger(0,"L888"+0,OBJPROP_COLOR,clrWhite);
    ObjectSet("L888"+0,OBJPROP_BACK,0);
    ObjectSet("L888"+0,OBJPROP_WIDTH,9);




 ObjectCreate("L81"+0,OBJ_LABEL,0, 0,0);
 
if (Close[0]>dt14-pacing/2) ObjectSetText("L81"+0,"95% at "+(DoubleToString(dt14-pacing/2,4)),16,"Arial Black",Red);
else if (Close[0]>dt14-pacing) ObjectSetText("L81"+0,"Deeply O.B. at "+(DoubleToString(dt14-pacing,4)),16,"Arial Black",Purple);
else if (Close[0]>dt14-pacing*1.5) ObjectSetText("L81"+0,"Upper Reversal "+(DoubleToString(dt14-pacing*1.5,4)),16,"Arial Black",Indigo);
else if (Close[0]>dt14-pacing*2) ObjectSetText("L81"+0,"Overbought at "+(DoubleToString(dt14-pacing*2,4)),16,"Arial Black",Black);
else if (Close[0]>dt14-pacing*2.5) ObjectSetText("L81"+0,"75% at "+(DoubleToString(dt14-pacing*2.5,4)),16,"Arial Black",Gray);
else if (Close[0]>dt14-pacing*3) ObjectSetText("L81"+0,"70% at "+(DoubleToString(dt14-pacing*3,4)),16,"Arial Black",Gray);
else if (Close[0]>dt14-pacing*3.5) ObjectSetText("L81"+0,"65% at "+(DoubleToString(dt14-pacing*3.5,4)),16,"Arial Black",Gray);
else if (Close[0]>dt14-pacing*4) ObjectSetText("L81"+0,"60% at "+(DoubleToString(dt14-pacing*4,4)),16,"Arial Black",Gray);
else if (Close[0]>dt14-pacing*4.5) ObjectSetText("L81"+0,"55% at "+(DoubleToString(dt14-pacing*4.5,4)),16,"Arial Black",Gray);
else if (Close[0]>dt14-pacing*5) ObjectSetText("L81"+0,"Median at "+(DoubleToString(dt14-pacing*5,4)),16,"Arial Black",OrangeRed);
else if (Close[0]>dt14-pacing*5.5) ObjectSetText("L81"+0,"45% at "+(DoubleToString(dt14-pacing*5.5,4)),16,"Arial Black",Gray);
else if (Close[0]>dt14-pacing*6) ObjectSetText("L81"+0,"40% at "+(DoubleToString(dt14-pacing*6,4)),16,"Arial Black",Gray);      
else if (Close[0]>dt14-pacing*6.5) ObjectSetText("L81"+0,"35% at "+(DoubleToString(dt14-pacing*6.5,4)),16,"Arial Black",Gray);
else if (Close[0]>dt14-pacing*7) ObjectSetText("L81"+0,"30% at "+(DoubleToString(dt14-pacing*7,4)),16,"Arial Black",Gray);     
else if (Close[0]>dt14-pacing*7.5) ObjectSetText("L81"+0,"25% at "+(DoubleToString(dt14-pacing*7.5,4)),16,"Arial Black",Gray);
else if (Close[0]>dt14-pacing*8) ObjectSetText("L81"+0,"Oversold at "+(DoubleToString(dt14-pacing*8,4)),16,"Arial Black",Black);    
else if (Close[0]>dt14-pacing*8.5) ObjectSetText("L81"+0,"Lower Reversal "+(DoubleToString(dt14-pacing*8.5,4)),16,"Arial Black",Indigo);
else if (Close[0]>dt14-pacing*9) ObjectSetText("L81"+0,"Deeply O.S. at "+(DoubleToString(dt14-pacing*9,4)),16,"Arial Black",Purple);
else if (Close[0]>dt14-pacing*9.5) ObjectSetText("L81"+0,"5% at "+(DoubleToString(dt14-pacing*9.5,4)),16,"Arial Black",Red);
else ObjectSetText("L81"+0,"",Red);
 
  ObjectSet("L81"+0,OBJPROP_CORNER,0);
  ObjectSet("L81"+0,OBJPROP_XDISTANCE,20);
  ObjectSet("L81"+0,OBJPROP_YDISTANCE,200);
  
   ObjectCreate("L82"+0,OBJ_LABEL,0, 0,0);
   
   
if (Close[0]<db14+pacing/2) ObjectSetText("L82"+0,"5% at "+(DoubleToString(db14+pacing/2,4)),16,"Arial Black",Red);
else if (Close[0]<db14+pacing) ObjectSetText("L82"+0,"Deeply O.S. at "+(DoubleToString(db14+pacing,4)),16,"Arial Black",Purple);
else if (Close[0]<db14+pacing*1.5) ObjectSetText("L82"+0,"Lower Reversal "+(DoubleToString(db14+pacing*1.5,4)),16,"Arial Black",Indigo);
else if (Close[0]<db14+pacing*2) ObjectSetText("L82"+0,"Oversold at "+(DoubleToString(db14+pacing*2,4)),16,"Arial Black",Black);
else if (Close[0]<db14+pacing*2.5) ObjectSetText("L82"+0,"25% at "+(DoubleToString(db14+pacing*2.5,4)),16,"Arial Black",Gray);
else if (Close[0]<db14+pacing*3) ObjectSetText("L82"+0,"30% at "+(DoubleToString(db14+pacing*3,4)),16,"Arial Black",Gray);
else if (Close[0]<db14+pacing*3.5) ObjectSetText("L82"+0,"35% at "+(DoubleToString(db14+pacing*3.5,4)),16,"Arial Black",Gray);
else if (Close[0]<db14+pacing*4) ObjectSetText("L82"+0,"40% at "+(DoubleToString(db14+pacing*4,4)),16,"Arial Black",Gray);
else if (Close[0]<db14+pacing*4.5) ObjectSetText("L82"+0,"45% at "+(DoubleToString(db14+pacing*4.5,4)),16,"Arial Black",Gray);
else if (Close[0]<db14+pacing*5) ObjectSetText("L82"+0,"Median at "+(DoubleToString(db14+pacing*5,4)),16,"Arial Black",OrangeRed);
else if (Close[0]<db14+pacing*5.5) ObjectSetText("L82"+0,"55% at "+(DoubleToString(db14+pacing*5.5,4)),16,"Arial Black",Gray);
else if (Close[0]<db14+pacing*6) ObjectSetText("L82"+0,"60% at "+(DoubleToString(db14+pacing*6,4)),16,"Arial Black",Gray);      
else if (Close[0]<db14+pacing*6.5) ObjectSetText("L82"+0,"65% at "+(DoubleToString(db14+pacing*6.5,4)),16,"Arial Black",Gray);
else if (Close[0]<db14+pacing*7) ObjectSetText("L82"+0,"70% at "+(DoubleToString(db14+pacing*7,4)),16,"Arial Black",Gray);     
else if (Close[0]<db14+pacing*7.5) ObjectSetText("L82"+0,"75% at "+(DoubleToString(db14+pacing*7.5,4)),16,"Arial Black",Gray);
else if (Close[0]<db14+pacing*8) ObjectSetText("L82"+0,"Overbought at "+(DoubleToString(db14+pacing*8,4)),16,"Arial Black",Black);    
else if (Close[0]<db14+pacing*8.5) ObjectSetText("L82"+0,"Upper Reversal "+(DoubleToString(db14+pacing*8.5,4)),16,"Arial Black",Indigo);
else if (Close[0]<db14+pacing*9) ObjectSetText("L82"+0,"Deeply O.B. at "+(DoubleToString(db14+pacing*9,4)),16,"Arial Black",Purple);
else if (Close[0]<db14+pacing*9.5) ObjectSetText("L82"+0,"95% at "+(DoubleToString(db14+pacing*9.5,4)),16,"Arial Black",Red);
else ObjectSetText("L82"+0,"",16,"Arial Black",Red);

  ObjectSet("L82"+0,OBJPROP_CORNER,0);
  ObjectSet("L82"+0,OBJPROP_XDISTANCE,20);
  ObjectSet("L82"+0,OBJPROP_YDISTANCE,180);
  
  ObjectCreate("L83"+0,OBJ_LABEL,0, 0,0);
  ObjectSetText("L83"+0," "+DoubleToString(Close[0],4)+", ATR:"+IntegerToString(ATRAVG*10000,1)+" TDY:"+IntegerToString(iATR(NULL,1440,1,0)*10000,1),16,"Arial Black",Blue);
  ObjectSet("L83"+0,OBJPROP_CORNER,0);
  ObjectSet("L83"+0,OBJPROP_XDISTANCE,20);
  ObjectSet("L83"+0,OBJPROP_YDISTANCE,220);
  
  
    ObjectCreate("L84"+0,OBJ_LABEL,0, 0,0);
   ObjectSetText("L84"+0,text,16,"Arial Black",Blue);
  ObjectSet("L84"+0,OBJPROP_CORNER,0);
  ObjectSet("L84"+0,OBJPROP_XDISTANCE,20);
  ObjectSet("L84"+0,OBJPROP_YDISTANCE,240);
  
  
      ObjectCreate("L85"+0,OBJ_LABEL,0, 0,0);
      if (Close[0]<weight) ObjectSetText("L85"+0,"Buy below: "+DoubleToString(weight-ATRAVG,4),16,"Arial Black",Black);
      else ObjectSetText("L85"+0,"Sell above: "+DoubleToString(weight+ATRAVG,4),16,"Arial Black",Black );
      
   ObjectSet("L85"+0,OBJPROP_CORNER,0);
  ObjectSet("L85"+0,OBJPROP_XDISTANCE,20);
  ObjectSet("L85"+0,OBJPROP_YDISTANCE,260);
  
  
        i=0;
   while (HighBuffer3[i]==EMPTY_VALUE && i<Bars)    
   i++;
   
 j=0;
   while (LowBuffer4[j]==EMPTY_VALUE && j<Bars)    
   j++;  
  
  
    ObjectCreate("L86"+0,OBJ_LABEL,0, 0,0);
    ObjectSetText("L86"+0,"Upr: "+DoubleToString(HighBuffer3[i],4)+" Dpr: "+DoubleToString(LowBuffer4[j],4),16,"Arial Black",Black); 
  ObjectSet("L86"+0,OBJPROP_CORNER,0);
  ObjectSet("L86"+0,OBJPROP_XDISTANCE,20);
  ObjectSet("L86"+0,OBJPROP_YDISTANCE,280);

}
   

return(0);
}

 
double ChoppinessIndex15(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,15,k);
      High0  = iHigh(NULL,15,k);
      Close1 = iClose(NULL,15,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 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 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 what){
   for(int iObj=ObjectsTotal()-1; iObj >= 0; iObj--){
      string   on = ObjectName(iObj);
      if(StringFind(on, what) == 0)  ObjectDelete(on);
}  }