OnStart function to EA - Adding a style template to your expert advisor load

 

Hi All,

 

Wondering if anyone has any experience and feedback on loading an style template file to the chart where you are loading your Expert advisor? Im actually look at this for 2 reasons. I am running it and debugging and need to see the indicators im using at the same time to work out what bit is not working and causing me a problem.

 

But the other thing is the goal is to make this useable and a training tool for the beginner trader on MT4. so they need to load all of the indicators to show them why the EA is making those trades.

 

In Principle Im here but its not working wont compile;

void OnStart()
   if(FileIsExist("Big-BrokingAutoTrader.tpl"))
     {
      Print("The file my_template.tpl found in \templates'");
      //--- apply template
      if(ChartApplyTemplate(0,"\\templates\\Big-BrokingAutoTrader.tpl"))
        {
         Print("The template 'Big-BrokingAutoTrader.tpl' applied successfully");
        }
      else
         Print("Failed to apply 'Big-BrokingAutoTrader.tpl', error code ",GetLastError());
     }
   else
     {
      Print("File 'Big-BrokingAutoTrader.tpl' not found in "
            +TerminalInfoString(TERMINAL_PATH)+"\\templates");
     }
  }


 

 

OnStart() is used in scripts, OnTick() is used in an EA - check here for Event Handling Functions

Just to be clear, which are you proposing? 

Presuming you are going the EA route:

I've not tried this, but I think you may run into some problems with the principle.

If you apply the template, it will remove what is currently applied to the chart (i.e. this EA!)

And if this EA is included in the template, you'll end up applying / removing / applying / removing the EA.

You may be better to create a script that applies the template which includes the EA and everything else you want.

Happy to be proven wrong though.

 
honest_knave:

OnStart() is used in scripts, OnTick() is used in an EA - check here for Event Handling Functions

Just to be clear, which are you proposing? 

Presuming you are going the EA route:

I've not tried this, but I think you may run into some problems with the principle.

If you apply the template, it will remove what is currently applied to the chart (i.e. this EA!)

And if this EA is included in the template, you'll end up applying / removing / applying / removing the EA.

You may be better to create a script that applies the template which includes the EA and everything else you want.

Happy to be proven wrong though.

Hi Knave,

 

My thoughts were that you could use the init deinit but from the experience of the last inidicator you helped me with i thought that was old code and not worth it.

I basically just want it to load the Chart Style and indicators to the visual window. If you run an EA and load a template that doesnt have an EA the EA will still be loaded well works for me that way.

If you have another EA saved into the template though it will reload the new one for you.

 

its just the visual thing really wondered if there was a way to just hard code the style into it

 

On MT5 you have access to ChartIndicatorAdd() which is probably what you want. Sadly, that doesn't work on MT4.

But yes, a template will override everything (objects, indicators, colour schemes, EAs).

I will also say, are you sure you want to learn MQL4 at this stage? It will be around for a while longer, but MQL5 is the future. However, there are less learning resources to get you going with MQL5.

 

Sorted this issue. Rather basic oversight! Save the template with the exact same name as your expert advisor and the template will be loaded by default when you add the Expert to the chart!.

 

MQL5 is very similar am I right? to be fair im not an MQL man normally I have a background in making a lot of stuff using VBA through Excel and Microsoft GUI's so just adapting what I know in MQL and have a good sound understanding of trading.