Ideas of dealing with position attributes in hedging account

 

Hello Traders,

so far in my EAs it was only possible to have one postion in each direction at the same time. I am saving position attributes like "BuyStopDistance" in global variables.  Now I am working on a EA which requires to have multiple positions in the same direction. To manage all positions I have a loop in the OnTick which goes through all positions. The problem is I can not safe attributes in global variables any more since I do not know how many positions will be opened during the session.


I know I can access some position attributes by "PositionGetDouble()" but not all that I need. Is there a possibility to add more entries in pre-defined enumerations like "ENUM_POSITION_PROPERTY_DOUBLE" ?

Or do  you have general ideas how to access related data to open positions, which are not included in the standard enumeration like the initial stop distance?


I appreciate any kind of help. Thank you!

 

You should think about a name creating function that uses program name, symbol, timeframe, identifier and some number to create global variable names. You can use the same function to run through names to check or get global variable values. If you make an enum from identifiers, you can have a loop go through that too.

enum ENUM_GLOB_IDENTIFIER
  {
   GLOB_ID_PRICE,
   GLOB_ID_SL,
   GLOB_ID_TP,
   GLOB_ID_OPEN
  };

string sep = ",";

//+-------------------------------------------------------------------------+
//| namecreate function, return value string name|
//+-------------------------------------------------------------------------+
string namecreate(int pos_index, ENUM_GLOB_IDENTIFIER id)
  {return(MQLInfoString(MQL_PROGRAM_NAME) + sep + _Symbol + sep + EnumToString(_Period) + sep + EnumToString(id) + sep + string(pos_index));}
//+-------------------------------------------------------------------------+
 
Tobias Johannes Zimmer #:
… EnumToString(id) + sep + string(pos_index));}

Do not use as-series indexes. You will create, for example, Name₀, and then on a new bar try to create another. Always use non-series indexes (or time) in names and remembered candles.

#define  SERIES(I)   (Bars(_Symbol,_Period) - 1 - I) // As-series to non-series or back.
 
Tobias Johannes Zimmer #:

You should think about a name creating function that uses program name, symbol, timeframe, identifier and some number to create global variable names. You can use the same function to run through names to check or get global variable values. If you make an enum from identifiers, you can have a loop go through that too.

Thank you very much! But for my case I do not understand how to make the new name to a global variable? I tried "GlobalVaribleSet()", but it seems to be not allowed  to use inside functions. How do you use this new created variable name? And how can I add the value I would like to store inside?

Reason: