Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1219

 

Static variables declared in a class function are pass-through for all instances of that class?

For some reason, I expected it to be different for each instance.

Is the alternative only class-level variables or are there some other tricky ways?

 

Hello ! I need to specify the path to save the file. more precisely the tick history. Help solve this problem )

//------------------------------------------------------------------
#property copyright "www.forex-tsd.com"
#property link      "www.forex-tsd.com"
//------------------------------------------------------------------
#property indicator_chart_window

//
//
//
//
//

extern string FileName   = "Ticks.csv";
extern bool   SaveVolume = true; 
int fileHandle;

MqlBookInfo book[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int  OnInit()                   
{ 
   MarketBookAdd(_Symbol); 
      fileHandle = FileOpen(Symbol()+" - "+FileName,FILE_WRITE|FILE_SHARE_READ|FILE_ANSI|FILE_CSV); 
      return(0); 
}
void OnDeinit(const int reason) 
{
   MarketBookRelease(_Symbol);
   FileClose(fileHandle);
}

//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//

int OnCalculate(const int rates_total, const int prev_calculated, const datetime &Time[],
                const double &Open[], const double &High[], const double &Low[], const double &Close[],
                const long &TickVolume[], const long &Volume[], const int &Spread[])
{                
   if (fileHandle <0)
   {
      static bool alerted = false;
         if (!alerted)
         {
            Alert("File : "+Symbol()+" - "+FileName+" could not be opened"); alerted = true;
         }
         return(0);
   }         

   //
   //
   //
   //
   //
   
   bool bget = MarketBookGet(_Symbol,book);
   int bidVolume = 0;
   int askVolume = 0;

      if (bget)
      {
         int    size = ArraySize(book);
         string info = "\n";
            for (int i=0; i<size; i++)
               {
                  if (book[i].type==BOOK_TYPE_SELL) askVolume += (int)book[i].volume;
                  if (book[i].type==BOOK_TYPE_BUY)  bidVolume += (int)book[i].volume;
               }                  
      }            
      
   if (FileSize(fileHandle) == 0)
         FileWriteString(fileHandle,"date and time,bid,ask,bid volume,ask volume\n");
         if (SaveVolume)
               FileWriteString(fileHandle,TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS)+","+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)+","+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits)+","+DoubleToString(bidVolume,0)+","+DoubleToString(askVolume,0)+"\n");
         else  FileWriteString(fileHandle,TimeToString(TimeCurrent(),TIME_DATE|TIME_SECONDS)+","+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits)+","+DoubleToString(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits)+"\n");
         FileFlush(fileHandle);
   return(0);
}
 

@NeuralNetwork

FileOpen

The file is opened in the folder of the client terminal in subfolder MQL5\Files (or agent_folder\MQL5\Files in case of testing).

If FILE_COMMON is specified among the flags, the file is opened in the common folder of all the client terminals \Terminal\Common\Files.

--

to another location only via "symbolic link"

      fileHandle = FileOpen(Symbol()+" - "+FileName,FILE_WRITE|FILE_SHARE_READ|FILE_ANSI|FILE_CSV);    // FILE_COMMON 



 
NeuralNetwork:
Thank you very much ! But, I want to set the path to save the file by specifying another drive or folder. I can't do it ...

https://www.mql5.com/ru/docs/files

3 line

Документация по MQL5: Файловые операции
Документация по MQL5: Файловые операции
  • www.mql5.com
Из соображений безопасности в языке MQL5 строго контролируется работа с файлами. Файлы, с которыми проводятся файловые операции средствами языка MQL5, не могут находиться за пределами файловой "песочницы". общая папка всех установленных на компьютере терминалов  – обычно расположена в каталоге C:\Documents and Settings\All Users\Application...
 
Fast235:

@NeuralNetwork

FileOpen

The file is opened in the folder of the client terminal in subfolder MQL5\Files (or agent_folder\MQL5\Files in case of testing).

If FILE_COMMON is specified among the flags, the file is opened in the common folder of all the client terminals \Terminal\Common\Files.

--

to another location only via "symbolic link"



Thank you very much !
 
Roman Shiredchenko:


how will the admins and moderators solve the problem of a crookedly written robot?

 

Please advise if it is possible to get RSI values for weekly timeframe in the Expert Advisor code, but to calculate the values for the week, starting not from Monday, but for example from Wednesday (that is for the week from Wednesday till next Wednesday). I understand that it will not work with iRSI, because it takes weekly bars, and they start on Monday.

So far I see only one way of calculating it. Is there a simpler solution or a ready solution?

 
Roman Shiredchenko:

Shouting, yelling, cursing, not wanting to make your own code work, blaming moderators and admins, insulting moderators and admins...

In general - the whole package. I will give you one week to cool down and sort out your mistakes. Thoughtful!

 
Valeriy Yastremskiy:

To account for a ticket.

When opening an order, the ticket must be memorised.

Thank you
 
Valeriy Yastremskiy:

Flags either control the number of order types or if there is a ticket control the closing time of the market order, if not equal to zero then the order has closed and the order opening flag is false.

Thanks, got it already, people suggested it )))))))😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃😃