I think that it is better to create the objects in init and then move them in the main program.
This may give you some ideas to work with
As it draws alternate rectangles, the highest level is missing. You may decide to draw additional rectangles with alternate colours
#property copyright "GumRai" #property link "none" #property version "1.00" #property strict #property indicator_chart_window //--- input parameters input int nLines = 40; //Number of levels to draw input double lineInterval = 0.0010; //Basic Interval between levels input color RCol=clrAquamarine; //Colour string obname="RectLevel"; double step; datetime BarTime=0; int RoundFactor; int halfLines; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { if(Digits==5 || Digits==3) RoundFactor=Digits-2; else RoundFactor=Digits-1; switch(Period()) { case PERIOD_M1: step=lineInterval; break; case PERIOD_M5: step=lineInterval; break; case PERIOD_M15: step=lineInterval; break; case PERIOD_M30: step=lineInterval; break; case PERIOD_H1: step=lineInterval*5; break; case PERIOD_H4: step=lineInterval*10; break; case PERIOD_D1: step=lineInterval*10; break; case PERIOD_W1: step=lineInterval*100; break; case PERIOD_MN1: step=lineInterval*100; break; } halfLines=(int)MathCeil(nLines*0.5); for (int ix = 1; ix <= halfLines; ix++) // Loop span number of times { ObjectCreate(0,obname+(string)ix,OBJ_RECTANGLE,0,0,0,0,0); ObjectSetInteger(0,obname+(string)ix,OBJPROP_COLOR,RCol); } //--- return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { for (int ix = 1; ix <= halfLines; ix++) ObjectDelete(0,obname+(string)ix); } //+------------------------------------------------------------------+ //| 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[]) { if(Time[0]!=BarTime) { BarTime=Time[0]; double normPrice = NormalizeDouble(Close[1],RoundFactor); // Current price is rounded to nearest "10" double first=normPrice-step*halfLines; datetime T2=Time[0]+PeriodSeconds()*100; for (int ix = 1; ix <= halfLines; ix++) { ObjectSet(obname+(string)ix,OBJPROP_PRICE1,first); ObjectSet(obname+(string)ix,OBJPROP_PRICE2,first+step); ObjectSet(obname+(string)ix,OBJPROP_TIME2,T2); first+=step*2; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+
It doesn't exactly draw 10 pips in a round number. It chooses arbitrary...
Wow!
Is that really the way that you respond when somebody takes the time and tries to help you? Complain that it doesn't do exactly as you expect?
It draws at levels rounded to 10 pips on my chart!
This may give you some ideas to work with
Means that it is intended to give you some ideas, not intended as your complete solution.
Oh, I wish it could carry the tone~ with all respect ~ ^_^
Thank you ~ but how can I apply this??? I don't know.
Thank you ~ but how can I apply this??? I don't know.
Read and understand the code
Modify/adapt it to do what you want or use parts of it in your own code
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
It doesn't work. Many errors. What needs to be fixed?
Also, when it goes higher timeframe, I want it to be changed,
===> 1Min ~ 30 Min ==> every 10 pips
===> 1 Hour ======> every 50 pips
===> 4 Hour, Daily ======> every 100 pips
===> Weekly, Monthly ===> every 1000 pips
Any help? Rectangles are desired instead of lines which can cause confusion with Resistance and Support Lines.
Please help, thanks in advance ~