Script for Changing Templates - page 2

 

Right, here's the story.  I have a number of charts open and have them as plain as possible, as part of that I have the foreground colour set to "none".  The downside to this is that you get no crosshair.  I therefore searched for a crosshair indicator and found the one by nicolishen, which works perfectly.  On the thread where I found it I noticed that people had made suggestions and he subsequently modified his indicator a number of times.  As he has done this in the past, I assumed (maybe wrongly) that he wold implement my suggestions as it would certainly improve the indicator.  If nicolishen had provided the source code I would be able to do this myself.  He chose to release his indicator just as an ex4, though, which is fair enough.

In the meantime, I thought if nicolishen does make the modifications to his indicator then it will mean slightly different settings for a few charts and therefore a different template.  This in turn means that the script I have to change templates will no longer work correctly as I will want to apply 3 different templates instead of one to ALL open charts.

While I don't have an in depth knowledge of how to code in MQL, I've started dabbling with it and modified many indicators/scripts and felt that I could do the same on this occasion.  I searched many places to try and find a solution but couldn't work out how to do it.  So, having seen thousands of threads where people ask for advice on MQL and thousands more on places like StackOverflow for other programming languages, I decided to ask for help here.  Now I know the world is made up of many different types of people, some helpful and will readily share their knowledge, others condescending and not so helpful. 

It's as though I'm Goldman Sachs and asking for 100,000 line algorithm to be written for me.  All I'm asking for is advice on a SNIPPET of code and if what I want is achievable.  I'm sure if someone was to provide the answer it wouldn't be much longer than the pseudo code I've written, explaining what I want.  Up to now I've be told to "search for it", which I have.  "Learn" MQL" (like nobody has ever asked questions before).  BEG in another forum for a bit of advice and stop using anchant [sic] code.

 
mp21: Right, here's the story.  ...  All I'm asking for is advice on a SNIPPET of code and if what I want is achievable.  I'm sure if someone was to provide the answer it wouldn't be much longer than the pseudo code I've written, explaining what I want.  Up to now I've be told to "search for it", which I have.  "Learn" MQL" (like nobody has ever asked questions before).  BEG in another forum for a bit of advice and stop using anchant [sic] code.

Don't just skim over users' posts or answers! @whroeder1 gave you the answer, which included a link than includes example code. But you decided to just skim over his post instead of looking at it line-by-line.

So, I am going to "spoon-feed" you by highlighting the section of his post. Maybe this time, you will actually put in the effort and stop complaining!

So follow the link, read it and look at the example code! If you are still unsure, then search using the function name and you will find many threads on it.

Forum on trading, automated trading systems and testing trading strategies

Script for Changing Templates

whroeder1, 2018.01.19 23:21

  1. You have only four choices: We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
              No free help
              urgent help.

  2. mp21: I just want to know the bit of code that does the following:

    if(market=XXX){
    apply template X
    }

    Perhaps you should read the manual.
              ChartApplyTemplate
    - Chart Operations - MQL4 Reference

  3. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  4. Stop using that ancient code. A lot has changed since February 3, 2014 (Build 600)

Also, since this site's search does not provide a direct MQL4 search, use Google and it will provide the answer on the very first item found:


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...
 

It's not applying the template that's the issue. It's the "IF", i.e if the chart is GBPUSD then apply template 1, if it's EURUSD then apply template 2, etc.

 
mp21: It's not applying the template that's the issue. It's the "IF", i.e if the chart is GBPUSD then apply template 1, if it's EURUSD then apply template 2, etc.

That's not what is understood from your thread title nor the initial post. You did say that it was pseudocode, so now you have to replace it with real MQL4 code.

You don't choose a market, but instead select a Chart ID from the list of open charts! ChartFirst(), ChartNext(), ChartSymbol(), ChartID() ... Chart Opertaions.

Until you learn the basics, you will not be able to explain yourself properly and you won't understand our advice. Both sides will just end up getting frustrated with each other!

So here is some reading material to help you get started:

Forum on trading, automated trading systems and testing trading strategies

Something Interesting to Read

Sergey Golubev, 2017.09.16 05:40

Expert Advisor Programming for MetaTrader 4


This book will teach you the following concepts:

  • The basic of the MLQ4 language, including variables and data types, operations, conditional and loop operators, functions, classes and objects, event handlers and more.
  • Place, modify and close market and pending orders.
  • Add a stop loss and/or take profit price to an individual order, or to multiple orders.
  • Close orders individually or by order type.
  • Get a total of all currently opened orders.
  • Work with OHLC bar data and locate basic candlestick patterns.
  • Find the highest high and lowest low of recent bars.
  • Work with MetaTrader’s built-in indicators, as well as custom indicators.
  • Add a trailing stop or break even stop feature to an expert advisor.
  • Use money management and lot size verification techniques.
  • Add a flexible trading timer to an expert advisor.
  • Construct several types of trading systems, including trend, counter-trend and breakout systems.
  • Add alert, emails, sounds and other notifications.
  • Add and manipulate chart objects.
  • Read and write to CSV files.
  • Construct basic indicators, scripts and libraries.
  • Learn how to effective debug your programs, and use the Strategy Tester to test your strategies.

All of the source code in this book is available for download, including an expert advisor framework that allows you to build robust and fully-featured expert advisors with minimal effort.

ChartFirst - Chart Operations - MQL4 Reference
ChartFirst - Chart Operations - MQL4 Reference
  • docs.mql4.com
ChartFirst - Chart Operations - MQL4 Reference
 

Thank you Fernando for pointing me in the right direction.