//+------------------------------------------------------------------+
//|                                   BLM Ichimoku Table update .mq4 |
//|                                            Copyright 2017 by Blm |
//|                                www.facebook.com/adelmarravillaii |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017 by Blm"
#property link      "www.facebook.com/adelmarravillaii"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
input string Input="";//////Please input the Pairs separated by semicolon (;) without space./////
input string Input2="";//////You must input correct Pair Name available by your broker./////
input string Input3="";//   1% Risque for training
input string Input4="";//   2% Risque for Advanced
input string Input5="";//   3% Risque for Experinced
input string Pairs="EURUSD;GBPUSD;NZDUSD;AUDUSD;XAUUSD;USDCAD;USDCHF;USDJPY;GBPJPY;CADJPY;NZDJPY;CHFJPY;AUDJPY;EURJPY";
//"EURUSD;EURGBP;EURAUD;EURCAD;GBPUSD;GBPCHF;USDJPY;EURJPY;GBPJPY;AUDJPY;NZDJPY;CHFJPY;CADJPY;USDCAD;USDCHF;AUDUSD;NZDUSD"
input int    ATR_Period=200;
double   Risque_Reward=1.5;
input double Capital=1000;
input double Risque_Pourcentage_Par_trade =1;
 double TP_amplifier=1;
 double SL_amplifier=1.7;

 double Daily_Risque = 8 ;
string Id="ATRBox";
string PairsArray[100];
double Gains;

int OnInit()
  {
//--- indicator buffers mapping
   StringToArray(Pairs,PairsArray);
   EditCreate(Id+"PairHead",300,25,100,25,"Pairs","Verdana",12,ALIGN_CENTER,clrOrange,clrBlack,clrNONE);
   
   
  
   
   
    EditCreate(Id+"LotHead",100,25,70,25,"Lot","Verdana",12,ALIGN_CENTER,clrDarkBlue,clrLime,clrNONE);
     
  //  EditCreate(Id+"tp1",1020,20,100,20,"TakeProfit","Verdana",12,ALIGN_CENTER,clrGreen,clrBlack,clrNONE);
    EditCreate(Id+"sl1",200,25,100,25,"StopLoss","Verdana",12,ALIGN_CENTER,clrRed,clrBlack,clrNONE);
    
   int nexty=50;
   for(int i=0;i<ArraySize(PairsArray);i++){
      EditCreate(Id+"Pair"+PairsArray[i],300,nexty,100,40,PairsArray[i],"Verdana",16,ALIGN_CENTER,clrGold,clrBlack,clrNONE);

     
      
     // EditCreate(Id+"tp10"+PairsArray[i],1020,nexty,100,24,"","Verdana",11,ALIGN_CENTER,clrLimeGreen,clrBlack,clrNONE);
       EditCreate(Id+"sl10"+PairsArray[i],200,nexty,100,40,"","Verdana",14,ALIGN_CENTER,clrTomato,clrBlack,clrNONE);
      
      EditCreate(Id+"Lot1212"+PairsArray[i],100,nexty,70,40,"","Verdana",14,ALIGN_CENTER,clrRoyalBlue,clrChartreuse,clrNONE);
   
  //-------------------------------------------------------------------------------------------------------------  
   
   ObjectCreate("1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("1","Capital"+"=" +Capital+"$",11, "Arial Black", clrSpringGreen);
   ObjectSet("1", OBJPROP_CORNER, 1);
   ObjectSet("1", OBJPROP_XDISTANCE, 40);
   ObjectSet("1", OBJPROP_YDISTANCE, 0);
   
   ObjectCreate("rs", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("rs","Risque"+"="+Risque_Pourcentage_Par_trade+"%",11, "Arial Black", Red);
   ObjectSet("rs", OBJPROP_CORNER, 1);
   ObjectSet("rs", OBJPROP_XDISTANCE, 200);
   ObjectSet("rs", OBJPROP_YDISTANCE, 0); 
   
   
  
   
   
 
 //--------------------------------------------------------------------------------------------------------------------  

 
      
      
      
      
      nexty+=33;
   }
//---
   return(INIT_SUCCEEDED);
  }


void OnDeinit(const int reason=0)
  {
   Comment("");
   //RectLabelDelete(0,"Box1");
   //LabelDelete(0,"Label1");
   ObjectsDeleteByPrefix(Id);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   int i;
   double tick=0;
   double Lot=0;double Lot2=0;double Lot3=0;
   double Closee=0,Closee2=0;
   double RangeUp=0,RangeDown=0;
   double HAopen=0,HAclose=0;
   double HAopen2=0,HAclose2=0;
   double EMA1=0,EMA2=0,EMA3=0,EMA4=0,LWMAs=0,LWMAf=0;
   double DATR=0;
   double DATR2=0;
   double poin=0;
   double Spread=0;
   double TP1=0,TP2=0,STOP=0,Take=0;
   Spread = MarketInfo(Symbol(), MODE_SPREAD);
   double RSI = 0 ;
   for(i=0;i<ArraySize(PairsArray);i++){
      poin=(MarketInfo(PairsArray[i],MODE_POINT));
   double Up1=0,Up2=0,Down1=0,Down2=0;   
 //-----------------Indicators-----------------------------------------------------------------------------//     
      EMA1=iMA(PairsArray[i],PERIOD_H1,120,0,MODE_EMA,PRICE_CLOSE,0);
      EMA2=iMA(PairsArray[i],PERIOD_H1,50,3,MODE_EMA,PRICE_CLOSE,3);
      EMA4=iMA(PairsArray[i],PERIOD_M30,20,0,MODE_EMA,PRICE_CLOSE,0);
   //   EMA3=iMA(PairsArray[i],PERIOD_M30,5,1,MODE_EMA,PRICE_CLOSE,1);
      RSI=iRSI(PairsArray[i],PERIOD_H1,34,PRICE_CLOSE,0);
    //  RangeUp=iEnvelopes(PairsArray[i],PERIOD_M30,200,MODE_EMA,0,PRICE_CLOSE,0.09,1,0);
      RangeDown=iEnvelopes(PairsArray[i],PERIOD_M30,200,MODE_EMA,0,PRICE_CLOSE,0.09,2,0);
      Closee = iClose(PairsArray[i],PERIOD_H1,0);
      Closee2=iClose(PairsArray[i],PERIOD_M30,0);
      LWMAf=iMA(PairsArray[i],PERIOD_M15,8,0,MODE_LWMA,PRICE_TYPICAL,0);
      LWMAs=iMA(PairsArray[i],PERIOD_M15,11,0,MODE_LWMA,PRICE_TYPICAL,0);
      Up1=(EMA1>EMA2);
      Up2=(LWMAf>LWMAs);
      Down1=(EMA1<EMA2);
      Down2=(LWMAf<LWMAs);
      
       double Di_mi,Di_pl,Adx1,Adx2,Adx3;
       
      Adx1 =  iADX(PairsArray[i],PERIOD_M30,8,PRICE_CLOSE,MODE_MAIN,0);
      Adx2 =  iADX(PairsArray[i],PERIOD_M30,8,PRICE_CLOSE,MODE_MAIN,1);
      Adx3 =  iADX(PairsArray[i],PERIOD_M30,8,PRICE_CLOSE,MODE_MAIN,2);
      Di_mi = iADX(PairsArray[i],PERIOD_M30,8,PRICE_CLOSE,MODE_MINUSDI,0);
      Di_pl = iADX(PairsArray[i],PERIOD_M30,8,PRICE_CLOSE,MODE_PLUSDI,0);
  if((Adx3>Adx2)&&(Adx2>Adx1))
  {
      SetEditText(Id+"ttrend2018"+PairsArray[i],CharToStr(74),clrRed);
      }
  
  
 //--------------------------------------------------------------------------------------------------------//
     tick= MarketInfo(PairsArray[i],MODE_TICKVALUE);
     Gains = (AccountEquity()*16)/100;
     
     
     SetEditText(Id+"adxx"+PairsArray[i],DoubleToStr(Adx1,2),clrBlack);
     SetEditText(Id+"adxx1"+PairsArray[i],DoubleToStr(Adx2,2),clrBlack);
     SetEditText(Id+"adxx2"+PairsArray[i],DoubleToStr(Adx3,2),clrBlack);
      
       HAopen=iCustom(PairsArray[i],PERIOD_M30,"Heiken Ashi",2,0);
      HAclose=iCustom(PairsArray[i],PERIOD_M30,"Heiken Ashi",3,0);
      
      HAopen2=iCustom(PairsArray[i],PERIOD_D1,"Heiken Ashi",2,0);
      HAclose2=iCustom(PairsArray[i],PERIOD_D1,"Heiken Ashi",3,0);
      double Renko;
     
     SetEditText(Id+"H4tend"+PairsArray[i],DoubleToStr(Di_pl,2),clrBlack);
     SetEditText(Id+"H4tend2"+PairsArray[i],DoubleToStr(Di_mi,2),clrBlack);
  /*   
     if(Di_mi>Di_pl)/////// SELL
      {
      SetEditText(Id+"ttrend2018"+PairsArray[i],CharToStr(234),clrRed);
      }
      else
      {
      SetEditText(Id+"ttrend2018"+PairsArray[i],CharToStr(233),clrGreen);
      }
      */
      if(HAclose>HAopen)/////// BUY
      {
      SetEditText(Id+"Trend"+PairsArray[i],CharToStr(233),clrGreen);
      }
      
      
      if(HAclose<HAopen)/////// SELL
      {
      SetEditText(Id+"Trend"+PairsArray[i],CharToStr(234),clrRed);
      }
      
       if(HAclose2>HAopen2)/////// BUY
      {
      SetEditText(Id+"Trend2"+PairsArray[i],CharToStr(233),clrGreen);
      }
      
      
      if(HAclose2<HAopen2)/////// SELL
      {
      SetEditText(Id+"Trend2"+PairsArray[i],CharToStr(234),clrRed);
      }
               
      DATR=NormalizeDouble(iATR(PairsArray[i],PERIOD_H1,ATR_Period,0)/poin,0);
      SetEditText(Id+"H4ATR"+PairsArray[i],DoubleToStr(DATR,0),clrBlack);
      
      SetEditText(Id+"H4ATR11"+PairsArray[i],DoubleToStr(Renko,0),clrBlack);
      
      
     // DATR2=((DATR*TP_amplifier)/Risque_Reward)  ;    ///// StopCover/////
      //SetEditText(Id+"H4ATR2"+PairsArray[i],DoubleToStr(DATR2,0),clrBlack);
      Lot=((Capital*Risque_Pourcentage_Par_trade)/100);
      Lot2=((Lot/(DATR/SL_amplifier))/tick);
      SetEditText(Id+"Lot1212"+PairsArray[i],DoubleToStr(Lot2,2),clrBlack);
      
    //  TP1=DATR*SL_TP_amplifier;
    //  SetEditText(Id+"TP"+PairsArray[i],DoubleToStr(TP1,0),clrBlack); 
   //   Lot3=((Lot/DATR2)/2)/tick;
    //  SetEditText(Id+"Lot21"+PairsArray[i],DoubleToStr(Lot2,2),clrBlack);
      
      Take=DATR*TP_amplifier;
      SetEditText(Id+"tp10"+PairsArray[i],DoubleToStr(Take,0),clrBlack);
      
      STOP=Take/SL_amplifier;    
      SetEditText(Id+"sl10"+PairsArray[i],DoubleToStr(STOP,0),clrBlack);
       
      
      
    }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

void SetEditText(string name, string txt, color clr=clrBlack){
   ObjectSetString(0,name,OBJPROP_TEXT,txt);
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
}

void StringToArray(string setring, string & array[])
{
   string tmp_txt=StringTrimLeft(StringTrimRight(setring));
   int koma=0;
   int arraycount=0;
   string txt_result="";
   while(tmp_txt!=""){
      koma=StringFind(tmp_txt,";",0);
      txt_result="";
      if(koma>0){txt_result=StringSubstr(tmp_txt,0,koma);}
      if(koma<=0){
         if(StringLen(tmp_txt)>0){txt_result=tmp_txt;tmp_txt="";}
         if(StringLen(tmp_txt)<0){tmp_txt="";break;}
      }
      if(txt_result=="")continue;
      tmp_txt=StringSubstr(tmp_txt,koma+1);
      ArrayResize(array, arraycount+1);
      array[arraycount]=txt_result;
      arraycount++;
   }
}

void ObjectsDeleteByPrefix(string prefix)
{
   string ObjName;
   int strLength = StringLen(prefix);
   int Count = 0;
   while (Count < ObjectsTotal()) {
      ObjName = ObjectName(Count);
      if (StringSubstr(ObjName, 0, strLength) != prefix) Count++;
      else ObjectDelete(ObjName);
   }
}


bool EditCreate(
                const string           name="Edit",              // object name
                const int              x=0,                      // X coordinate
                const int              y=0,                      // Y coordinate
                const int              width=50,                 // width
                const int              height=18,                // height
                const string           text="Text",              // text
                
                
                
                const string           font="Arial",             // font
                const int              font_size=10,             // font size
                const ENUM_ALIGN_MODE  align=ALIGN_LEFT,       // alignment type
                const color            back_clr=clrNONE,        // background color
                const color            clr=clrYellow,             // text color
                color                  border_clr=clrNONE,
                )                // priority for mouse click
  {
//--- reset the error value
                const int              sub_window=0;             // subwindow index
                const long             chart_ID=0;               // chart's ID
                const bool             read_only=true;          // ability to edit
                const ENUM_BASE_CORNER corner=CORNER_RIGHT_UPPER; // chart corner for anchoring
                const bool             back=false;               // in the background
                const bool             selection=false;          // highlight to move
                const bool             hidden=true;              // hidden in the object list
                const long             z_order=0;
   if(border_clr==clrNONE)border_clr=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);       // border color
   ResetLastError();
//--- create edit field
   if(!ObjectCreate(chart_ID,name,OBJ_EDIT,sub_window,0,0))
     {
      Print(__FUNCTION__,
            ": failed to create \"Edit\" object! Error code = ",GetLastError());
      return(false);
     }
//--- set object coordinates
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- set object size
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- set the text
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text font
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font size
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the type of text alignment in the object
   ObjectSetInteger(chart_ID,name,OBJPROP_ALIGN,align);
//--- enable (true) or cancel (false) read-only mode
   ObjectSetInteger(chart_ID,name,OBJPROP_READONLY,read_only);
//--- set the chart's corner, relative to which object coordinates are defined
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- set text color
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set background color
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr);
//--- set border color
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,border_clr);
//--- display in the foreground (false) or background (true)
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of moving the label by mouse
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object list
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chart
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful execution
   return(true);
  }
  
bool EditDelete(const long   chart_ID=0,  // chart's ID
                const string name="Edit") // object name
  {
  
//---reset the error value
   ResetLastError();
//--- delete the label
   if(ObjectFind(0,name)<0)return(true);
   if(!ObjectDelete(chart_ID,name))
     {
      Print(__FUNCTION__,
            ": failed to delete \"Edit\" object! Error code = ",GetLastError());
      return(false);
     }
// ---  successful execution
   return(true);
   
  }
  