-
Why did you post your question in the MT5 General section (a catch all category) instead of the MT5 EA section (non-indicator codeing)?
General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
Next time, post in the correct place. I have moved this thread. -
You do understand that scripts only run once?
-
high = iHigh(_Symbol, PERIOD_D1, i); low = iLow(_Symbol, PERIOD_D1, i);
On MT5: Unless the current chart is that specific pair/TF, you must synchronize the terminal Data from the Server before accessing candle/indicator values.
Error 4806 while using CopyBuffer() - Expert Advisors and Automated Trading - MQL5 programming forum #10 (2020)
Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum (2019)
Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum #2 (2018)
SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum (2019) -
Your loop (i) is the current chart's bars, yet you are using it to access D1 bars. You are mixing apples and oranges.
- You are drawing all bars, but there can be only one object named “High Line”.
Hi
As was mentioned above, script runs only one time so it displays the lines and remove itself from the chart, it won’t update itself along with new candles on new day. If you want it to work constantly make it as an indicator or EA and to make it work, use daily period for getting the data in all elements. Also you cannot use horizontal line if you want to set start and end time for the line. Use trendline instead: Try something like this:
double high, low, range, P_25, P_50, P_75; int bars = iBars(_Symbol, PERIOD_D1); for(int i = 1; i<bars; i++) { high = iHigh(_Symbol, PERIOD_D1, i); low = iLow(_Symbol, PERIOD_D1, i); range = ((high-low)/_Point); P_25 = low + (range * (25/100)); P_50 = low + (range * (50/100)); P_75 = low + (range * (75/100)); datetime startOfDay = TimeCurrent() - (TimeCurrent() % 86400); datetime endOfDay = startOfDay + 86400 - 1; // 86400 seconds in a day ObjectCreate(0, "High Line", OBJ_TREND, 0, startOfDay, high, endOfDay, high); ObjectSetInteger(0, "High Line", OBJPROP_COLOR, clrRed); ObjectSetInteger(0, "High Line", OBJPROP_WIDTH, 1); ObjectSetInteger(0, "High Line", OBJPROP_STYLE, STYLE_DASH); ObjectSetInteger(0, "High Line", OBJPROP_RAY_RIGHT, false); }
Have a nice day
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm having some issues with my code that is trying to draw the high, low and 25%, 50% and 75% of the previous day on the current days chart, I would like to see historical data show their values so I can see certain levels. The code I have written seems to flash across the screen and not actually draw the levels out.
Can someone help me out and explain why this isnt working.
Regards