How to start with MQL5 - page 38

 
Vladimir Karputov # :

Kodunuzu ekleyin, kodun tam olarak ne için açıklayın. Tam olarak neşeyle işe yaramadığını açıklayın.

I am sending the codes. In the macd indicator I want, if the difference between the main line and the signal line is greater than InpDifference, the position is closed. but there are many different operations. I change the InpDifference value, but the operations do not change.

 
Kutluhan Yesilkaya # :

I am sending the codes. In the macd indicator I want, if the difference between the main line and the signal line is greater than InpDifference, the position is closed. but there are many different operations. I change the InpDifference value, but the operations do not change.

I gave you a code ( iMACD Difference Close All : ) - why are you ignoring my code? Why are you inserting obscure characters and operations into the code?

You must do this: You must take my code. And then start consultations - how to change it (or supplement it). That is, we continue to work like this: you take my code, you ask a question - and wait for an answer.

iMACD Difference Close All
iMACD Difference Close All
  • www.mql5.com
Советник-утилита: при граничной разнице между линиями индикатора iMACD (Moving Average Convergence/Divergence, MACD) советник закроет все позиции на текущем символе.
 

How to read the name of currency pairs from a text file

So an example:

Stage number 1:

Let's start with the location of the text file: in the MetaEditor 5 editor in the ' File ' menu, select the item ' Open Data Folder r':

in explorer click on folder ' MQL5 '

in explorer click on the folder ' Files '

in the folder that opens, create our file 'ForexSymbol.txt' and write a string with symbols into it

AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURJPY,EURNZD,EURUSD,GBPAUD,GBPCAD,GBPCHF,GBPJPY,GBPNZD,GBPUSD,NZDCAD,NZDCHF,NZDJPY,NZDUSD,USDCAD,USDCHF,USDJPY


Stage number 2:

Let's launch our Expert Advisor:

//+------------------------------------------------------------------+
//|                                           CFileTxt test Read.mq5 |
//|                         Copyright © 2022, Vladimir Karputov |
//|                      https://www.mql5.com/en/users/barabashkakvn |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, Vladimir Karputov"
#property link      "https://www.mql5.com/en/users/barabashkakvn"
#property version   "1.000"
//---
#include <Trade\SymbolInfo.mqh>
#include <Files\FileTxt.mqh>
//---
CSymbolInfo    m_symbol;                     // object of CSymbolInfo class
CFileTxt       m_file_txt;                   // file txt object
//--- input parameters
input string   InpFileName = "ForexSymbol.txt"; // File name
//---
string   m_array_symbols[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(!m_file_txt.Open(InpFileName,FILE_READ))
     {
      Print("Error open ',",InpFileName,"' #",GetLastError());
      return(INIT_FAILED);
     }
   Print("File ',",InpFileName,"' opened successfully");
   string sep=",";                // A separator as a character
   ushort u_sep;                  // The code of the separator character
//--- Get the separator code
   u_sep=StringGetCharacter(sep,0);
   while(!m_file_txt.IsEnding())
     {
      //--- read and print the string
      string to_split=m_file_txt.ReadString();
      Print(to_split);
      string result[];               // An array to get strings
      //--- Split the string to substrings
      int k=StringSplit(to_split,u_sep,result);
      //--- Show a comment
      PrintFormat("Strings obtained: %d. Used separator '%s' with the code %d",k,sep,u_sep);
      //--- Now output all obtained strings
      if(k>0)
        {
         for(int i=0; i<k; i++)
           {
            ResetLastError();
            if(!m_symbol.Name(Symbol())) // sets symbol name
              {
               Print(__FILE__," ",__FUNCTION__,", ERROR: CSymbolInfo.Name");
               continue;
              }
            PrintFormat("result[%d]=\"%s\"",i,result[i]);
            int size=ArraySize(m_array_symbols);
            ArrayResize(m_array_symbols,size+1,10);
            m_array_symbols[size]=result[i];
           }
        }
     }
   m_file_txt.Close();
   Print("- - -");
   ArrayPrint(m_array_symbols);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
  }
//+------------------------------------------------------------------+

Result:

File ',ForexSymbol.txt' opened successfully
AUDCAD,AUDCHF,AUDJPY,AUDNZD,AUDUSD,CADCHF,CADJPY,CHFJPY,EURAUD,EURCAD,EURCHF,EURGBP,EURJPY,EURNZD,EURUSD,GBPAUD,GBPCAD,GBPCHF,GBPJPY,GBPNZD,GBPUSD,NZDCAD,NZDCHF,NZDJPY,NZDUSD,USDCAD,USDCHF,USDJPY
Strings obtained: 28. Used separator ',' with the code 44
result[0]="AUDCAD"
result[1]="AUDCHF"
result[2]="AUDJPY"
result[3]="AUDNZD"
result[4]="AUDUSD"
result[5]="CADCHF"
result[6]="CADJPY"
result[7]="CHFJPY"
result[8]="EURAUD"
result[9]="EURCAD"
result[10]="EURCHF"
result[11]="EURGBP"
result[12]="EURJPY"
result[13]="EURNZD"
result[14]="EURUSD"
result[15]="GBPAUD"
result[16]="GBPCAD"
result[17]="GBPCHF"
result[18]="GBPJPY"
result[19]="GBPNZD"
result[20]="GBPUSD"
result[21]="NZDCAD"
result[22]="NZDCHF"
result[23]="NZDJPY"
result[24]="NZDUSD"
result[25]="USDCAD"
result[26]="USDCHF"
result[27]="USDJPY"
- - -
[ 0] "AUDCAD" "AUDCHF" "AUDJPY" "AUDNZD" "AUDUSD" "CADCHF" "CADJPY" "CHFJPY" "EURAUD" "EURCAD" "EURCHF" "EURGBP" "EURJPY" "EURNZD"
[14] "EURUSD" "GBPAUD" "GBPCAD" "GBPCHF" "GBPJPY" "GBPNZD" "GBPUSD" "NZDCAD" "NZDCHF" "NZDJPY" "NZDUSD" "USDCAD" "USDCHF" "USDJPY"
 
Vladimir Karputov # :

Sana bir kod verdim ( iMACD Fark Tümünü Kapat : ) - neden kodumu geliyorsun? Neden koda tamamlar ve tamamlarsınız?

Bunu yapmalısın: Kodumu almalısın. Ve antrenmanlara - sonra nasıl yapılır (veya tamamlanır). Yani, şu şekilde mezun olduğunuzda: kodumu alıyorsunuz, bir soru soruyorsunuz - ve bir cevap bekliyorsunuz.

Is it wrong to add the code to the robot? Do you need to run the codes you gave in a different place?

 
Kutluhan Yesilkaya #:

Is it wrong to add the code to the robot? Do you need to run the codes you gave in a different place?

There is both a text file and an mql5 file in metaeditor. Which key should I press to see the results? Thank you

 
Kutluhan Yesilkaya # :

Is it wrong to add the code to the robot? Do you need to run the codes you gave in a different place?

Kutluhan Yesilkaya # :

There is both a text file and an mql5 file in metaeditor. Which key should I press to see the results? Thank you

Do-it-yourself work is always very good! But: I offer you a better way. You need to take my code (this will be the base) and then gradually change it according to your requirements.

 
Vladimir Karputov # :

Kendin yap işi her zaman çok iyidir! Ama: Sana daha iyi bir yol sunuyorum. Kodumu olacaktır (bu olacaktır) ve bundan sonra temel bir değer olarak değerlendirilmelidir.

I added the codes to my robot. is this wrong? Should I run the Imacd codes separately?

 
Kutluhan Yesilkaya # :

I added the codes to my robot. is this wrong? Should I run the Imacd codes separately?

This option is also possible. But compare my and your code - you have an old construction in OnInit. I repeat for the last time: You must take the original code and then GRADUALLY, STEP by STEP, make changes. So I'm waiting for you to take the first step.

 
Vladimir Karputov #:

This option is also possible. But compare my and your code - you have an old construction in OnInit. I repeat for the last time: You must take the original code and then GRADUALLY, STEP by STEP, make changes. So I'm waiting for you to take the first step.

I did what you said, I completed the deficiencies of oninit. but nothing has changed.

 
Kutluhan Yesilkaya # :

I did what you said, I completed the deficiencies of oninit. but nothing has changed.

No and no again - you are making the same mistake again. Remember the algorithm:

  1. You must (you simply must) take the COMPLETE code of the MACD Difference Close All Expert Advisor
  2. At this stage, you are PROHIBITED to make any changes to the code!!!
  3. You should ask the question: "What needs to be changed (or added) in the code so that the code works in accordance with your algorithm"
iMACD Difference Close All
iMACD Difference Close All
  • www.mql5.com
Советник-утилита: при граничной разнице между линиями индикатора iMACD (Moving Average Convergence/Divergence, MACD) советник закроет все позиции на текущем символе.
Reason: