I'm having a couple of issues with the ChartApplyTemplate function that I hope someone can help me with. I have a template that I like to trade on an offline range bar chart which has a bunch of indicators and a trade pannel EA. However, some of the indicators don't update properly, so occasionally I force them to refresh by re-applying the template. To make this easier I coded the following simple script that I assign to a key and just hit that to refresh.
Code: Select all
//+------------------------------------------------------------------+
//| TemplateScript.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
input string Template = "My_Template.tpl";
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
//---
if(ChartApplyTemplate(0,"\\"+Template))Print("Template Refreshed");
else
Print("Failed to apply template, error code ",GetLastError());
}
//+------------------------------------------------------------------+The second problem I had was when I moved this code to an on-screen button within an indicator. Using standard button code taken from the mql4 reference files I put a button on the chart with the sole purpose of refreshing the template. So the active code itself hasn't changed, I just dropped it into an OnChartEvent (with input string Template declared globally).
Code: Select all
if(id==CHARTEVENT_OBJECT_CLICK)
{
if(sparam=="Button1")
{
if(ChartApplyTemplate(0,"\\"+Template))Print("Template Refreshed");
else
Print("Failed to apply template, error code ",GetLastError());
// unpress the button
ObjectSetInteger(0,"Button1",OBJPROP_STATE,false);
return;
}
}//if(id==CHARTEVENT_OBJECT_CLICK)So in theory, this is the same code it's just that it is called from a button click rather than a script. However, the difference is that this way of sending the code removes the live trading permissions from an EA that I have loaded in the template - even though the original template was saved with the EA trading permissions ticked. I've read in the reference that "Live trading and DLL imports permissions cannot be extended for the Expert Advisors launched by applying the template using ChartApplyTemplate() function." The script method works fine though so how do I give the indicator "permission to trade" so that it can extend it to the EA? Or is it simply that scripts can trade and indicators can't? If that's the case, can a button click call a script perhaps? Any ideas?
Thanks
Bruster