I want to modify Macd Sample for multiple currency pairs trading .

 

Hello;

I want to modify the known expert advisor ((Macd Sample)), I have added a stop loss and a magicnumber and modified the code to allow trading in multiple currency pairs in the same time by adding a variable ((compteur)), the problem is that this code do not open any trade on backtests .

The code is in attached files.

Sorry for mistakes because English is my fifth language.

Thank You for help.

 
ziko750:

Hello;

, the problem is that this code do not open any trade on backtests .


Why ? is it because the conditions needed to open an order are not met ? is it because the order is not placed correctly ? what have you discovered already ?
 
RaptorUK:
Why ? is it because the conditions needed to open an order are not met ? is it because the order is not placed correctly ? what have you discovered already ?


I have no idea .

I just modifed those parts of the initial code .

---->first

I declared stop and magicnumber ((no problem))

extern double StopLoss = 50;
extern int MagicNumber = 12345;

---->inside int start() declared two other variable

int compteur=0;
string aide=Symbol();

----> Then calculated the number of trades by currency and added a condition for opening just one trade by currency

total=OrdersTotal();
   for(int i=0; i<total; i++)
    {
    if(OrderSelect(i, SELECT_BY_POS)==false) continue;
    if(OrderSymbol()==aide) compteur++;
    }
if(compteur<1) 

---> ordersend with stop loss and magicnumber

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"macd sample",MagicNumber,0,Green);

and

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"macd sample",MagicNumber,0,Red);
 
ziko750:


I have no idea .

Don't you think you should try to find out ? Maybe add some print statements, re-run the code, see what the results of the print statements tell you ? it's not rocket science . . .

For example . . .

Print("MacdCurrent=  ",MacdCurrent," SignalCurrent= ",SignalCurrent," MacdPrevious= ",MacdPrevious," SignalPrevious= ",SignalPrevious," MathAbs(MacdCurrent)= ",MathAbs(MacdCurrent),
" (MACDOpenLevel*Point)= ",(MACDOpenLevel*Point));   //  <----------------------------------------------


if(MacdCurrent<0 && MacdCurrent>SignalCurrent && MacdPrevious<SignalPrevious &&
         MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious)
        {
         Print("Try to open Buy order");  //  <----------------------------------------------
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"macd sample",MagicNumber,0,Green);
         if(ticket>0)
 
ziko750:

Hello;

the problem is that this code do not open any trade on backtests .


Yes it does !

 

I will add comments, but firstly the EA must work, I don't know what is the problem !!!, the initial EA has good result in backtests and forward tests but it open only one trade in one currency and does not use stop loss, I really don't know why metaquotes programmer coded the EA in this way .

Files:
 
RaptorUK:

Yes it does !


Is it openning trades in your MT4 !!
 
ziko750:

Is it openning trades in your MT4 !!
Yes, look at the chart posted ! Lots of orders, account balance falls quickly.
 
ziko750:

I will add comments, but firstly the EA must work, I don't know what is the problem !!!,

The Print statements are NOT comments . . they are debugging info to help you find where the PROBLEM is . . . add the print statements, run the code, look in the Journal tab of the Strategy tester.
 

Ok I will see that then I will be back .

Thank you for your help RaptorUK .

 

thank you very much raptoruk now I have found the mistake and it's trading .

Reason: