Download MetaTrader 5
To add comments, please log in or register
Add our channel to friends and follow the news!
Don
6
Don 2016.03.08 18:00 

I am trying to code an EA, that will check for certain criteria across multiple currencies, and if they are satisfied open a trade. To try and get the code to work the only criteria I am currently using is open a new bar (I'll add more when I can get this bit to work). I'm also limiting it to 3 currencies, though more can be added later.

The code I have is:

string CurrencySymbol[3] = {"AUDCAD", "EURUSD", "GBPJPY"};

 if (Bars(0,PERIOD_M1) != ThisBarTrade)
   {
   ThisBarTrade = Bars(0,PERIOD_M1);  // ensure only one trade opportunity per bar
  
   for (int i=0; 2; i++)
      {
      LastClose = iClose(CurrencySymbol[i],PERIOD_M1,1);
      LastHigh = iHigh(CurrencySymbol[i],PERIOD_M1,1);
      LastLow = iLow(CurrencySymbol[i],PERIOD_M1,1);
      OrderSend(CurrencySymbol[i],OP_BUYSTOP,0.01,LastHigh,3,0,0,"Don",12345,0,Green);
      }

   }

This is attached to EURUSD chart, but instead of opening 3 trades one for each symbol, it just opens the EURUSD trade.


I thought this would work, but can't work out why not, can anybody offer any suggestions please?

Also, for pending orders there is the ability to have it close automatically if not triggered be the required time. What parameters does this take? is it seconds, or do you put in a date and time etc?

Vasyl Nosal
18218
Vasyl Nosal 2016.03.08 19:24  

for (int i=0; 2

What is it? 

 

and create buffer for new bars for different pairs

Bars(0,PERIOD_M1 

whroeder1
13641
whroeder1 2016.03.08 19:37  
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. string CurrencySymbol[3] = {"AUDCAD", "EURUSD", "GBPJPY"};
    Are all three in market watch?
  3. Tester?
    Do not trade multiple currencies
    • You can't use any predefined variables, can't use the tester, must poll (not OnTick,) and usually other problems.
    • Code it to trade the chart pair only. Look at the others if you must.
    • Then put it on other charts to trade the other pairs. Done.

  4. for (int i=0; 2; i++)
    infinite loop
  5. OrderSend(CurrencySymbol[i],OP_BUYSTOP,0.01,LastHigh,3,0,0,"Don",12345,0,Green);
    Check your return codes (OrderSend) and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
/
To add comments, please log in or register