Sudha365:
Do not double post!
I have deleted your other post.
In future please post in the correct section.
I will move this to the MQL4 and MT4 section
Keith Watford:
Do not double post!
I have deleted your other post.
In future please post in the correct section.
I will move this to the MQL4 and MT4 section
Sudha365: I have tried to store the last cross signal value in "static double"
under void OnTick(void), BUT ITS NOT changing when +DI and-DI crosses next time. And the code I have tried is below. Help please
Global and static variables work exactly the same way in MT4/MT5/C/C++.
static double lastsignal =adxSig();
- 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 server related functions in OnInit (or on load,) 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.
- 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
William Roeder:
Global and static variables work exactly the same way in MT4/MT5/C/C++.
Global and static variables work exactly the same way in MT4/MT5/C/C++.
- Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
external static variable - MQL4 programming forum
int init(){ OnInitFunction(); OnInitFunction2 .. : } TYPE functionVariable; void OnInitFunction(){ functionVariable = 0; } TYPE Function(){ if (functionVariable == 0){ functionVariable = ...Thank you. I have copied and pasted your above code from other question.
Still , it is hard for me to follow or convert this into a workable solution. Could you please let me know how to simplyfy this ?
Sudha365: Could you please let me know how to simplyfy this
?
I gave you a template. Only you know what you need. That is a simple as possible without specifics.-
MT4: Learn to code it.
MT5: Begin learning to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours. - or pay (Freelance) someone to code it.
Hiring to write script - General - MQL5 programming forum
No free help
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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 using ADX cross EA. At the moment it buys and sells only when +DI and -DI crosses. Could someone please help as below
If No trades exist
then place trade based on LAST +Di and -DI cross.
I have tried to store the last cross signal value in "static double" under void OnTick(void), BUT ITS NOT changing when +DI and-DI crosses next time. And the code I have tried is below. Help please