//+------------------------------------------------------------------+ //| RoundLevels.mq4 | //| by Captain Nemo | //| | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 0 extern bool ShowMidLevels=true; extern bool ShowMidLevels_W1=false; extern bool ShowMidLevels_MN1=false; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { DeleteLevels(); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int deinit() { DeleteLevels(); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void DeleteLevels() { int obj_total=ObjectsTotal(); string name; for(int i=obj_total;i>=0;i--) { name=ObjectName(i); if(StringFind(name,"RoundLevel_")!=-1) ObjectDelete(name); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int highestBar=iHighest(NULL,0,WHOLE_ARRAY,0); int lowestBar=iLowest(NULL,0,WHOLE_ARRAY,0); double lowestPrice=Low[lowestBar]; double highestPrice=High[highestBar]; double numOfDigits; double x=MathCeil(highestPrice); if(x/100000>=1) {Alert("Prices >= then 100000 are not supported!");return(0);} if(x/10000>=1) numOfDigits=5; else if(x/1000>=1) numOfDigits=4; else if(x/100>=1) numOfDigits=3; else if(x/10>=1) numOfDigits=2; else if(x>=1) numOfDigits=1; else if(x*10>=1) numOfDigits=-1; else {Alert("Prices lower then 0.1 are not supported!");return(0);} double bottomLine=0,topLine=0,step=0; switch((int)numOfDigits) { case 5: bottomLine=(MathFloor(lowestPrice/1000)*1000); topLine=(MathCeil(highestPrice/1000)*1000); step=1000; break; case 4: bottomLine=(MathFloor(lowestPrice/100)*100); topLine=(MathCeil(highestPrice/100)*100); step=100; break; case 3: bottomLine=(MathFloor(lowestPrice/10)*10); topLine=(MathCeil(highestPrice/10)*10); step=10; break; case 2: bottomLine=MathFloor(lowestPrice); topLine=MathCeil(highestPrice); step=1; break; case 1: bottomLine=(MathFloor(lowestPrice*10)/10); topLine=(MathCeil(highestPrice*10)/10); step=0.1; break; case -1: bottomLine=(MathFloor(lowestPrice*100)/100); topLine=(MathCeil(highestPrice*100)/100); step=0.01; break; } for(double p=bottomLine;p