Questions from Beginners MQL5 MT5 MetaTrader 5 - page 442

 

Good evening, everyone,

1.

Strategy - bar appeared, set pending order with stoploss and takeprofit (sl, tp), nothing else.

Let's assume that in the current bar, after some time, a price will appear for the order to trigger, later the sl price will come, and then the tp price .

Please try to explain - let's assume that the opening price of the new bar will be somewhere between the sl and tp price limits. How is this calculation performed?

Logically, it cannot, because the tester has only the next bar open price? And it is not equal to the price specified in the condition for pending order triggering, which means the order should not be triggered.

But: during the tester's run, trades are somehow executed and stops are triggered. In what way?

2.

the tester creates fxt with every start. and this is time. I couldn't find any setting hinting at avoiding this... In idea: create it once and if I don't change anything, use this file, but no, the terminal rewrites it

 
Can you tell me, does the EA need a tick to execute init()?
 
-Aleks-:
Can you tell me, does the EA need a tick to execute init()?

No. You don't. Here's the code to help you see this:

//+------------------------------------------------------------------+
//|                                                  test_expert.mq5 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright  "Copyright 2015, MetaQuotes Software Corp."
#property link       "http://www.mql5.com"
#property version    "1.00"
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- 
   Print(__FUNCTION__);
   return(INIT_FAILED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   Print(__FUNCTION__);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   Print(__FUNCTION__);
  }
//+------------------------------------------------------------------+
Attach it to the chart and see what functions are working at the weekend.
 
-Aleks-:
Can you tell me, does the EA need a tick to execute init()?
I don't think so.
 
Karputov Vladimir:

No. You don't. Here's the code to help you see it:

Attach it to the chart and see which functions are working at the weekend.
Tapochun:
I don't think so.
Thank you for the prompt reply. Then I don't understand why it doesn't work - there's no print...
 
-Aleks-:
Thank you for your prompt reply. Then I don't understand why it's not working - there's no print...
Where is your printer? Can I have the code to reproduce it?
 
Karputov Vladimir:
And where does your printer stand? Can I have the code, for reproduction?

It turns out that initialisation does not happen when the terminal is loaded, but it does happen when the timeframe is changed.

I need to check if reading one file by a dozen EAs during initialization would not be a problem...

I am using a class.

int init()
  {
//Автоматическая настройка
   if(Use_SetupLoad==true)
     {
      CSVReader FileLoads(FileLoadSetup);
      FileLoads.SetDelimiter(';');
      FileLoads.SetCommon(true);
      int StrokaSetup=0;
      if(FileLoads.Load(1))
        {
         PrintFormat("File %s loaded. Total rows=%d, Total columns=%d",FileLoads.FileName(),FileLoads.TotalRows(),FileLoads.TotalColumns());
         
         for (int i=1;i<30; i++)
         //for (int i=1; i<100 || StrokaSetup!=0; i++)
         {
           if (Magic==FileLoads.GetIntValue(i,13))
           {
            StrokaSetup=i ;
            Print ("StrokaSetup=",StrokaSetup);
            break;
            }
         //   if (i==100) i=1;
         //  Print (FileLoads.GetIntValue(i,13));
         }
         /*
         for (int i=1; i<30; i++)
         {
         Print (FileLoads.GetIntValue(i,13));         
         }
         */
         if(StrokaSetup!=0)
           {
            pipsXH=FileLoads.GetIntValue(StrokaSetup,4)/10;
            if (pipsXH>0)
            {
            pMAH=FileLoads.GetIntValue(StrokaSetup,3);
   //         typeMAH=FileLoads.GetIntValue(StrokaSetup,3);
   //         priceMAH=FileLoads.GetIntValue(StrokaSetup,2);
            
  //          if (pipsXH<0)
  //          PrintFormat("pMAH=%d",pMAH,"typeMAH=%d",typeMAH,"priceMAH=%d",priceMAH,"pipsXH=%d",pipsXH);
            }
            else pipsXH=(-1);
            
            pipsXL=FileLoads.GetIntValue(StrokaSetup,7)/10*(-1);
            if (pipsXL>0)
            {
            pMAL=FileLoads.GetIntValue(StrokaSetup,6);
     //       typeMAL=FileLoads.GetIntValue(StrokaSetup,3);
     //       priceMAL=FileLoads.GetIntValue(StrokaSetup,2);
            
      //      PrintFormat("pMAL=%d",pMAL,"typeMAL=%d",typeMAL,"priceMAL=%d",priceMAL,"pipsXL=%d",pipsXL);
            }
            else pipsXL=(-1);
                        
            pMAT=FileLoads.GetIntValue(StrokaSetup,9);
      //      typeMAT=FileLoads.GetIntValue(StrokaSetup,3);
      //      priceMAT=FileLoads.GetIntValue(StrokaSetup,2);
      //      PrintFormat("pMAT=%d",pMAT,"typeMAT=%d",typeMAT,"priceMAT=%d",priceMAT);
            
            lot=FileLoads.GetDoubleValue(StrokaSetup,11);
      //    PrintFormat("pMAH=%d",pMAH,"pipsXH=%d",pipsXH,"pMAL=%d",pMAL,"pipsXL=%d",pipsXL,"lot=%d",lot);            
            Print("Magic=",Magic," pMAH=",pMAH," pipsXH=",pipsXH," pMAL=",pMAL," pipsXL=",pipsXL," lot=",lot);            
            
           }

        }
      else PrintFormat("Error in loading data from %s",FileLoads.FileName());
     }
///Конец автоматической настройки///  
   return(INIT_SUCCEEDED);
  } 

A piece of class responsible for reading a file

//+------------------------------------------------------------------+
//| Load                                                             |
//+------------------------------------------------------------------+
bool CSVReader::Load(int start_line)
  {
   int filehandle=FileOpen(m_filename,FILE_CSV|FILE_READ|FILE_ANSI|FILE_SHARE_READ,'\n');
   if(filehandle==INVALID_HANDLE)
     {
      Alert("Error in open of file ",m_filename,", error",GetLastError());
      return(false);
     }
//---
   int line_index=0;
   while(!FileIsEnding(filehandle))
     {
      string str=FileReadString(filehandle);
      //--- skip 0th row
      if(line_index>=start_line)
         if(str!="")
           {
            if(line_index==1) AddData(str,true);
            else AddData(str,false);
           }
      line_index++;
     }
//---
   FileClose(filehandle);
   return(true);
  } 
 
-Aleks-:

It turns out that initialisation does not happen when the terminal is loaded, but it does happen when the timeframe is changed.

I need to check if reading one file by a dozen EAs during initialization would not be a problem...

I am using a class.

Piece of class responsible for file reading

So there are a lot of checks and conditions in your code before the print. Go through it in debug mode and check what is not working.
 
Karputov Vladimir:
So there are a lot of checks and conditions in your code before the print. Go to debug mode and check what is not working.
In the tester everything works - but there are no prints when the terminal is loaded - that's what confused me.
 
-Aleks-:
In the tester, everything works - but there are no printers when the terminal is loaded - that's what confused me.
So it's worth adding more printers and seeing where the algorithm goes.
Reason: