What is wrong with that code?

 

This short script  has been rejectesd from Codebase but not sure why. It is intended to apply a template to all charts.

//+------------------------------------------------------------------+
//|                                                     closeAll.mq5 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property link      "http://www.mql5.com"
#property version   "1.00"
#property script_show_inputs
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
#property copyright "2010, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#include <private/errordescription.mqh>
//+------------------------------------------------------------------+
input string TemplateName;//  template name
int OnStart()
  {
//---
   long chart_id=ChartNext(0);

   while(chart_id > 0)
     {
      if(!ChartApplyTemplate(chart_id,TemplateName))
        {
         Print(ErrorDescription(GetLastError()));
         return(-1);
        }
      chart_id=ChartNext(chart_id);
     }

   ChartApplyTemplate(chart_id,TemplateName);
   return (0);

  }
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2022.03.13
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Carlos Albert Barbero Marcos: This short script  has been rejectesd from Codebase but not sure why. It is intended to apply a template to all charts.

Maybe you failed to supply the "#include" file with the publication,
or maybe because your comments with "closeAll.mq5" don't match the functionality or real file name.
or maybe the copyright and link are not yours but that of MetaQuotes (just guessing here).

However, surely when it rejected the publication it gave some textual hints of why that was.

 
  1. Perhaps you should read the manual. ChartNext - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    ChartNext(0) is wrong. You should use ChartFirst()


  2. Why are you trying to apply a template with an invalid ID? (after the loop.)

 
William Roeder #:
  1. Perhaps you should read the manual. ChartNext - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    ChartNext(0) is wrong. You should use ChartFirst()


  2. Why are you trying to apply a template with an invalid ID? (after the loop.)

Thanks 

1: starting with chartnext  preserves the chart from where the script is launched,  starting with first chart would cross the script chart therefore stopping the loop before duty

2 at the end of the chartnext loop chart ID is zero meaning the first chart according to doc but in fact it means the launching chart which was not the first one. Btw nothing forbids starting a loop with chartNext.

That 's why I don't understand the Bad Cose reason, if template not found then exit script with error code,  otherwise it completes the task theu the end.

 
Fernando Carreiro #:

Maybe you failed to supply the "#include" file with the publication,
or maybe because your comments with "closeAll.mq5" don't match the functionality or real file name.
or maybe the copyright and link are not yours but that of MetaQuotes (just guessing here).

However, surely when it rejected the publication it gave some textual hints of why that was.

It is not the include because  there was not in the version I submitted, it was returned with Bad code reason meaning not metadata

 
Carlos Albert Barbero Marcos #: It is not the include because  there was not in the version I submitted, it was returned with Bad code reason meaning not metadata

Then show the code exactly as it was submitted! It's for the Codebase, so why not show the exact same code, instead of this roundabout one. Attach it as a file instead of posting it.

 
Fernando Carreiro #:

Then show the code exactly as it was submitted! It's for the Codebase, so why not show the exact same code, instead of this roundabout one. Attach it as a file instead of posting it.

Because the include just stacks  a succession of error messages strings witch would clog the code, it has really no interest

 
Carlos Albert Barbero Marcos #: Because the include just stacks  a succession of error messages strings witch would clog the code, it has really no interest

But that is exactly the problem — it is of interest! Otherwise we cannot compile and test its functionality for you in order to help you understand what's wrong.

Anyway, I've lost interest! Maybe someone else will have the spare time to help you out!

 
Fernando Carreiro #:

But that is exactly the problem — it is of interest! Otherwise we cannot compile and test its functionality for you in order to help you understand what's wrong.

Anyway, I've lost interest! Maybe someone else will have the spare time to help you out!

You already saw first the error in the metadata which was out of he rule, thanks

 
Carlos Albert Barbero Marcos #: 1: starting with chartnext  preserves the chart from where the script is launched, 

Really? ChartNext - Chart Operations - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5:

Parameters

chart_id

[in]  Chart ID. 0 does not mean the current chart. 0 means "return the first chart ID".

Reason: