//+------------------------------------------------------------------+
//|                                                 Ano gojek ciledug|
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Darwati"
#property link      ""

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_level1 20
#property indicator_levelcolor clrYellow
#property indicator_level2 80
#property indicator_level3 50
#property indicator_level4 96
#property indicator_level5 4


//---- parameters
//
//
//
//
string IndicatorName, IndicatorObjPrefix;




extern string timeFrame = "0";

//---- buffers

double Line1[], Line2[], Line3[] ,Line4[],Line5[], Line6[], Line7[],Line8[],Line9[], Line10[], Line11[] ,Line12[],Line13[], Line14[], Line15[] ,Line16[],Line17[],Line18[],Line19[],Line20[],Line21[],Line22[],Line23[],Line24[],Line25[],Line26[],Line27[],Line28[],Line29[],Line30[],Line31[],Line32[],Line33[];



datetime RTimeArray[];
datetime TTimeArray[];
int    TimeFrame;
int    atrTimeFrame;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

string GenerateIndicatorName(const string target)
{
   string name = target;
   int try = 2;
   while (WindowFind(name) != -1)
   {
      name = target + " #" + IntegerToString(try++);
   }
   return name;
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//----//put in the Init() function
//if(TimeCurrent() >= StrToTime(ExpiryDate)){
//Alert("Indi AnoDashLine3 sdh Expired, wa +62895 3374 03 585");

//return(1);
//}
//else{
//Print(" Indicator Valid");
//}

   IndicatorObjPrefix = "__" + IndicatorName + "__";
   IndicatorShortName(IndicatorName);
   IndicatorDigits(Digits);

 
 //  SetIndexStyle(5,DRAW_LINE,STYLE_SOLID,4,Green);//DRAW_LINE
 //  SetIndexBuffer(5,Line6);

 //  SetIndexStyle(6,DRAW_LINE,STYLE_SOLID,4,Red);//DRAW_LINE
 //  SetIndexBuffer(6,Line7);

   

   
   IndicatorDigits(Digits);
   IndicatorShortName("Darwati-Master");

       
   TimeFrame = stringToTimeFrame(timeFrame);
   atrTimeFrame=PERIOD_D1;
   if (TimeFrame >= atrTimeFrame)
      switch (TimeFrame)
         {
            case PERIOD_D1: atrTimeFrame = PERIOD_W1; break;
            default:        atrTimeFrame = PERIOD_MN1;

         }

   


   
      
   return(0);
}


int deinit()
{
   ObjectsDeleteAll(ChartID(), IndicatorObjPrefix);
   ObjectsDeleteAll(1, OBJ_LABEL);
    return(0);
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+


int start()
{
    int accnt2 = 200079257;
    int accnt3 = 52091565; 
   double Bal1=AccountBalance();
   //SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Lime);//DRAW_LINE
   //SetIndexBuffer(0,Line1);
   SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,3,Magenta);//DRAW_LINE
   SetIndexBuffer(2,Line1);
   SetIndexArrow(2,251); 

   SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,3,Lime);//DRAW_LINE
   SetIndexBuffer(3,Line2);
   SetIndexArrow(3,251); 
   SetIndexStyle(0,DRAW_ARROW,STYLE_SOLID,1,Magenta);//DRAW_LINE
   SetIndexBuffer(0,Line10);
   SetIndexArrow(0,108); 

   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1,Lime);//DRAW_LINE
   SetIndexBuffer(1,Line11);
   SetIndexArrow(1,108); 

   SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID,4,Red);//DRAW_LINE
   SetIndexBuffer(4,Line5);
   SetIndexArrow(4,251); 

   SetIndexStyle(5,DRAW_ARROW,STYLE_SOLID,4,Aqua);//DRAW_LINE
   SetIndexBuffer(5,Line6);
   SetIndexArrow(5,251); 
   
   SetIndexStyle(6,DRAW_ARROW,STYLE_SOLID,2,Magenta);//DRAW_LINE
   SetIndexBuffer(6,Line7);
   SetIndexArrow(6,108); 

   double maValue;
   double avgRange;
   double Tenkan;
   double   SpanB;
   double   SpanA;
   double   SpanB1;
   //double   Spike;
   

   int    counted_bars=IndicatorCounted();
   int    limit;
   int    i,r,y;
  

//----
     
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
      limit=MathMax(Bars-counted_bars,TimeFrame/Period());   
      
      ArrayCopySeries(RTimeArray ,MODE_TIME ,NULL,atrTimeFrame);
      ArrayCopySeries(TTimeArray ,MODE_TIME ,NULL,0);

   //----
   //
   //
   //
   //
   
      for (i=0,r=0,y=0;i<limit;i++)
         {
            if(Time[i]<RTimeArray[r]) r++;
            if(Time[i]<TTimeArray[y]) y++;
               
               avgRange          = iATR(NULL,atrTimeFrame,6,r);
               maValue           = iCustom(NULL,0,"SR Direction Helper File 3_3",0,y);
               SpanA             = iCustom(NULL,0,"SR Direction Helper File 3_3",1,y);
               SpanB             = iCustom(NULL,0,"SR Direction Helper File 3_3",2,y);
               Tenkan            = iCustom(NULL,0,"SR Direction Helper File 3_3",3,y);
               SpanB1            = iCustom(NULL,0,"SR Direction Helper File 3_3",4,y);
    
      Line1[i]=maValue;
      Line2[i]=SpanA;
      Line3[i]=SpanB;
      Line4[i]=Tenkan;
      Line5[i]=SpanB1;
//}
    
         }
   return(0);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+


int stringToTimeFrame(string tfs)
{
   int tf=0;
       
         if (tfs=="M1" || tfs=="1")     tf=PERIOD_M15;
         if (tfs=="M5" || tfs=="5")     tf=PERIOD_M15;
         if (tfs=="M15"|| tfs=="15")    tf=PERIOD_M15;
         if (tfs=="M30"|| tfs=="30")    tf=PERIOD_M15;
         if (tfs=="H1" || tfs=="60")    tf=PERIOD_M15;
         if (tfs=="H4" || tfs=="240")   tf=PERIOD_M15;
         if (tfs=="D1" || tfs=="1440")  tf=PERIOD_M15;
         if (tfs=="W1" || tfs=="10080") tf=PERIOD_M15;
         if (tfs=="MN" || tfs=="43125") tf=PERIOD_M15;
         if (tf<Period()) tf=Period();
  


//
//
//
//
//

   
   return(0);
}