//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+void handleButtonClicks() { if(ObjectGetInteger(ChartID(), buttonId, OBJPROP_STATE)) { ObjectSetInteger(ChartID(), buttonId, OBJPROP_STATE, false); show_data = !show_data; GlobalVariableSet(IndicatorName + "_visibility", show_data ? 1.0 : 0.0); recalc = true; start(); } }//+------------------------------------------------------------------------------------------------------------------+void OnChartEvent(const int id, //don't change anything here const long &lparam, const double &dparam, const string &sparam) { handleButtonClicks(); }//+------------------------------------------------------------------------------------------------------------------+string GetButtonState(string whichbutton) { bool selected = ObjectGetInteger(ChartID(),whichbutton,OBJPROP_STATE); if(selected) { return ("on"); } else { return ("off"); } }//+------------------------------------------------------------------------------------------------------------------+int start() { handleButtonClicks(); recalc = false; int xshift=0, nxshift=0; if(Corner==CORNER_RIGHT_LOWER || Corner==CORNER_RIGHT_UPPER) { xshift=49; nxshift=66; } for(int i = 0; i < cpairsLen; i++) ButtonCreate2(ChartID(),UniqueID+"t"+(string)i,Window,XShift+nxshift+2,YShift+30+i*15,66,14,Corner,cpairs,"Arial",9,TextColor,BorderColor,FillColor); for(int i = 0; i < ctimesLen; i++) ButtonCreate2(ChartID(),UniqueID+"h"+(string)i,Window,XShift+xshift+i*50+69,YShift+15,49,14,Corner,timeFrameToString(aTimes),"Arial",9,TextColor,BorderColor,FillColor); for(int i = 0; i < cpairsLen; i++) if(iClose(cpairs,0,0)!=0) for(int t = 0; t < ctimesLen; t++) { double value = iStochastic(cpairs,aTimes[t],StoPeriod,1,StoSmoothing,MODE_SMA,Price,MODE_MAIN,BarToTest); int step = (int)((ColorSteps-1)*(MathMax(MathMin(value,lStrongUp),lStrongDown)-lStrongDown)/(lStrongUp-lStrongDown)); color theColor = colors[ColorSteps-step-1]; ButtonCreate2(ChartID(),UniqueID+(string)t+(string)i,Window,XShift+xshift+t*50+69,YShift+30+i*15,49,14,Corner," ","arial",10,theColor,BorderColor,theColor); } if(Corner==CORNER_RIGHT_UPPER || Corner==CORNER_RIGHT_LOWER) ButtonCreate2(ChartID(),UniqueID+"title",Window,XShift+xshift+ctimesLen*50+19,YShift+30+cpairsLen*15,ctimesLen*50-1,14,Corner," Stochastic ("+(string)StoPeriod+","+(string)StoSmoothing+")","arial",10,TextColor,BorderColor,FillColor); else ButtonCreate2(ChartID(),UniqueID+"title",Window,XShift+xshift+69,YShift+30+cpairsLen*15,ctimesLen*50-1,14,Corner," Stochastic ("+(string)StoPeriod+","+(string)StoSmoothing+")","arial",10,TextColor,BorderColor,FillColor);
if(!show_data) { ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_OFF_color); int idLength = StringLen(UniqueID); for(int i = ObjectsTotal(); i>=0; i--) { string name = ObjectName(i); if(StringSubstr(name,0,idLength) == UniqueID) ObjectDelete(name); } } else ObjectSetInteger(ChartID(),buttonId,OBJPROP_COLOR,btn_text_ON_color);
return(0); }//+------------------------------------------------------------------------------------------------------------------+bool ButtonCreate2(const long chart_ID=0, // chart's ID const string name="Button", // button name const int sub_window=0, // subwindow index const int x=0, // X coordinate const int y=0, // Y coordinate const int width=50, // button width const int height=18, // button height const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring const string text="Button", // text const string font="Arial", // font const int font_size=10, // font size const color clr=clrBlack, // text color const color clrBorder=clrBlack, // border color const color back_clr=clrGray, // background color const bool state=true, // pressed/released 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) // priority for mouse click { ObjectCreate(chart_ID,name,OBJ_BUTTON,sub_window,0,0); ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width); ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height); ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,back_clr); ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_COLOR,clrBorder); ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,BORDER_FLAT); ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); ObjectSetString(chart_ID,name,OBJPROP_FONT,font); return(true); }