Lines not drawing on MQL5
Another thing to note: it seems as if the PP line also isn't removed when I remove the indicator. I'm probably missing something very obvious there but, again, any and all help is very much appreciated.
-
double lineHandleS1 = ObjectCreate(4, PivotLineName, OBJ_HLINE, 0, 0, S1Calculation); if(lineHandleS1 == INVALID_HANDLE) { Print("S1 line error: Invalid Handle."); } ObjectSetInteger(4, PivotLineName, OBJPROP_COLOR, indicator_color5); ObjectSetInteger(4, PivotLineName, OBJPROP_STYLE, indicator_style5); ObjectSetInteger(4, PivotLineName, OBJPROP_WIDTH, indicator_width5); Alert("S1 Line:" + ((2 * PivotCalculation) - price_high)); // Draw S2 line PivotLineName = "S2"; double lineHandleS2 = ObjectCreate(5, PivotLineName, OBJ_HLINE, 0, 0, S2Calculation);
ObjectCreate does not create a handle. ObjectCreate does not return a double. - 4 or 5 are not valid chart IDs.
- Object names must be unique.
-
int OnInit() { Alert("NEW DEBUG!"); double price_high = iHigh(_Symbol, _Period, 0); double price_low = iLow(_Symbol, _Period, 0);
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 your feedback! I have a few questions:
- Instead of using ObjectCreate, what should I use instead?
- Why are 4 and 5 not valid chart IDs? Is there a fixed limit?
- Can I reinitialize variables like this?
use int test = 1;
test = 2? - I am putting the code in OnCalculate but I'm concerned that it will simply generate moving lines that moves with the chart. I don't want this, I simply want to draw them as if they were lines I would put in manually. Am I worrying over nothing?
Thanks for helping me, I can understand it's frustrating!
Nevermind, when rewriting the code most of these issues were ironed out!
Thank you very much for the help.

You are missing trading opportunities:
- Free trading apps
- Free Forex VPS for 24 hours
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hey everyone, I'm coding some Pivot Points for MetaTrader5 but I'm having trouble drawing the lines.
The plan is to draw 7 horizontal lines (PP, R1, S1 etc.) however only the PP line is actually being placed on the chart.
I've attached the file below. Any and all help is appreciated!