Code:
//+------------------------------------------------------------------+ //| Script 1.mq5 | //| Copyright 2020, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2020, MetaQuotes Software Corp." #property link "https://www.mql5.com" #property version "1.00" //--- //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { Print(CalculateHLines()); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int CalculateHLines(void) { int count_hlines=0; for(int i=ObjectsTotal(ChartID(),0,OBJ_HLINE)-1; i>=0; i--) count_hlines++; //--- return(count_hlines); } //+------------------------------------------------------------------+
Files:
Script_1.mq5
3 kb
Vladimir Karputov:
Code:
Thank you very much sir. If I may ask, are there any books on MQL programming for MQL4 or 5? Besides the MQL documentation.
sir7williams :
Thank you very much sir. If I may ask, are there any books on MQL programming for MQL4 or 5? Besides the MQL documentation.
MQL5.com is the largest information repository. Use Documentation, Articles, Forum and CodeBade for learning.
Posted code | int count_hlines=0; for(int i=ObjectsTotal(ChartID(),0,OBJ_HLINE)-1; i>=0; i--) count_hlines++; |
Simplified | int count_hlines=ObjectsTotal(ChartID(),0,OBJ_HLINE); |
You are missing trading opportunities:
- Free trading apps
- 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
Hi. I am trying to follow a function that calculates number of buy Positions that works properly, and create a function that will calculate number of HLINE objects i have on my main screen on the current chart. But I fail to get it right.
On this one, I tried to
1. Loop through all the objects on the current symbol
2. Get the type of all the objects
3. If the type of the object is HLINE, i add 1 to a variable "numberofhlines" to get the number of HLINEs.
4. I then return the value of those HLINES. But the problem here is, i get '543 155 680' instead of the number of HLINEs i have on the screen. Please help.