Download MetaTrader 5
To add comments, please log in or register
Find out how social trading can improve your profits
Shaun Overton
104
Shaun Overton 2015.12.18 20:40 

I'm trying to write a script which writes my trading history to a binary file. I tried to follow the example at https://docs.mql4.com/files/filewritestruct, but I keep getting the compile error "'tradeBuff' - parameter conversion not allowed OSR Trade History Recorder Binary.mq4 72 33"

 I can't figure out what the compiler is unhappy. Do you know why this won't compile?

 

#property strict

struct trade 
{
   string symbol;
   int direction;
   double lots;
   datetime openTime;
   datetime closeTime;
   double sl;
   double tp;
};


void OnStart()
{  
   trade tradeBuff[];
   string symbols[];
   int directions[];
   double lots[];
   datetime openTimes[];
   datetime closeTimes[];
   
   int size = OrdersHistoryTotal();
   ArrayResize(tradeBuff,size);
   ArrayResize(symbols,size);
   ArrayResize(directions,size);
   ArrayResize(lots,size);
   ArrayResize(openTimes,size);
   ArrayResize(closeTimes,size);
   
   for(int i = size - 1; i >= 0; i--)
   {
      if( OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) )
      {
         if(OrderType()==6)
            continue;
         
         symbols[i] = OrderSymbol();
         directions[i] = OrderType();        
         lots[i] = OrderLots();
         openTimes[i] = OrderOpenTime();
         closeTimes[i] = OrderCloseTime();
      }
   }
   
   for(int i = size - 1; i >= 0; i--)
   {
      tradeBuff[i].symbol = symbols[i];
      tradeBuff[i].direction = directions[i];
      tradeBuff[i].lots = lots[i];
      tradeBuff[i].openTime = openTimes[i];
      tradeBuff[i].closeTime = closeTimes[i];
   }
 
   string file = "tradeHistory.bin";
   
   int handle = FileOpen(file,FILE_READ|FILE_WRITE|FILE_BIN|FILE_COMMON);
   
   if( handle != INVALID_HANDLE )
   {
      for(int i = size - 1; i >= 0; i--)
      {
         FileWriteStruct(handle,tradeBuff[i]);  // THIS IS WHERE THE COMPILE ERROR OCCURS
	// 'tradeBuff' - parameter conversion not allowed	OSR Trade History Recorder Binary.mq4	72	33
      }
   }   
   FileClose(handle);  
}
Martin
3
Martin 2015.12.22 19:20  
FileWriteStruct doesn't work with arrays that "contain strings, dynamic arrays or virtual functions.". To make it compile you need to remove string symbol; from trade struct.
whroeder1
13610
whroeder1 2015.12.22 21:02  
MartinT: FileWriteStruct doesn't work with arrays that "contain strings, dynamic arrays or virtual functions.". To make it compile you need to remove string symbol; from trade struct.
Exactly. next time RTFM FileWriteStruct - MQL4 Documentation

struct_object

[in] Reference to the object of this structure. The structure should not contain strings, dynamic arrays or virtual functions.

Shaun Overton
104
Shaun Overton 2015.12.22 21:49  

Can I convert the string to bytes or another data type so that I don't lose the information?

 WHRoeder, there's no reason to be rude. It was an honest oversight. I modeled my code on the documentation... I obviously read the manual. Snotty remarks like yours are the reason people don't ask questions when they need help. 

Ovo Cz
2963
Ovo Cz 2015.12.22 21:56  
Use char[12] instead, 12 is max length of a symbol.
Demos Stogios
184
Demos Stogios 2015.12.22 22:58  
texasnomad:

Can I convert the string to bytes or another data type so that I don't lose the information?

 WHRoeder, there's no reason to be rude. It was an honest oversight. I modeled my code on the documentation... I obviously read the manual. Snotty remarks like yours are the reason people don't ask questions when they need help. 

hello,

regarding RTFM i may say that i find it to be in the funny side - at least for me ; some years before (ahem) whenever i was facing that epxression, I got the impression that it was used in a friendly manner , coming from a positive stance and also humorous :) I could use it in a similar manner on my own - a rather geeky approach if you ask me but quite common to computer users , but again, not in a bad attitude ( i guess :) )

Ovo Cz
2963
Ovo Cz 2015.12.23 12:57  
Demos:

hello,

regarding RTFM i may say that i find it to be in the funny side - at least for me ; some years before (ahem) whenever i was facing that epxression, I got the impression that it was used in a friendly manner , coming from a positive stance and also humorous :) I could use it in a similar manner on my own - a rather geeky approach if you ask me but quite common to computer users , but again, not in a bad attitude ( i guess :) )

 

Well, you may use it both ways, I think. A good advice and expressing contempt.

Anyway, I still have a bug report pending at Service Desk since 2014.08.28 - the third parameter always gets trimmed to the sizeof of declared structure. I.e. it invalidates structure inheritance, and actually the parameter becomes very useless.

Shaun Overton
104
Shaun Overton 2015.12.28 16:58  
Ovo:
Use char[12] instead, 12 is max length of a symbol.
Thanks!
/
To add comments, please log in or register