What have i done wrong ?
The easiest way to find out is to find your rectangle in the list of objects and check its properties
Toyuu:
So, i made this code and it does't throw any errors, but i don't see any rectangle on my chart.
What have i done wrong ?
Return value of the ObjectCreate(); function is boolen. either true or false. the issue contains in your if statement. put this code into chart and you will see.
int OnInit() { double High1 = iHigh(NULL,PERIOD_CURRENT,1); double Low1 = iLow(NULL,PERIOD_CURRENT,1); datetime Start = iTime(NULL,PERIOD_CURRENT,1); datetime End = iTime(NULL,PERIOD_CURRENT,1) + 60*60*24; // add a one day to the 15 min candle open price ObjectDelete(0,"Rectangle"); // delete the old one to avoid over creating. bool Created = ObjectCreate(0,"Rectangle",OBJ_RECTANGLE,0,Start,High1,End,Low1); if(Created == true) { ObjectSetInteger(0,"Rectangle",OBJPROP_BACK,1); // set to the background ObjectSetInteger(0,"Rectangle",OBJPROP_COLOR,clrWhite); Print("Object Rectangle has created"); } else { Print(GetLastError()); // prints the last error. ResetLastError(); // reset the last error is nessery. } return (INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectDelete(0,"Rectangle"); // clears the chart. }
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- A new tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
thanks for the information, bro, it's Technically true. but in this case just put it into a fully loaded chart.
Well, i checked all that, and now i see that the Rectangle is drawn, but on the wrong chart.
But why is that ? It always create it on the AUDCAD 1H chart, but i want it on the WS30 15M chart (which is the chart in which the code is running on).
bool rectangleCreated = ObjectCreate(0, "GapRectangle", OBJ_RECTANGLE, 0, startTime, startY, endTime, endY);
Well, thanks for your help.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
What have i done wrong ?