What is the best way store Data for every trade into MQL Code.

 

Dear,


I want to store a some data for every trade into my Expert Advisor coding, so EA can use that data to control those trade. As i know several option to save data but all are not good all. 


1. Save into Variable.

I can save data into variable but problem is that if expart remove from chart, EA loss that data so it is not working with me.


2. Save into Global variable

but there also have problem. Global variable store with terminal, if terminal move i also loss that save data, also global variable can store data max 4 week, if terminal off for more then 4 week then i also loss data. 


3. Save data into trade comments

This is best for me, data will be store with trade, so when every your attach EA on chart you will get save data. It is the best for me, but there also i found a problem. Some broker are edit trade comments when pending order active into trade. If broker change comment, i loss all my save data.


4. More better solution ?

I need help is anyone know more better solution to save data without using comment so EA re attach on chart and get the previous data. 

 
Mohammad Ali:

Dear,


I want to store a some data for every trade into my Expert Advisor coding, so EA can use that data to control those trade. As i know several option to save data but all are not good all. 


1. Save into Variable.

I can save data into variable but problem is that if expart remove from chart, EA loss that data so it is not working with me.


2. Save into Global variable

but there also have problem. Global variable store with terminal, if terminal move i also loss that save data, also global variable can store data max 4 week, if terminal off for more then 4 week then i also loss data. 


3. Save data into trade comments

This is best for me, data will be store with trade, so when every your attach EA on chart you will get save data. It is the best for me, but there also i found a problem. Some broker are edit trade comments when pending order active into trade. If broker change comment, i loss all my save data.


4. More better solution ?

I need help is anyone know more better solution to save data without using comment so EA re attach on chart and get the previous data. 

write the data you need in a temp log file. The temp file will stay on the disk forever so you can get that data back anytime you want

Jeff

 
It's to use arrays
 
Mohammad Ali:

Dear,


I want to store a some data for every trade into my Expert Advisor coding, so EA can use that data to control those trade. As i know several option to save data but all are not good all. 


1. Save into Variable.

I can save data into variable but problem is that if expart remove from chart, EA loss that data so it is not working with me.


2. Save into Global variable

but there also have problem. Global variable store with terminal, if terminal move i also loss that save data, also global variable can store data max 4 week, if terminal off for more then 4 week then i also loss data. 


3. Save data into trade comments

This is best for me, data will be store with trade, so when every your attach EA on chart you will get save data. It is the best for me, but there also i found a problem. Some broker are edit trade comments when pending order active into trade. If broker change comment, i loss all my save data.


4. More better solution ?

I need help is anyone know more better solution to save data without using comment so EA re attach on chart and get the previous data. 

If there's a lot of trades you would like to store, forget the arrays, a temp file used to be the best approach .... before the implementation of sqlite ! 

With SQL you can retrieve range of data, based on date interval or by specific item ... that's really the best way to do it nowadays ! I didn't yet implemented it in my metatraders' stuff because I'm not sure it's supported by the tester (that way you'll tell me lol) but I widely use it in my medical projects ! 

I guarantee you won't reget !

https://www.mql5.com/en/articles/7463

SQLite: Native handling of SQL databases in MQL5
SQLite: Native handling of SQL databases in MQL5
  • www.mql5.com
MQL5 is a perfect solution for algorithmic trading since it is as close to C++ as possible in terms of both syntax and computation speed. The MetaTrader 5 platform offers its users the modern specialized language for developing trading robots and custom indicators allowing them to go beyond simple trading tasks and create analytical systems of...
 
ffoorr:
It's to use arrays


Array will be remove when EA remove from chart

 
ffoorr:
It's to use arrays

then write the arrays in a temp file ! not that hard

 
Mohammad Ali:


Array will be remove when EA remove from chart

s-q-l. did you tried it ? does it work inside the tester ?  

Reason: