-
double tickValue=MarketInfo(_Symbol,MODE_TICKVALUE); double ask = SymbolInfoDouble(symbol,SYMBOL_ASK);
Your posted code is without context. Are these lines inside a function or global? Why are other lines indented?
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problemIf they are outside, then those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and 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.
-
Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum #2 (2013)
-
-
for (int i = 0; i <= limit; i++) name = "Red-" + TimeToStr(Time[i], TIME_DATE|TIME_MINUTES); length = DoubleToStr(((ask-iOpen("GBPUSD",0,i))*10000)0);
Why are you repeatedly assigning to name? What do you expect length to be, when it is after the loop?
-
Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.
-
int counted_bars = IndicatorCounted(); if (counted_bars > 0) counted_bars--; int limit = Bars - counted_bars; if (limit > 6000) limit = 6000;
You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)See How to do your lookbacks correctly #9 — #14 & #19. (2016)
-
Your posted code is without context. Are these lines inside a function or global? Why are other lines indented?
How To Ask Questions The Smart Way. (2004)
Be precise and informative about your problemIf they are outside, then those are not assignments; they are initialization of a common (globally declared), or static variable with a constant. They work exactly the same way in MT4/MT5/C/C++.
-
They are initialized once on program load.
-
They don't update unless you assign to them.
-
In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants. There is no default in MT5, or MT4 with strict (which you should always use).
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and 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.
-
Unlike indicators, EAs are not reloaded on chart change, so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum #2 (2013)
-
-
Why are you repeatedly assigning to name? What do you expect length to be, when it is after the loop?
-
Always use strict. Fixing the warnings will save you hours of debugging, but you must understand the differences.
-
You should stop using the old event handlers (init, start, deinit) and IndicatorCounted() and start using new event handlers (OnInit, OnTick/OnCalculate, OnDeinit).
Event Handling Functions - MQL4 Reference
How to do your lookbacks correctly - MQL4 programming forum #9-14 & #19 (2016)See How to do your lookbacks correctly #9 — #14 & #19. (2016)
thank you a lot for the reply. what is the reason why new event handlers are used? (oninit,ontick,oncalculate,ondeinit) ? that is confusing to me, but i am sure it must have a reason.
what i expect length to be, is on the screen above the bar it should give a number that gets updated, but at the moment it is static. but as you explained above i understand it now, i basically assign a string to a text and it gets added, but it does not update. but why is that? should i otherwise upload the whole indicator so far i made? i just thought i use a small part of it. so it is easier to understand?
but when i do
length = DoubleToStr(((ask-iOpen("GBPUSD",0,i))*10000)0);
it is static, but when i do
length = DoubleToStr((((iClose("GBPUSD",0,i))-iOpen("GBPUSD",0,i))*10000),0);
then it does update.
but as i understand from your post that happens because i use
string symbol = "EURUSD"; double ask = SymbolInfoDouble(symbol,SYMBOL_ASK);
so my question is how can i fix that? hopefully it is something small. otherwise i need to rewrite the indicator. thanks
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use