expert advisor - miscellaneous questions - page 5

 

I need a bit more clearly explanation about the 'GlobalVariable Functions' which one how can I use it. 
I already read documentation.

( if would be example that would be awesome ) 

Thanks in advance.

 
Max Enrik:

I need a bit more clearly explanation about the 'GlobalVariable Functions' which one how can I use it. 
I already read documentation.

( if would be example that would be awesome ) 

Thanks in advance.

The documentation is quite self explanatory regarding this.

Use them in the same way as globally declared variables when you need a value retained after an EA or indicator has been removed or the terminal is shut down or timeframe changed on the chart to which an indicator is attached.

The most important thing is to make sure that they are given individual names. You could use magic number and Symbol in the name. It could cause problems if more than 1 EA or indicator were trying to access and change the same Global Variable (of the client terminal).

 
Max Enrik:

I need a bit more clearly explanation about the 'GlobalVariable Functions' which one how can I use it. 
I already read documentation.

( if would be example that would be awesome ) 

Thanks in advance.


Article for mql5, but it works the same with mql4.
MQL5 Programming Basics: Global Variables of the Terminal
MQL5 Programming Basics: Global Variables of the Terminal
  • 2016.11.25
  • Dmitry Fedoseev
  • www.mql5.com
Global variables of the terminal provide an indispensable tool for developing sophisticated and reliable Expert Advisors. If you master the global variables, you will no more be able to imagine developing EAs on MQL5 without them.
 
Keith Watford:

The documentation is quite self explanatory regarding this.
... 

Alain Verleyen:

Article for mql5, but it works the same with mql4.

Big thanks for more informative comments.

And I try like below code but I do not get good result. So I try to terminal would save my latest changes.
e.g: Default Lot Size is 0.01 after I changed Lot Size then I change TimeFrames - Lot Size turn to Default.
Please, help me or give me good (clearly) advice!

Thanks in advance.

//Global Variables
string  _lotGV;

//-----------------------------------------------------------------------------

int OnInit()
{
    //Global Variables

    _lotGV = _prefix + _Symbol + " _lotGV";
  
    if ( GlobalVariableCheck( _lotGV ) == true )
    {
        GlobalVariableGet( _lotGV );
    }   //---if Close
    else
    {
        GlobalVariableSet( _lotGV, _lotSize );
    }
}
 

#GlobalVariable - Closed

I solved like below code.

//--------------------------------------------

_lotGV = _prefix + _Symbol + " _lotGV";

if ( GlobalVariableCheck( _lotGV ) == true )
{
    _lotSize = GlobalVariableGet( _lotGV );
}   //---if Close
else
{
    GlobalVariableSet( _lotGV, _lotSize );
}
Special thanks to @Alain Verleyen @Keith Watford
 

#Lot Reset - Open

I have not any idea about 'Lot Reset' Button. some describe: And I need to when I click reset button lot size turn to default lot size value. ( e.g lot size value 1 )
So, I need good advice with example.

( also I am still researching )

All the best to you.

 

I am really struggle, someone please help me.

Thanks. 

 
Max Enrik:

#Lot Reset - Open

I have not any idea about 'Lot Reset' Button. some describe: And I need to when I click reset button lot size turn to default lot size value. ( e.g lot size value 1 )
So, I need good advice with example.

( also I am still researching )

All the best to you.

It may help if you describe what you are referring to.
 
if(sparam=="reset")
{
  Lotsize=0.01;
}
 
Marco vd Heijden:
if(sparam=="reset")
{
  Lotsize=0.01;
}

You clearly understand me, thank you great man, much appreciate.
( it is simple, but sometimes I struggle.. )

Reason: