//+------------------------------------------------------------------+
//|                                                    Test Indi.mq4 |
//|                                                    abc@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025"
#property link      "https://www.abc.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_level1 20.0
#property indicator_level2 50.0
#property indicator_level3 80.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT

//+------------------------------------------------------------------+
// User Input Variables

int      strSf=0;
int      endSf=20;

ENUM_LINE_STYLE LineStyle=0;
int      LineWid=2;
color    LineClr=clrLime;
string   LineLabel="Sto";

ENUM_LINE_STYLE VLStyle=3;
bool     VLLabelDel=true;
string   VLLabel="VL_";

int      VLGrWid=1;
color    VLGrClr=clrLime;

int      VLRdWid=1;
color    VLRdClr=clrPink;

//+------------------------------------------------------------------+
string   sym=Symbol();
int      tTF=Period();
//+------------------------------------------------------------------+
// LINES BUFFERS

double buf1[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit() {

//+------------------------------------------------------------------+
   IndicatorDigits(3);

   SetIndexStyle(0,DRAW_LINE,LineStyle,LineWid,LineClr);
   SetIndexBuffer(0,buf1);
   SetIndexLabel(0,LineLabel+" ");

   return(INIT_SUCCEEDED);
   }

//+------------------------------------------------------------------+
//| Deinitialization function                                        |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
   Comment("");

   for(int i=ObjectsTotal()-1; i>=0; i--) {
   if((VLLabelDel && StringFind(ObjectName(i),VLLabel)!=-1) || StringFind(ObjectName(i),LineLabel)!=-1) {
   Print(IntegerToString(i)+") "+ObjectName(i));
   ObjectDelete(ObjectName(i));}}

   }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {

//+------------------------------------------------------------------+
   ArrayResize(buf1,endSf+1);

   for(int i=strSf; i<endSf+1; i++) buf1[i]=iStochastic(sym,tTF,5,3,3,0,0,0,i);
//+------------------------------------------------------------------+ Draw Vertical Lines Main Chart
   for(int i=strSf; i<=endSf; i++) {double cSto0=iStochastic(sym,tTF,5,3,3,0,0,0,i);

   if(cSto0<=20) drawVL(i,VLLabel+"O/Sold(Up)",VLGrClr,VLGrWid,true);
   if(cSto0>20 && ObjectFind(0,VLLabel+"O/Sold(Up)"+IntegerToString(Time[i]))!=-1)
      ObjectDelete(VLLabel+"O/Sold(Up)"+IntegerToString(Time[i]));

   if(cSto0>=80) drawVL(i,VLLabel+"O/Bogt(Dw)",VLRdClr,VLRdWid,true);
   if(cSto0<80 && ObjectFind(0,VLLabel+"O/Bogt(Dw)"+IntegerToString(Time[i]))!=-1)
      ObjectDelete(VLLabel+"O/Bogt(Dw)"+IntegerToString(Time[i]));
   }
   //+-------------------------------------------+

   return(rates_total);
   }

//+------------------------------------------------------------------+
//| Draw Vertical Lines on Selected Bar Chart                        |
//+------------------------------------------------------------------+
void drawVL(int i, string text, color colour, int width, bool draw) {

   if(draw) {ObjectCreate(text+IntegerToString(Time[i]),OBJ_VLINE,0,Time[i],0);
             ObjectSet(text+IntegerToString(Time[i]),OBJPROP_STYLE,VLStyle);
             ObjectSet(text+IntegerToString(Time[i]),OBJPROP_BACK,true);
             ObjectSet(text+IntegerToString(Time[i]),OBJPROP_COLOR,colour);
             ObjectSet(text+IntegerToString(Time[i]),OBJPROP_WIDTH,width);}
   }

