Download MetaTrader 5
To add comments, please log in or register
What is MetaQuotes ID? Find that out from the article!
Willbur
198
Willbur 2016.04.17 21:00 

Hi there,

my plan is to save the chart as a template bevor leaving it. This part works fine!

It's the reload in 'OnInit', which don't do what I what.

The MessageBox says "Template apply: 0" - but noting happends in the chart.

I can load the template when going the manual way: right mouse button in the chart - template - template load - 

Any idea?

Willbur


OnInit
       ResetLastError();

       if(ChartApplyTemplate(0,_Symbol+".tpl"))
               ChartRedraw();

       MessageBox("Template apply:"+GetLastError());


OnDeinit  
       ChartSaveTemplate(0,_Symbol);

Willbur
198
Willbur 2016.04.18 08:14  

That's realy odd:

It's working with 'USDJPY' but it's not not working with 'Ger30Jun16' .

Willbur

Alain Verleyen
Moderator
30639
Alain Verleyen 2016.04.18 08:17  

You don't need to add ".tpl"

       if(ChartApplyTemplate(0,_Symbol+".tpl"))
Though you will have a "loop" as the OnInit() will be applied after the template is loaded.
Willbur
198
Willbur 2016.04.18 08:53  

Hi Alain

thanks for the hint: I put the "+'.tpl'" off.


Regarding the loop. There is a code sequence I didn't post, which cares about this issue.

The hole story is:

1. In a chart/template, I worked already with, there is a Text-Object named "Symbol". This allows me to decide whether I see a default (which has no text object) or the chart which I used last time.

2. I do not know, how to check what the reason for the OnInit is. So I brought in a flag named "ProgStartInit".

bool ProgStart = true;

int OnInit(void)
{
//--- Is the right template loaded? Try it!
      if(ProgStartInit && ObjectFind(0,"Symbol") < 0)
         if(MessageBox(_Symbol+"\n\nLoad Template?","Frage",MB_YESNO) == IDYES)
            {
            ResetLastError();
            if(ChartApplyTemplate(0,_Symbol))

               ChartRedraw();
            else
               MessageBox("Template load Error:"+GetLastError());
            }
               
 . . .  other stuff . . .

 
     ProgStartInit = false;
     return(INIT_SUSSEEDED);
}

Willbur
198
Willbur 2016.04.18 09:10  

Uppsss .... I am afraid my 'ProgStartInit' does not work in case of a template change.

For other reasons - like change of PERIOD - it works fine.

Does the change of the template cause a completely new start fo the EA?

Anyway: the ChartApplyTemplate() works only for some Symbols.

WIllbur

Alain Verleyen
Moderator
30639
Alain Verleyen 2016.04.18 09:19  
Willbur:

Uppsss .... I am afraid my 'ProgStartInit' does not work in case of a template change.

For other reasons - like change of PERIOD - it works fine.

Does the change of the template cause a completely new start fo the EA?

Yes.

Anyway: the ChartApplyTemplate() works only for some Symbols.

WIllbur

You can check the uninit reason : UninitializeReason(). See documentation.
Willbur
198
Willbur 2016.04.18 12:22  

ok, I give up.       I reduced my test program to

input string inTemplateName = "Test";

int OnInit(void)
{     ResetLastError();
      ChartApplyTemplate(0,inTemplateName);
      MessageBox("Load Template "+inTemplateName+" LastError: "+IntegerToString(GetLastError()));

After 2 hours of testing the result is:

TemplateName     Result
------------------    --------
Ger30Jun16         Nok
Ger30Ju16            OK
Ger30Jun1            OK
Test1234              OK
USDJPY                OK  not opened in another chart simulatiously
Usa500Jun16        OK  opened in another chart the simultaiously
... and so on .... and so on ....

The code is now:

int OnInit(void)
{

     string templateFileName = _Symbol;

     if(_Symbol == "Ger30Jun16")
         templateFileName = "FuckIt";
        
      ResetLastError();
      if(ChartApplyTemplate(0,templateFileName))
            MessageBox("Ladefehler Template:"+GetLastError());  

Works fine . . .

/
To add comments, please log in or register