Naming an array after variables

 
I am trying to name an array after some variables, something like this
string symbol = "AUDCAD" ;
string type = "BUY" ;
double symbol + type[ ] ;

ArrayResize( AUDCADBUY , 1 ) ;
AUDCADBUY[ 0 ] = 1 ;


This doesn't work though, and I haven't been able to find anything anywhere to point me in the right direction.

 
0Tom:
I am trying to name an array after some variables, something like this

This doesn't work though, and I haven't been able to find anything anywhere to point me in the right direction.

Define an array for each symbol + type:
double AUDCAD_BUY[];


 
Mohammad Hossein Sadeghi:
Define an array for each symbol + type:


Hmm yes, not quite what I'm looking for but I guess this will suffice.
 
0Tom:
Hmm yes, not quite what I'm looking for but I guess this will suffice.

So what are you looking for? It's not quite clear from your post.

 
lippmaje:

So what are you looking for? It's not quite clear from your post.

So what I'm trying to add to my EA is that every tick it goes through all the open orders, for each open order it checks it's symbol, and then checks if there is already an array named after the symbol, if there isn't it creates an array named after the symbol (this is the part I'm not sure how to do, or if it is even possible on MQL4) and puts that orders ticket/position in the array, if there is already an array named after that symbol it puts the order ticket/position in that array. It will also check if the orders are buy or sell and add that onto the name of the array, although this can be ignored for now. What Mohammad suggested should work fine and that is what I will do for now but it means I'll have to make it so that the EA makes 54 empty arrays (a buy and sell array for each major currency pair) every tick before filling some of them up, which won't look nice on the code. I can post my code if you want although it's quite messy, and it shouldn't really be necessary as this question isn't specific to my EA.
 
0Tom:
So what I'm trying to add to my EA is that every tick it goes through all the open orders, for each open order it checks it's symbol, and then checks if there is already an array named after the symbol, if there isn't it creates an array named after the symbol (this is the part I'm not sure how to do, or if it is even possible on MQL4) and puts that orders ticket/position in the array, if there is already an array named after that symbol it puts the order ticket/position in that array. It will also check if the orders are buy or sell and add that onto the name of the array, although this can be ignored for now. What Mohammad suggested should work fine and that is what I will do for now but it means I'll have to make it so that the EA makes 54 empty arrays (a buy and sell array for each major currency pair) every tick before filling some of them up, which won't look nice on the code. I can post my code if you want although it's quite messy, and it shouldn't really be necessary as this question isn't specific to my EA.
dynamic string array of symbols, dynamic struct array containing array of ticket numbers (one to one map against struct array index)
 
Sardion Maranatha:
dynamic string array of symbols, dynamic struct array containing array of ticket numbers (one to one map against struct array index)
Hi, could you elaborate please?
 
I coded mql 5 expert adviser, it enters the transaction at the moving average intersections, everything like the trailing stop is working but after the position is closed, I want it to not open a transaction again if there is no signal after a certain pips. Can you help me with this issue. Thank you.
 
ümit gün:
I coded mql 5 expert adviser, it enters the transaction at the moving average intersections, everything like the trailing stop is working but after the position is closed, I want it to not open a transaction again if there is no signal after a certain pips. Can you help me with this issue. Thank you.

Why have you posted in the MQL4 section??

 
0Tom:
Hi, could you elaborate please?
//+------------------------------------------------------------------+
//|                                MultiSymAndEntriesAssociative.mq5 |
//|                                     Copyright 2021, Rosh Jardine |
//|                                          https://roshjardine.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, Rosh Jardine"
#property link      "https://roshjardine.com"
#property version   "1.00"
//+------------------------------------------------------------------+
//--- based on https://www.mql5.com/en/forum/365805

string TradedSymbols[];
struct TradedEntriesStruct
{
  ulong BuyPosNo[];
  ulong SellPosNo[];
  void Insert(ulong ArgTicketNo,bool ArgEntryBuy) 
  { 
    if (ArgEntryBuy)
    {
      int BuySize = ArraySize(BuyPosNo); 
      ArrayResize(BuyPosNo,BuySize+1);
      BuyPosNo[BuySize] = ArgTicketNo;
    }
    else 
    {
      int SellSize = ArraySize(SellPosNo); 
      ArrayResize(SellPosNo,SellSize+1);
      SellPosNo[SellSize] = ArgTicketNo;
    }
  }
};
TradedEntriesStruct TradedEntries[];
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
  //--- OnTick
  string CurrSymbol = Symbol();
  string NextSymbol = "GBPUSD";
  string CheckSymbol = "EURUSD";
  
  int CurrSymbolIdx = 0;
  int NextSymbolIdx = 0;
  int CheckSymbolIdx = 0;
  
  CheckTradedSymbolExist(TradedSymbols,CurrSymbol,CurrSymbolIdx);
  CheckTradedSymbolExist(TradedSymbols,NextSymbol,NextSymbolIdx);
  CheckTradedSymbolExist(TradedSymbols,CheckSymbol,CheckSymbolIdx);
  //--- Buy
  TradedEntries[CurrSymbolIdx].Insert(ulong(1),true);
  TradedEntries[NextSymbolIdx].Insert(ulong(3),true);
  //--- append buy ticket to exisiting symbol
  TradedEntries[CheckSymbolIdx].Insert(ulong(5),true);
  
  //--- Sell
  TradedEntries[CurrSymbolIdx].Insert(ulong(2),false);
  TradedEntries[NextSymbolIdx].Insert(ulong(4),false);
  //--- append sell ticket to exisiting symbol
  TradedEntries[CheckSymbolIdx].Insert(ulong(6),false);
  
  #ifdef __MQL5__
  ArrayPrint(TradedSymbols);  
  ArrayPrint(TradedEntries[CurrSymbolIdx].BuyPosNo);
  ArrayPrint(TradedEntries[CurrSymbolIdx].SellPosNo);
  ArrayPrint(TradedEntries[NextSymbolIdx].BuyPosNo);
  ArrayPrint(TradedEntries[NextSymbolIdx].SellPosNo);
  ArrayPrint(TradedEntries[CheckSymbolIdx].BuyPosNo);
  ArrayPrint(TradedEntries[CheckSymbolIdx].SellPosNo);
  #endif
  //--- for MQL4, do your own loop
  
  //--- since this is for testing purpose running on script, freeing up the arrays is necessary
  ArrayFree(TradedSymbols);
  ZeroMemory(TradedEntries);
  //---
  
  }
//+------------------------------------------------------------------+

void CheckTradedSymbolExist(string &Sym[],const string ArgSymbol,int &ArgSymbolIdx)
{
  int SymSize = ArraySize(Sym);
  if (SymSize<1)
  {
    ArrayResize(Sym,SymSize+1);
    ArrayResize(TradedEntries,SymSize+1);
    Sym[SymSize] = ArgSymbol;
    ArgSymbolIdx = 0;
    return;
  }
  else 
  {
    bool Found = false;
    for (int i=0;i<SymSize;i++)
    {
      if (ArgSymbol==Sym[i])
      {
        ArgSymbolIdx = i;
        Found = true;
        return;
      }
    }
    if (!Found)
    {
      ArrayResize(Sym,SymSize+1);
      ArrayResize(TradedEntries,SymSize+1);
      Sym[SymSize] = ArgSymbol;
      ArgSymbolIdx = SymSize;
    }
  }
}

don't use as is but improve / revise to serve your purpose

Reason: