How to Set (by Script), the Long & Short, Only Long or Only Short options, when i run an EA?

 
Hi,

I would like to know if is there a way to Set (by Script) the Long & Short, Only Long or Only Short options, when the EA is loaded...


I tried to do this Saving 3 Templates, each one with one of these options selected (Long & Short, Only Long, Only Short). When i looked in those files, i noticed a difference on the parameter FLAGS, with the values (343 - Long & Short, 342 - Only SHort, and 341 - Only Long)

The problem is, when a use the Template manually, the EA is loaded fine, with the Option set correctly (Long & Short, Only Long or Only Short), according the file. It doesn't matter if the Template was made manually, or using the function ChartSaveTemplate...

But, when a try to load those same templates, using the funcion ChartApplyTemplate, the EA is Loaded, by always using the Long & Short Option set...The parameter FLAGS is ignored...

I need this, because i will have an EA controlling another one... And of course, one of them was not wrote by me...


I'm using MQL4...


Anyone can help me out?

Tks
 

Hello, 

    I am having the same problem. In my templates I use flags=343, in my case after calling ChartApplyTemplate the "Allow Trading" is disabled on the Expert Advisor included on the template, so my system doesn't allow me to trade at all.

    Did you find any solution yet ? Thanks in advanced !!

Regards

Pablo

 
Pablo Ibanez Porcel:

Hello, 

    I am having the same problem. In my templates I use flags=343, in my case after calling ChartApplyTemplate the "Allow Trading" is disabled on the Expert Advisor included on the template, so my system doesn't allow me to trade at all.

    Did you find any solution yet ? Thanks in advanced !!

Regards

Pablo

Hi,

I am also having similar problems and am looking for any code (automated) solution to resolve this...

I can manually or with ChartSaveTemplate properly make a template that contains an EA with its common parameters are set as: position=Long and Short, Enable alerts ticked, Live Trading = Allow live trading, Safety=[Allow DLL imports and Allow import of external experts]. This is saved in the *.tpl file as flags=343.

And when I apply the template (which has also been assigned as the default template) to a chart, either manually to an existing chart or when opening a new chart using the Market Window/Chart Window command (which applies the default template), the EA common parameters are all set CORRECTLY.

However when I try to apply the template using code, either by using ChartOpen (which will apply the default template) or using ChartApplyTemplate (from either the calling chart or the newly created chart), the EA common parameters are set INCORRECTLY. It doesn't matter where these template files reside (e.g. in in a roaming directory \templates \MQL4\Files \MQL4\Indicators \MQL4\Experts or in C:\Program Files\Broker or a directly specified location anywhere on the PC) the EAs common parameters still do not get set properly. And to be clear both the template was created with the EA active for autotrading (smiley face good) and the calling chart's EA had smiley face.

This used to work properly in MT4 as I had been using this code for a long time with a different broker (MT4 Build prior to 1170). However with my current brokers (multiple all using Build 1170), this no longer works and I am forced to manually set the parameter or manually reapply the template which totally breaks the automation...

Any automated suggestions (MQL4, AutoKeys, scripts, dll's, etc) appreciated !
 
albry:

Hi,

I am also having similar problems and am looking for any code (automated) solution to resolve this...

I can manually or with ChartSaveTemplate properly make a template that contains an EA with its common parameters are set as: position=Long and Short, Enable alerts ticked, Live Trading = Allow live trading, Safety=[Allow DLL imports and Allow import of external experts]. This is saved in the *.tpl file as flags=343.

And when I apply the template (which has also been assigned as the default template) to a chart, either manually to an existing chart or when opening a new chart using the Market Window/Chart Window command (which applies the default template), the EA common parameters are all set CORRECTLY.

However when I try to apply the template using code, either by using ChartOpen (which will apply the default template) or using ChartApplyTemplate (from either the calling chart or the newly created chart), the EA common parameters are set INCORRECTLY. It doesn't matter where these template files reside (e.g. in in a roaming directory \templates \MQL4\Files \MQL4\Indicators \MQL4\Experts or in C:\Program Files\Broker or a directly specified location anywhere on the PC) the EAs common parameters still do not get set properly. And to be clear both the template was created with the EA active for autotrading (smiley face good) and the calling chart's EA had smiley face.

This used to work properly in MT4 as I had been using this code for a long time with a different broker (MT4 Build prior to 1170). However with my current brokers (multiple all using Build 1170), this no longer works and I am forced to manually set the parameter or manually reapply the template which totally breaks the automation...

Any automated suggestions (MQL4, AutoKeys, scripts, dll's, etc) appreciated !

On more detailed analysis of this, it appears that the MT4 behavior has been changed (as of Build 1170, possibly earlier) so as to ensure that a program that IS NOT allowed to trade (e.g. an indicator) can not instantiate an EA that IS allowed to trade.

Essentially ChartOpen and ChartApplyTemplate (and possibly other routines) now appear to look at the calling routines trading status (e.g. MQLInfoInteger(MQL_TRADE_ALLOWED)) , and if not allowed, that any EAs that a template (or other MQL4 means?) applies, will have the EAs Common parameters changed to a default (no trade allowed) setting.


So to resolve this, 2 viable solutions are:

 1) move the functionality that calls ChartOpen /ChartApplyTemplate to an EA (or script?) that has MQL_TRADE_ALLOWED trade status.

 2) use WinUser32 routine (PostMessageA/MT4_WMCMD_LOAD_TEMPLATE) to apply a specific template from the roaming \templates folder to the chart, applying the templates saved permissions (e.g. flags=343), and which may be called from any routine including indicators


Although both work (tested), I went with the WinUser32 option,  since it involved a lot less renovations of my code...

Reason: