#property indicator_chart_window

bool show=false,ea_show=false,Op_ShwB=false,Op_Show=false,Op_OHL=true,Op_HiLo=false,Op_DDw=false,Op_DDw2=false,Op_DDw3=false,
      script=false, rate1c=true, rate2c=false, rate3c=false, rate4c=false, ha_Opt=false;
int frameX=20, frameY=35, Op_Liqu;           // ^ test iOPen/(iHigh+iLow)/2

int init()
  {
   if (GlobalVariableCheck("ShowAll")) show = GlobalVariableGet("ShowAll");
   if (GlobalVariableCheck("Show_EA")) ea_show = GlobalVariableGet("Show_EA");
   if (GlobalVariableCheck("Op_ShwB")) Op_ShwB = GlobalVariableGet("Op_ShwB");
   if (GlobalVariableCheck("Op_OHL")) Op_OHL = GlobalVariableGet("Op_OHL");
   if (GlobalVariableCheck("Op_Show")) Op_Show = GlobalVariableGet("Op_Show");
   if (GlobalVariableCheck("Op_DDw")) Op_DDw = GlobalVariableGet("Op_DDw");
   if (GlobalVariableCheck("Op_DDw2")) Op_DDw2 = GlobalVariableGet("Op_DDw2");
   if (GlobalVariableCheck("Op_DDw3")) Op_DDw3 = GlobalVariableGet("Op_DDw3");
   if (GlobalVariableCheck("Op_HiLo")) Op_HiLo = GlobalVariableGet("Op_HiLo");
   if (GlobalVariableCheck("frameX")) frameX = GlobalVariableGet("frameX");
   if (GlobalVariableCheck("frameY")) frameY = GlobalVariableGet("frameY");

  if (GlobalVariableCheck("OScript")) script = GlobalVariableGet("OScript");
  if (GlobalVariableCheck("RateOC1")) rate1c = GlobalVariableGet("RateOC1");
  if (GlobalVariableCheck("RateOC2")) rate2c = GlobalVariableGet("RateOC2");
  if (GlobalVariableCheck("RateOC3")) rate3c = GlobalVariableGet("RateOC3");
  if (GlobalVariableCheck("RateOC4")) rate4c = GlobalVariableGet("RateOC4");

  if (GlobalVariableCheck("H_A_Opt")) ha_Opt = GlobalVariableGet("H_A_Opt");
  if (GlobalVariableCheck("Op_Liqu")) Op_Liqu = GlobalVariableGet("Op_Liqu");

//   CreateButton(0,0,"||",1,frameX-14,frameY+13,0);
   return(0);
  }
int deinit()
  {
   return(0);
  }

int start() {
  return(0);
}

const string PREFIX = "EA_Test";
void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam){
//   Print("*** ",lparam," - ",dparam," - ",sparam," ***");
   if (id == CHARTEVENT_OBJECT_CLICK) {      //CHARTEVENT_OBJECT_DRAG
//         framex = ObjectGetInteger(0,"Label_Equity",OBJPROP_XDISTANCE);
//         framey = ObjectGetInteger(0,"Label_Equity",OBJPROP_YDISTANCE);
//         ObjectSetInteger(0,"Label_Equity",OBJPROP_XDISTANCE,300);
//         ObjectSetInteger(0,"Label_Equity",OBJPROP_YDISTANCE,framey);
//         Sleep(3000);

      if (sparam == PREFIX+"_Label_Show") { show = (show ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, show? clrAqua: clrSilver);
//            Print("*** Option ShowAll = ",show? true: false," ***");
            GlobalVariableSet("ShowAll", show); }
      else if (sparam == PREFIX+"_Label_Show-EA") { ea_show = (ea_show ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, ea_show? clrAqua: clrSilver);
//            Print("*** Option Show-EA = ",ea_show? true: false," ***");
            GlobalVariableSet("Show_EA", ea_show); }
      else if (sparam == PREFIX+"_Label_Op_OHL") { Op_OHL = (Op_OHL ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, Op_OHL? clrAqua: clrSilver);
//            Print("*** Option Op_OHL = ",Op_OHL? true: false," ***");
            GlobalVariableSet("Op_OHL", Op_OHL); }
      else if (sparam == PREFIX+"_Label_Op_Show") { Op_Show = (Op_Show ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, Op_Show? clrAqua: clrSilver);
//            Print("*** Option Op_Show = ",Op_Show? true: false," ***");
            GlobalVariableSet("Op_Show", Op_Show); }
      else if (sparam == PREFIX+"_Label_Op_pDDw") { Op_DDw = (Op_DDw ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, Op_DDw? clrAqua: clrSilver);
//            Print("*** Option Op_DDw = ",Op_DDw? true: false," ***");
            GlobalVariableSet("Op_DDw", Op_DDw); }
      else if (sparam == PREFIX+"_Label_Op_DDw1") { Op_DDw2 = (Op_DDw2 ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, Op_DDw2? clrAqua: clrSilver);
//            Print("*** Option Op_DDw2 = ",Op_DDw2? true: false," ***");
            GlobalVariableSet("Op_DDw2", Op_DDw2); }
      else if (sparam == PREFIX+"_Label_Op_DDw2") { Op_DDw3 = (Op_DDw3 ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, Op_DDw3? clrAqua: clrSilver);
//            Print("*** Option Op_DDw3 = ",Op_DDw3? true: false," ***");
            GlobalVariableSet("Op_DDw3", Op_DDw3); }
      else if (sparam == PREFIX+"_Label_Op_HiLo") { Op_HiLo = (Op_HiLo ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, Op_HiLo? clrAqua: clrSilver);
//            Print("*** Option Op_HiLo = ",Op_HiLo? true: false," ***");
            GlobalVariableSet("Op_HiLo", Op_HiLo); }
      else if (sparam == PREFIX+"_Label_||") { Op_ShwB = (Op_ShwB ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, Op_ShwB? clrAqua: clrSilver);
//            Print("*** Option Op_ShwB = ",Op_ShwB? true: false," ***");
            GlobalVariableSet("Op_ShwB", Op_ShwB); }

      else if (sparam == PREFIX+"_Label_Script") { script = (script ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, script? clrAqua: clrSilver);
//            Print("*** Option OScript = ",script? true: false," ***");
            GlobalVariableSet("OScript", script); }
      else if (sparam == PREFIX+"_Label_rate1c") { rate1c = (rate1c ? false : true);
            rate2c = false;      rate3c = false;      rate4c = false;
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, rate1c? clrSkyBlue: clrSilver);
//            Print("*** Option RateOC1 = ",rate1c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate2c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC2 = ",rate2c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate3c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC3 = ",rate3c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate4c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC4 = ",rate4c? true: false," ***");
            GlobalVariableSet("RateOC1", rate1c);
            GlobalVariableSet("RateOC2", rate2c);
            GlobalVariableSet("RateOC3", rate3c);
            GlobalVariableSet("RateOC4", rate4c); }
      else if (sparam == PREFIX+"_Label_rate2c") { rate2c = (rate2c ? false : true);
            rate1c = false;      rate3c = false;      rate4c = false;
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, rate2c? clrSkyBlue: clrSilver);
//            Print("*** Option RateOC2 = ",rate2c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate1c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC1 = ",rate1c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate3c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC3 = ",rate3c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate4c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC4 = ",rate4c? true: false," ***");
            GlobalVariableSet("RateOC1", rate1c);
            GlobalVariableSet("RateOC2", rate2c);
            GlobalVariableSet("RateOC3", rate3c);
            GlobalVariableSet("RateOC4", rate4c); }
      else if (sparam == PREFIX+"_Label_rate3c") { rate3c = (rate3c ? false : true);
            rate1c = false;      rate2c = false;      rate4c = false;
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, rate3c? clrSkyBlue: clrSilver);
//            Print("*** Option RateOC3 = ",rate3c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate1c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC1 = ",rate1c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate2c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC2 = ",rate2c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate4c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC4 = ",rate4c? true: false," ***");
            GlobalVariableSet("RateOC1", rate1c);
            GlobalVariableSet("RateOC2", rate2c);
            GlobalVariableSet("RateOC3", rate3c);
            GlobalVariableSet("RateOC4", rate4c); }
      else if (sparam == PREFIX+"_Label_rate4c") { rate4c = (rate4c ? false : true);
            rate1c = false;      rate2c = false;      rate3c = false;
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, rate4c? clrSkyBlue: clrSilver);
//            Print("*** Option RateOC4 = ",rate4c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate1c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC1 = ",rate1c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate2c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC2 = ",rate2c? true: false," ***");
            ObjectSetInteger(0,PREFIX+"_Label_rate3c",OBJPROP_COLOR, clrSilver);
//            Print("*** Option RateOC3 = ",rate3c? true: false," ***");
            GlobalVariableSet("RateOC1", rate1c);
            GlobalVariableSet("RateOC2", rate2c);
            GlobalVariableSet("RateOC3", rate3c);
            GlobalVariableSet("RateOC4", rate4c); }

      else if (sparam == PREFIX+"_Label_Op_HA") { ha_Opt = (ha_Opt ? false : true);
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, ha_Opt? clrDeepSkyBlue: clrSilver);
//            Print("*** Option OScript = ",ha_Opt? true: false," ***");
            GlobalVariableSet("H_A_Opt", ha_Opt); }
      else if (sparam == PREFIX+"_Label_exp-Err") { Op_Liqu = 0;
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, clrSkyBlue);
            ObjectSetInteger(0,PREFIX+"_Label_expSo1",OBJPROP_COLOR,clrSilver);
            ObjectSetInteger(0,PREFIX+"_Label_expSo2",OBJPROP_COLOR,clrSilver);
//            Print("*** Option OScript = ",Op_Liqu? true: false," ***");
            GlobalVariableSet("Op_Liqu", Op_Liqu); }
      else if (sparam == PREFIX+"_Label_expSo1") { Op_Liqu = 1;
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, clrSkyBlue);
            ObjectSetInteger(0,PREFIX+"_Label_exp-Err",OBJPROP_COLOR,clrSilver);
            ObjectSetInteger(0,PREFIX+"_Label_expSo2",OBJPROP_COLOR,clrSilver);
//            Print("*** Option OScript = ",Op_Liqu? true: false," ***");
            GlobalVariableSet("Op_Liqu", Op_Liqu); }
      else if (sparam == PREFIX+"_Label_expSo2") { Op_Liqu = 2;
            ObjectSetInteger(0,sparam,OBJPROP_COLOR, clrSkyBlue);
            ObjectSetInteger(0,PREFIX+"_Label_exp-Err",OBJPROP_COLOR,clrSilver);
            ObjectSetInteger(0,PREFIX+"_Label_expSo1",OBJPROP_COLOR,clrSilver);
//            Print("*** Option OScript = ",Op_Liqu? true: false," ***");
            GlobalVariableSet("Op_Liqu", Op_Liqu); }

      else if (sparam == PREFIX+"_Label_<>") { frameX = (frameX==20 ? 300 : (frameX==300 ? 170 : 20));
            ObjectSetInteger(0,PREFIX+"_Label_Op_OHL",OBJPROP_XDISTANCE,frameX);
            ObjectSetInteger(0,PREFIX+"_Label_Op_Show",OBJPROP_XDISTANCE,frameX);
            ObjectSetInteger(0,PREFIX+"_Label_Op_pDDw",OBJPROP_XDISTANCE,frameX);
            ObjectSetInteger(0,PREFIX+"_Label_Op_DDw1",OBJPROP_XDISTANCE,frameX);
            ObjectSetInteger(0,PREFIX+"_Label_Op_DDw2",OBJPROP_XDISTANCE,frameX);
            ObjectSetInteger(0,PREFIX+"_Label_Op_HiLo",OBJPROP_XDISTANCE,frameX);
//            if (sparam == PREFIX+"_Label_Show") 
               ObjectSetInteger(0,PREFIX+"_Label_Show",OBJPROP_XDISTANCE,frameX);
            ObjectSetInteger(0,PREFIX+"_Label_Show-EA",OBJPROP_XDISTANCE,frameX);
            ObjectSetInteger(0,PREFIX+"_Label_||",OBJPROP_XDISTANCE,frameX -14);
            ObjectSetInteger(0,sparam,OBJPROP_XDISTANCE,frameX -18);
            ObjectSetInteger(0,PREFIX+"_Label_Op_OHL",OBJPROP_YDISTANCE,frameY);
            ObjectSetInteger(0,PREFIX+"_Label_Op_Show",OBJPROP_YDISTANCE,frameY+15);
            ObjectSetInteger(0,PREFIX+"_Label_Op_pDDw",OBJPROP_YDISTANCE,frameY+30);
            ObjectSetInteger(0,PREFIX+"_Label_Op_DDw1",OBJPROP_YDISTANCE,frameY+45);
            ObjectSetInteger(0,PREFIX+"_Label_Op_DDw2",OBJPROP_YDISTANCE,frameY+60);
            ObjectSetInteger(0,PREFIX+"_Label_Op_HiLo",OBJPROP_YDISTANCE,frameY+75);
//            if (sparam == PREFIX+"_Label_Show") 
               ObjectSetInteger(0,PREFIX+"_Label_Show",OBJPROP_YDISTANCE,frameY);
            ObjectSetInteger(0,PREFIX+"_Label_Show-EA",OBJPROP_YDISTANCE,frameY);
            ObjectSetInteger(0,PREFIX+"_Label_||",OBJPROP_YDISTANCE,frameY +13);
            ObjectSetInteger(0,sparam,OBJPROP_YDISTANCE,frameY +1);
            GlobalVariableSet("frameX", frameX);   GlobalVariableSet("frameY", frameY); }
   }

   else if (Op_ShwB) { datetime ev_Tim1, ev_Tim2;    double ev_Price;    int i;
      ChartXYToTimePrice(0,lparam,dparam, i, ev_Tim1, ev_Price);
      while (ev_Tim1 > ev_Tim2 && i < Bars) { ev_Tim2 = iTime(NULL,0,Bars-(i+1));   i ++; }
      if ((iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i)) > 0) Print("*** ",(Bars-i)," - ",
      iOpen(NULL,0,Bars-i)," - ",iHigh(NULL,0,Bars-i)," - ",iLow(NULL,0,Bars-i)," - ",iClose(NULL,0,Bars-i)," - ",
         ((MathAbs((iClose(NULL,0,Bars-i)-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i)))
         > 0.3 && ((iOpen(NULL,0,Bars-i) - (iHigh(NULL,0,Bars-i)+iLow(NULL,0,Bars-i)) / 2) > 20 * Point ||
         MathAbs((iClose(NULL,0,Bars-i)-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i))) > 0.75)) ||
         ((iClose(NULL,0,Bars-i) - iOpen(NULL,0,Bars-i)) > 20 * Point && 
         (iOpen(NULL,0,Bars-i) - (iHigh(NULL,0,Bars-i)+iLow(NULL,0,Bars-i)) / 2) > 20 * Point &&
         (iOpen(NULL,0,Bars-i) - (iOpen(NULL,0,Bars-i+1)+iClose(NULL,0,Bars-i+1)) / 2) > 20 * Point &&
         MathAbs((iClose(NULL,0,Bars-i)-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i))) < 0.3)),
      " - ",MathAbs(((iClose(NULL,0,Bars-i)-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i))) > 0.3 && 
         ((iOpen(NULL,0,Bars-i) - (iHigh(NULL,0,Bars-i)+iLow(NULL,0,Bars-i)) / 2) > 20 * Point ||
         MathAbs((iClose(NULL,0,Bars-i)-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i))) > 0.75)),
      " - ",((iClose(NULL,0,Bars-i) - iOpen(NULL,0,Bars-i)) > 20 * Point && 
         (iOpen(NULL,0,Bars-i) - (iHigh(NULL,0,Bars-i)+iLow(NULL,0,Bars-i)) / 2) > 20 * Point &&
         (iOpen(NULL,0,Bars-i) - (iOpen(NULL,0,Bars-i+1)+iClose(NULL,0,Bars-i+1)) / 2) > 20 * Point &&
         MathAbs((iClose(NULL,0,Bars-i)-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i))) < 0.3),
      " - ",MathAbs((iClose(NULL,0,Bars-i)-iOpen(NULL,0,Bars-i)) / (iHigh(NULL,0,Bars-i)-iLow(NULL,0,Bars-i))),
      " - ",(iOpen(NULL,0,Bars-i) - (iHigh(NULL,0,Bars-i)+iLow(NULL,0,Bars-i)) / 2),
      " - ",(iOpen(NULL,0,Bars-i) - (iOpen(NULL,0,Bars-i+1)+iClose(NULL,0,Bars-i+1)) / 2),
      " - ",(iClose(NULL,0,Bars-i) - iOpen(NULL,0,Bars-i))," ***");
   }
}

void CreateButton(double LinePrice,int BarNum,string vText,int Item,int mX,int mY,int Color) {
   string LabelName = PREFIX+"_Label_"+StringSubstr(vText,0,7);
   ObjectCreate(LabelName,OBJ_LABEL,0,0,0);           int vX, vY;
   if (BarNum && LinePrice) ChartTimePriceToXY(0,0,Time[BarNum],LinePrice,vX,vY);
   ObjectSet(LabelName,OBJPROP_XDISTANCE,mX? mX: vX);
   ObjectSet(LabelName,OBJPROP_YDISTANCE,mY? mY: vY);
   ObjectSet(LabelName,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSet(LabelName,OBJPROP_ANCHOR,ANCHOR_LEFT);
   ObjectSetString(0,LabelName,OBJPROP_TEXT,vText);
   ObjectSet(LabelName,OBJPROP_FONTSIZE, Item? 9: 10);
   ObjectSet(LabelName,OBJPROP_COLOR, Color? Color==1 && Op_OHL? clrAqua: Color==2 && Op_Show? clrAqua: Color==3 && Op_DDw? 
      clrAqua: Color==4 && Op_DDw2? clrAqua: Color==5 && Op_DDw3? clrAqua: Color==6 && Op_HiLo? clrAqua: clrSilver: clrSkyBlue);
   ObjectSet(LabelName,OBJPROP_SELECTABLE, true);
   ObjectSet(LabelName,OBJPROP_SELECTED, false);
   ObjectSet(LabelName,OBJPROP_HIDDEN, true);
}
