How to make ea open orders on several pairs with a click from one chart window?

 

Hello Gurus in the house,


Please I need your help in solving this nagging problem of assigning each name of pairs to OrderSend function to open, I was able to call all the symbols from the market watch but to assign a particular pair for each OrderSend is the problem, it was just picking all the symbols and buying them all but I want it to buy/sell a few that I will assign to it with variables. Below is the codes I have gotten so far:


string Symbolgroup_1[]; 

int init() {
 
 //-----
 
 int iCount=SymbolsTotal(true); // true, the function returns the number of symbols selected in MarketWatch.
      ArrayResize(Symbolgroup_1,iCount);
      Print("Symbols Count: ",iCount);
      int i;
      for(i=0; i<iCount; i++) {
 Symbolgroup_1[i]=SymbolName(i,true); // the symbol is taken from the list of symbols selected in MarketWatch.
        }
  return(INIT_SUCCEEDED);
  }

////////////////////////////////////////////////
//Within the chartevent object button click area

if(id==CHARTEVENT_OBJECT_CLICK) {  
   
//----
   string name="USDBasketBuy";
   if(ObjectGetInteger(0,name,OBJPROP_STATE)==true) { 
   ObjectSetInteger(0,name,OBJPROP_STATE,false);
 
 int size_1=ArraySize(Symbolgroup_1);
 for(int i=0; i<size_1; i++) {    //
   
  string  symbol_01=SymbolName(i,true);
    
    Alert("Our Symbols are "+symbol_01); 
    
   double ask=MarketInfo(symbol_01,MODE_ASK);

   RefreshRates();

   res=OrderSend(symbol_01,OP_BUY,LotB,ask,1,0,0,"",MagicNo,0,Green); 

    }  
  }  
}


After clicking the button on the chart, it will just open buy orders for all the symbols present in the market watch panel. Please what do I do or How do I assign specific group of pairs for opening without opening all?

However, I did something like this:

if(id==CHARTEVENT_OBJECT_CLICK) {  
   
//----
   string name="USDBasketBuy";
   if(ObjectGetInteger(0,name,OBJPROP_STATE)==true) { 
   ObjectSetInteger(0,name,OBJPROP_STATE,false);

RefreshRates();
   res=OrderSend("USDCAD",OP_BUY,LotB,Ask,1,0,0,"",MagicNo,0,Green);
   res=OrderSend("USDJPY",OP_BUY,LotB,Ask,1,0,0,"",MagicNo,0,Green);
   res=OrderSend("USDCHF",OP_BUY,LotB,Ask,1,0,0,"",MagicNo,0,Green);
   res=OrderSend("GBPUSD",OP_SELL,LotB,Bid,1,0,0,"",MagicNo,0,Red);
   res=OrderSend("AUDUSD",OP_SELL,LotB,Bid,1,0,0,"",MagicNo,0,Red);
   res=OrderSend("NZDUSD",OP_SELL,LotB,Bid,1,0,0,"",MagicNo,0,Red);
   res=OrderSend("EURUSD",OP_SELL,LotB,Bid,1,0,0,"",MagicNo,0,Red);

Print("All orders opened successfully!");
   }
 }
Although this one worked perfectly only on demo account but it didn't work on my real trading account, it was just throwing 4106 error. Please what codes do I add to make it work? Thanks in advance for your assistance
 
Olufemi Adeyemo:

Please I need your help in solving this nagging problem of assigning each name of pairs to OrderSend function to open, I was able to call all the symbols from the market watch but to assign a particular pair for each OrderSend is the problem, it was just picking all the symbols and buying them all but I want it to buy/sell a few that I will assign to it with variables. Below is the codes I have gotten so far:

4106 for mt4 means "unknown symbol" - check your symbol names, or upload a screenshot of your market watch so we know you've got the symbol names right...

 
Seng Joo Thio:

4106 for mt4 means "unknown symbol" - check your symbol names, or upload a screenshot of your market watch so we know you've got the symbol names right...

4106, Yes I know. i got the symbol pairs right but please read my question from the beginning and you will understand what i am saying. Thanks anyway
 
Can not do this.
 
Olufemi Adeyemo:
4106, Yes I know. i got the symbol pairs right but please read my question from the beginning and you will understand what i am saying. Thanks anyway

Well, you want to open orders for those pairs that you choose - am I right? To get any useful reply you'll have to let us know HOW you prefer to make the selection? Do you prefer a dialog box with checkboxes? Or an array which you hardcode? Or read from a text file? As far as I'm concerned, that is the EASY and STRAIGHTFORWARD part.

4106 is the main problem here - and you've mentioned that the same code behaved differently when run on demo and your life account (tell-tale sign that the code works). So if you cannot get rid of the 4106 error, what's the point of creating a sub-list of pairs? Then you'll end up blaming the sub-list?

Hope someone else will see things from your perspective... I've tried, and let's take it that I failed to understand what you're saying.

 
Seng Joo Thio:

Well, you want to open orders for those pairs that you choose - am I right? To get any useful reply you'll have to let us know HOW you prefer to make the selection? Do you prefer a dialog box with checkboxes? Or an array which you hardcode? Or read from a text file? As far as I'm concerned, that is the EASY and STRAIGHTFORWARD part.

4106 is the main problem here - and you've mentioned that the same code behaved differently when run on demo and your life account (tell-tale sign that the code works). So if you cannot get rid of the 4106 error, what's the point of creating a sub-list of pairs? Then you'll end up blaming the sub-list?

Hope someone else will see things from your perspective... I've tried, and let's take it that I failed to understand what you're saying.

Thanks for your concern, I really appreciate it. Yes, I used an array of just those pairs so that it will not open all other symbols in the market watch but all it saying is error 4106 and that the symbol could not be found. The codes especially, the second one works perfectly on demo so I was thinking maybe it might be my broker or the kind of account I am using (micro account of fxopen).
 
 if (id== CHARTEVENT_OBJECT_CLICK ) {  
   
   string name="USDBasketBuy";
   if(ObjectGetInteger(0,name,OBJPROP_STATE)==true) 
     {
      ObjectSetInteger(0,name,OBJPROP_STATE,false);

      RefreshRates();
      struct symbols
        {
         string s;
         color  c;
        };
      symbols Symbols[]=
        {
           {"USDCAD",Green},
           {"USDJPY",Green},
           {"USDCHF",Green},
           {"GBPUSD",Red},
           {"AUDUSD",Red},
           {"NZDUSD",Red},
           {"EURUSD",Red}
        };
      for(int i=0; i<7; i++)
         res=OrderSend(Symbols[i].s,OP_BUY,LotB,Ask,1,0,0,"",MagicNo,0,Symbols[i].c);

      Print("All orders opened successfully!");
     }
Possible so
 
Konstantin Nikitin:
Possible so

Thanks for this piece. Tried it and it returned all the selected pairs as expected but it didn't send the pairs' orders, only returning error 4106

I believe there is more you can do for me to make it work.

While waiting, thanks so much, I am grateful

 
      symbols Symbols[]=
        {
           {addSymbol("USDCAD"),Green},
           {addSymbol("USDJPY"),Green},
           {addSymbol("USDCHF"),Green},
           {addSymbol("GBPUSD"),Red},
           {addSymbol("AUDUSD"),Red},
           {addSymbol("NZDUSD"),Red},
           {addSymbol("EURUSD"),Red}
        };

//------------------------
string addSymbol(const string _symbol)
{
        if(_symbol == "")
                return _Symbol;
//---
        int total = SymbolsTotal(false);
        string symbol = _symbol;
        bool p = StringToUpper(symbol);
        for(int i=0; i<total; i++)
        {
                string _s = SymbolName(i, false);
                p = StringToUpper( _s );
                if(     _s != symbol &&
                        StringFind(symbol, _s, 0) < 0 &&
                        StringFind(_s, symbol, 0) < 0) continue;
                
                symbol = SymbolName(i, false);
                break;
        }
        if( !SymbolSelect(symbol, true) )
                return _Symbol;
//---
        return symbol;
}

I can't read minds.
Need to see code. Something to fix.
I can only assume. That you have something with symbols.

 
Konstantin Nikitin:

I can't read minds.
Need to see code. Something to fix.
I can only assume. That you have something with symbols.


I tried to work around it and this is what I got:

fx1

Is there any solution to this? Thanks for your time, you are blessed

 
Olufemi Adeyemo:

I tried to work around it and this is what I got:

Is there any solution to this? Thanks for your time, you are blessed

addSymbol function copied?
Reason: