//+------------------------------------------------------------------+ //| iSymbol.mq5 | //| Copyright 2012, iC | //| http://icreator.biz/ | //+------------------------------------------------------------------+ #property copyright "Copyright 2012, iC" #property link "http://icreator.biz/" #property version "0.10" #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 1 #property indicator_type1 DRAW_BARS #property indicator_color1 clrCrimson //+-------------------------------------------------------- enums ---+ enum CYesNo { Yes=-1,No=1 }; //+------------------------------------------------------- inputs ---+ input string _InpInst="EURUSD"; // Symbol input CYesNo _InpInvert=No; // Invert input CYesNo _InpScale=No; // Scale fix string _Inst; CYesNo _Invert=No; CYesNo _ScaleFix=No; //+------------------------------------------------------ defines ---+ const int REDRAW=0; const string TC=IntegerToString(GetTickCount()); const string OBJ_NAME="PriceDiffLabel"+TC; const string OBJ_INVERT="ObjInvert"+TC; const string OBJ_SCALE="ObjScale"+TC; const string OBJ_INST="ObjSymbol"+TC; const string OBJ_INST_TIP="ObjSymbolTip"+TC; const string OBJ_FREEZE="ObjFreeze"+TC; const string OBJ_BACK="ObjBackgroung"+TC; const string OBJ_BACK2="ObjBack2"+TC; const string WH=IntegerToString(ChartGetInteger(0,CHART_WINDOW_HANDLE)); const string COUNT="Count"+WH; const string POSITION="Position"+WH; //+--------------------------------------------- global variables ---+ double OBuf[],HBuf[],LBuf[],CBuf[]; CYesNo _freeze=No; datetime _startTime=0; datetime _endTime=0; int _lastChoose=0; int _first,_count; string names[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { SetIndexBuffer(0,OBuf,INDICATOR_DATA); SetIndexBuffer(1,HBuf,INDICATOR_DATA); SetIndexBuffer(2,LBuf,INDICATOR_DATA); SetIndexBuffer(3,CBuf,INDICATOR_DATA); IndicatorSetInteger(INDICATOR_DIGITS,_Digits); PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0); if(!SymbolSelect(_InpInst,true)) { Print("Wrong symbol."); return -1; } _Inst=_InpInst; _Invert=_InpInvert; _ScaleFix=_InpScale; GlobalVariableSet(COUNT,GlobalVariableGet(COUNT)+1); GlobalVariableSet(POSITION,0); ObjCreate(); EventChartCustom(0,0,0,0,NULL); return 0; } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { ObjectDelete(0,OBJ_INVERT); ObjectDelete(0,OBJ_FREEZE); ObjectDelete(0,OBJ_SCALE); ObjectDelete(0,OBJ_INST); ObjectDelete(0,OBJ_INST_TIP); ObjectDelete(0,OBJ_BACK); ObjectDelete(0,OBJ_BACK2); if(GlobalVariableGet(COUNT)==1) GlobalVariableDel(COUNT); else GlobalVariableSet(COUNT,GlobalVariableGet(COUNT)-1); GlobalVariableDel(POSITION); EventChartCustom(0,0,0,0,NULL); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &in[]) { _Invert=CYesNo(ObjectGetInteger(0,OBJ_INVERT,OBJPROP_STATE)==0?1:-1); _ScaleFix=CYesNo(ObjectGetInteger(0,OBJ_SCALE,OBJPROP_STATE)==0?1:-1); _freeze=CYesNo(ObjectGetInteger(0,OBJ_FREEZE,OBJPROP_STATE)==0?1:-1); _Inst=ObjectGetString(0,OBJ_INST,OBJPROP_TEXT); ObjectSetInteger(0,OBJ_BACK,OBJPROP_BGCOLOR,PlotIndexGetInteger(0,PLOT_LINE_COLOR)); if(_freeze==No) { int first=(int)ChartGetInteger(0,CHART_FIRST_VISIBLE_BAR); int count=(int)ChartGetInteger(0,CHART_VISIBLE_BARS); if(count-1>first) return 0; _first=first; _count=count; } else if(_freeze==Yes) { if(_lastChoose!=No) _first=_first+_first+1-_count; _count=_first+1; } _lastChoose=_freeze; if(in[0]!=EMPTY_VALUE) { if(_ScaleFix==Yes) ChartSetInteger(0,CHART_SCALEFIX,0,true); else ChartSetInteger(0,CHART_SCALEFIX,0,false); } else if(in[2]!=EMPTY_VALUE) { if(_freeze==Yes) { ObjectSetInteger(0,OBJ_FREEZE,OBJPROP_STATE,true); ArrayInitialize(OBuf,0.0); ArrayInitialize(HBuf,0.0); ArrayInitialize(LBuf,0.0); ArrayInitialize(CBuf,0.0); } else ObjectSetInteger(0,OBJ_FREEZE,OBJPROP_STATE,false); } else if(in[1]==EMPTY_VALUE && in[3]==EMPTY_VALUE && in[4]==EMPTY_VALUE) return rates_total; double d=0; double tick_size=SymbolInfoDouble(_Inst,SYMBOL_POINT); double tick_size2=SymbolInfoDouble(_Symbol,SYMBOL_POINT); double min=DBL_MAX,max=0; double lOp=0; int cnt=-1; datetime prevTime=0; datetime time[]; double high[],low[]; double open[1]; MqlRates rt[1]; CopyOpen(_Symbol,0,_first,1,open); CopyTime(_Symbol,0,_first-_count+1,_count,time); CopyHigh(_Symbol,0,_first-_count+1,_count,high); CopyLow(_Symbol,0,_first-_count+1,_count,low); for(int i=rates_total-_first-1;i0) d+=(rt[0].open-lOp)*_Invert/tick_size*tick_size2; lOp=rt[0].open; OBuf[i]=open[0]; HBuf[i]=open[0]; LBuf[i]=open[0]; CBuf[i]=open[0]; if(prevTime!=0) { OBuf[i]+=d; HBuf[i]+=d+(rt[0].high-rt[0].open)*_Invert/tick_size*tick_size2; LBuf[i]+=d+(rt[0].low-rt[0].open)*_Invert/tick_size*tick_size2; CBuf[i]+=d+(rt[0].close-rt[0].open)*_Invert/tick_size*tick_size2; } prevTime=rt[0].time; if(high[cnt]>max) max=high[cnt]; if(HBuf[i]>max) max=HBuf[i]; if(LBuf[i]>max) max=LBuf[i]; if(low[cnt]250) { lastTime=GetTickCount(); return; } else { arr[2]=(double)ObjectGetInteger(0,OBJ_FREEZE,OBJPROP_STATE); for(int i=0;i