Automated script to open charts and place EAs

 

Hi


Sorry if a silly question but I'm running multiple EAs in MT4 and find it time consuming to manually open a chart and place the EA on it. Error prone when you are testing 50+ EAs 

I know in a script you can open a chart but can you add an EA to that chart?

Any help much appreciated.

Thanks

 
locactus:

Hi


Sorry if a silly question but I'm running multiple EAs in MT4 and find it time consuming to manually open a chart and place the EA on it. Error prone when you are testing 50+ EAs 

I know in a script you can open a chart but can you add an EA to that chart?

Any help much appreciated.

Thanks

I haven't tried this, but there is a function ChartApplyTemplate() in MT4.

https://docs.mql4.com/chart_operations/chartapplytemplate

As long as your template is the same name as your EA, the template should automatically load the EA when invoked.

Of course, by "same name" I mean same name, appropriate extension, e.g.  ABC.tpl -- ABC.mq4

ChartApplyTemplate - Chart Operations - MQL4 Reference
ChartApplyTemplate - Chart Operations - MQL4 Reference
  • docs.mql4.com
Applies a specific template from a specified file to the chart. The command is added to chart message queue and executed only after all previous commands have been processed. The Expert Advisor will be unloaded and will not be able to continue operating in case of successful loading of a new template to the chart it is attached to. Live Trading...
 
Anthony Garot:

I haven't tried this, but there is a function ChartApplyTemplate() in MT4.

As long as your template is the same name as your EA, the template should automatically load the EA when invoked.

https://docs.mql4.com/chart_operations/chartapplytemplate

Of course, by "same name" I mean same name, appropriate extension, e.g.  ABC.tpl -- ABC.mq4

ChartApplyTemplate() is the right way, just include the EA in the template.

No need to use the same name, that's useful only with the Strategy Tester, and is working in opposite direction, a template is used automatically when you run a test with an EA using the same name.

 

Thanks Guys 

That really helps. 

 
Alain Verleyen:

ChartApplyTemplate() is the right way, just include the EA in the template.

No need to use the same name, that's useful only with the Strategy Tester, and is working in opposite direction, a template is used automatically when you run a test with an EA using the same name.

Thank you dear Alian

It's amazing solution

but there is a problem:

when I load template on chart by own, template is load and EA is running and Allow Automated Trading is On

when my indicator load template on next chart, template is load and EA is running but Allow Automated Trading is Off

Allow Automated Trading


I tried to use parameters in template, then i edit template in notepad and find this switch:

expertmode=1

0 is not allow

1 is allow

But this switch just work when you load template by own.

I'm thankful for your answers.

 

Did you read the documentation ?

The terminal allows saving the configured chart as a template with all indicators and Expert Advisors launched on it. Thus, it is possible to quickly apply template settings to all other charts. When saving the template, permissions of the launched programs (live trading and DLL imports) are also saved. When applying the template to the chart, these permissions may be limited due to security reasons:

Live trading and DLL imports permissions cannot be extended for the Expert Advisors launched by applying the template using ChartApplyTemplate() function.

If the mql4 program calling ChartApplyTemplate() function has no permission to trade, the Expert Advisor launched via the template will also not be able to trade regardless of the template settings.

If the mql4 program calling ChartApplyTemplate() function has permission to trade, while there is no such permission in the template settings, the Expert Advisor launched via the template will not be able to trade.

ChartApplyTemplate - Chart Operations - MQL4 Reference
ChartApplyTemplate - Chart Operations - MQL4 Reference
  • docs.mql4.com
Applies a specific template from a specified file to the chart. The command is added to chart message queue and executed only after all previous commands have been processed. The Expert Advisor will be unloaded and will not be able to continue operating in case of successful loading of a new template to the chart it is attached to. Live Trading...
 
Alain Verleyen:

Did you read the documentation ?

Thank you for your reply

I saw your link: 

https://docs.mql4.com/chart_operations/chartapplytemplate

and some another link:

https://www.mql5.com/en/articles/5166

https://www.mql5.com/en/code/19003

https://www.mql5.com/en/docs/chart_operations/chartapplytemplate

https://www.mql5.com/en/docs/runtime/tradepermission

and many other.

I can run EA on chart by template, but I cant find a way to "Allow Automated Trading" by code.

You think, this is impossible?

Thanks in advance

ChartApplyTemplate - Chart Operations - MQL4 Reference
ChartApplyTemplate - Chart Operations - MQL4 Reference
  • docs.mql4.com
Applies a specific template from a specified file to the chart. The command is added to chart message queue and executed only after all previous commands have been processed. The Expert Advisor will be unloaded and will not be able to continue operating in case of successful loading of a new template to the chart it is attached to. Live Trading...
 
Morteza Soltani:

Thank you for your reply

I saw your link: 

https://docs.mql4.com/chart_operations/chartapplytemplate

and some another link:

https://www.mql5.com/en/articles/5166

https://www.mql5.com/en/code/19003

https://www.mql5.com/en/docs/chart_operations/chartapplytemplate

https://www.mql5.com/en/docs/runtime/tradepermission

and many other.

I can run EA on chart by template, but I cant find a way to "Allow Automated Trading" by code.

You think, this is impossible?

Thanks in advance

If your template has trading allowed, you still need to use ChartApplyTemplate from a code having trading rights. An indicator doesn't have trading rights.

And by the way you are here on mql4/MT4 section, you should not try to get answer about mql5/MT5.

 
Alain Verleyen:

If your template has trading allowed, you still need to use ChartApplyTemplate from a code having trading rights. An indicator doesn't have trading rights.

And by the way you are here on mql4/MT4 section, you should not try to get answer about mql5/MT5.

Dear Alian

As always, you solved my problem. Thank you so much.

I should open EA in next chart by an EA instead of Indicator.

Because first EA has Automated Trading Permission.

Documentation on MQL5: Chart Operations / ChartNext
Documentation on MQL5: Chart Operations / ChartNext
  • www.mql5.com
Chart Operations / ChartNext - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: