How to get the previous Stop Loss of the opened position? - page 2

jaffer wilson
3593
jaffer wilson  
Chris70:

Even if you don't find the necessary information in the deal history, it should't be a big deal to make the EA keep track of the stop loss history by itself and store it in an array and/or save it permanently in a file.

Will the file not make the process slow? I am trying to make the process lightening fast so I can even go for scalping as my broker is offering that facility to me. But everytime opening, searching and closing will make the process of buying and selling slow. That's why I thought if there is anything that I missed, I thought I can ask about it.

Aidin Hasanoghli
142
Aidin Hasanoghli  
jaffer wilson:

Will the file not make the process slow? I am trying to make the process lightening fast so I can even go for scalping as my broker is offering that facility to me. But everytime opening, searching and closing will make the process of buying and selling slow. That's why I thought if there is anything that I missed, I thought I can ask about it.

why don't you make an array including the Order Ticket, SL modification counter and respective SL value. you can store it later when the order was closed in the file, in this case opening and closing of the file will be minimized and process of the EA will not slow down.

jaffer wilson
3593
jaffer wilson  
Aidin Hasanoghli:

why don't you make an array including the Order Ticket, SL modification counter and respective SL value. you can store it later when the order was closed in the file, in this case opening and closing of the file will be minimized and process of the EA will not slow down.

I will try. But that might need a lot resources. May be. But still I will try. Thank you for the suggestion.

Chris70
544
Chris70  
jaffer wilson:

I will try. But that might need a lot resources. May be. But still I will try. Thank you for the suggestion.

You'd be surprised how fast the file operations actually are. This in mind, what affects performance a little is frequent use of FileFlush or frequent closing and reopening, which isn't necessary if you just leave the file open (and combine FILE_READ and FILE_WRITE flags) and close it in OnDeinit. However, I still wouldn't recommend this! I'd distinguish between realtime storing as arrays and less frequent harddrive backups, that you could e.g. schedule via OnTimer events e.g. every couple of minutes (only for safety, if e.g. you need to restart your EA without losing the data). But I wouldn't recommend saving with every call of OnTick.

Instead, I'd suggest using a struct array like

struct SL_HISTORY
  {
   double               sl;
   datetime             time;
   long                 position_ticket;
   ENUM_POSITION_TYPE   type;
  };

SL_HISTORY sl_history[];

for the regular temporary storage and then for the occasional backup using a .bin file (--> FILE_BIN flag) with FileWriteArray(file_handle,sl_history). What's nice is that FileWriteArray also can deal with struct arrays, so you need just one line of code to save the entire sl history.

jaffer wilson
3593
jaffer wilson  
Chris70:

You'd be surprised how fast the file operations actually are. This in mind, what affects performance a little is frequent use of FileFlush or frequent closing and reopening, which isn't necessary if you just leave the file open (and combine FILE_READ and FILE_WRITE flags) and close it in OnDeinit. However, I still wouldn't recommend this! I'd distinguish between realtime storing as arrays and less frequent harddrive backups, that you could e.g. schedule via OnTimer events e.g. every couple of minutes (only for safety, if e.g. you need to restart your EA without losing the data). But I wouldn't recommend saving with every call of OnTick.

Instead, I'd suggest using a struct array like

for the regular temporary storage and then for the occasional backup using a .bin file (--> FILE_BIN flag) with FileWriteArray(file_handle,sl_history). What's nice is that FileWriteArray also can deal with struct arrays, so you need just one line of code to save the entire sl history.

Thank you for your help. This could be a good suggestion. I thought that MQL5 might have something else. But I guess it need to be created on our own. Your suggestion is really appreciated.

Mahdi Ebrahimzadeh
2952
Mahdi Ebrahimzadeh  

I have same issue!! I'm going to code an OnTester Function to optimization purpose to add every EA without any need to use File operations, Array define or track during Code running, just end of each optimization cycle, I need to access SL of entry in deals (DEAL_ENTRY_IN) as initial SL of each trade which was executed! 


As a reminder,

1) I can not use File operation and storage during main cycle of EA runs

2) I can not track trades during main cycle of EA runs by Arrays, Write in comment or any other idea that suggests during running main body of EA and Trade cycle. Just inside of OnTester() function which is end of EA.


Thanks 

[Deleted]  
Chris70:

You'd be surprised how fast the file operations actually are. This in mind, what affects performance a little is frequent use of FileFlush or frequent closing and reopening, which isn't necessary if you just leave the file open (and combine FILE_READ and FILE_WRITE flags) and close it in OnDeinit. However, I still wouldn't recommend this! I'd distinguish between realtime storing as arrays and less frequent harddrive backups, that you could e.g. schedule via OnTimer events e.g. every couple of minutes (only for safety, if e.g. you need to restart your EA without losing the data). But I wouldn't recommend saving with every call of OnTick.

Instead, I'd suggest using a struct array like

for the regular temporary storage and then for the occasional backup using a .bin file (--> FILE_BIN flag) with FileWriteArray(file_handle,sl_history). What's nice is that FileWriteArray also can deal with struct arrays, so you need just one line of code to save the entire sl history.

Thanks for your suggestions. Its really very helpful for new traders.