I am trying to print the high of a bar 10 points above the high of the bar for last n bars.
Here is my code. I am not getting this to work. Can somebody please help me with this.
I am using X=High[a] as an example here. What I want to do is to print a value(integer type).
Please help. Thanks in Advance.
I have no idea as to how to do it. Can you please help me with it?
- All names must be unique.
You can't use an as-series index in names as they are not unique. As soon as a new bar starts, you will be trying to create a new name (e.g. "name0",) same, existing, previous, name (e.g. "name0" now on bar one.)
Use time (as int) or a non-series index:
#define SERIES(I) (Bars - 1 - I) // As-series to non-series or back.
-
Place the object above the candle. Not above the current candle.
- Brijesh Kuttan: I have no idea as to how to do it. Can you please help me with it?
Perhaps you should read the manual. OBJ_TEXT
How To Ask Questions The Smart Way. 2004
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up. -
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help 2017.04.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12
I have no idea as to how to do it. Can you please help me with it?
like data + a, dont forget to typecast
like data + a, dont forget to typecast
{ Vertical_Offset= Point*20; ObjectCreate("data"+a, OBJ_TEXT, 0, Time[a], High[a]+ Vertical_Offset); ObjectSetText("data"+a,DoubleToStr(X),10,"Times New Roman", Red); ObjectSet("data"+a,OBJPROP_ANGLE,90); }
I did this and it gives me the required output. Thanks
I did this and it gives me the required output. Thanks
please follow William's advice..you'll avoid future problem..use time as data name concatenation
Made a few changes.
Here is my latest code.
//+------------------------------------------------------------------+ //| | //| 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" #property strict #property indicator_chart_window //#property indicator_separate_window //sub window extern int BarsToProcess = 10; double X; double Vertical_Offset; string Horizontal_Offset; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- return(0); } //-------------------------------------------- int deinit() { //---- ObjectsDeleteAll(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); Comment(" \n Print High above High"); //---- if (IsthisANewCandle()) { ObjectsDeleteAll(); pastdata(); }
//---- return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void pastdata() { for(int a=BarsToProcess; a>=1; a--) { X = High[a]; if(X!=15) { Vertical_Offset= Point*20; ObjectCreate("data"+a, OBJ_TEXT, 0, Time[a], High[a]+ Vertical_Offset); ObjectSetText("data"+a,DoubleToStr(X),10,"Times New Roman", Red); ObjectSet("data"+a,OBJPROP_ANGLE,90); } } } //+------------------------------------------------------------------+ bool IsthisANewCandle() { static int BarsOnChart = 0; if (Bars == BarsOnChart) return(false); BarsOnChart = Bars; return(true); }
- All names must be unique.
-
Place the object above the candle. Not above the current candle.
-
Perhaps you should read the manual. OBJ_TEXT
How To Ask Questions The Smart Way. 2004
How To Interpret Answers.
RTFM and STFW: How To Tell You've Seriously Screwed Up. -
Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your problem.
No free help 2017.04.21Or pay someone. Top of every page is the link Freelance.
Hiring to write script - General - MQL5 programming forum 2018.05.12
Thank You for your reply. Sardion too is suggesting me to follow your advice. However, I am an amateur programmer.
So I am finding it difficult to understand what you are saying. But, I will go through what you have said.
Thank You,
- Brijesh Kuttan: I did this and it gives me the required output. Thanks
Not if you call original code a second time. Ignored #3.1 and #7
-
Use of ObjectsDeleteAll is not recommended. Your code should only delete what it creates. This will likely create problems for you in the future.
-
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
New candle - MQL4 programming forum #3 2014.04.04I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum 2011.05.06

- 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 am trying to print the high of a bar 10 points above the high of the bar for last n bars.
Here is my code. I am not getting this to work. Can somebody please help me with this.
I am using X=High[a] as an example here. What I want to do is to print a value(integer type).
Please help. Thanks in Advance.