EA Coding support !

 

Hi All

Can you help me ?

i wanna to know how to write a code that can make my EA able to open more than one trade (not in the same pair) on a different pairs at the same time if the condition is valid

the following code is the MACD sample EA i wanna to know what is the code that i should channge to make the EA able to open several trades at the same time on a different currencies?

appreciate your help very much

//========================================================

total=OrdersTotal();

if(total<1)

{

// no opened orders identified

if(AccountFreeMargin()<(1000*Lots))

{

Print("We have no money. Free Margin = ", AccountFreeMargin());

return(0);

}

// check for long position (BUY) possibility

if(MacdCurrentSignalCurrent && MacdPrevious<SignalPrevious &&

MathAbs(MacdCurrent)>(MACDOpenLevel*Point) && MaCurrent>MaPrevious)

{

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

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());

return(0);

}

// check for short position (SELL) possibility

if(MacdCurrent>0 && MacdCurrentSignalPrevious &&

MacdCurrent>(MACDOpenLevel*Point) && MaCurrent<MaPrevious)

{

ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,"macd sample",16384,0,Red);

if(ticket>0)

{

if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());

}

else Print("Error opening SELL order : ",GetLastError());

return(0);

}

return(0);

}

 

Hi WAW

Are you talking about the original MACD Sample included in MT4?

Right now I'm looking at its code and I can see that it works on multiple pairs.

If the entry conditions are met, the EA will open a position, no matter if there are any other position open or not.

You don't have to modify the EA.

Btw, the code you pasted here isn't the the part where the EA checks if there are any open positions.

Bye.

 
cucurucu:
Are you talking about the original MACD Sample included in MT4?

Right now I'm looking at its code and I can see that it works on multiple pairs.

If the entry conditions are met, the EA will open a position, no matter if there are any other position open or not.

You don't have to modify the EA.

Btw, the code you pasted here isn't the the part where the EA checks if there are any open positions.

Bye.

Hi Cucurucu

IF You mean the code down below, it is as i undestand for trailing stop check but not effect on what i have asked ,

Actualy if u tried the EA u will found that it opens only one trade per time on one currency only

//==================================================

// it is important to enter the market correctly,

// but it is more important to exit it correctly...

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()<=OP_SELL && // check for opened position

OrderSymbol()==Symbol()) // check for symbol

{

if(OrderType()==OP_BUY) // long position is opened

{

// should it be closed?

if(MacdC(MACDCloseLevel*Point))

{

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position

return(0); // exit

}

// check for trailing stop

if(TrailingStop>0)

{

if(Bid-OrderOpenPrice()>Point*TrailingStop)

{

if(OrderStopLoss()<Bid-Point*TrailingStop)

{

OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);

return(0);

}

}

}

}

else // go to short position

{

// should it be closed?

if(MacdC>MacdP && MathAbs(MacdC)>(MACDCloseLevel*Point))

{

OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position

return(0); // exit

}

// check for trailing stop

if(TrailingStop>0)

{

if((OrderOpenPrice()-Ask)>(Point*TrailingStop))

{

if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))

{

} OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);

return(0);

}

}

 

I have double checked it and I don't see any code to allow only 1 single trade. When the entry conditions are met, it will enter. When the exit conditions are met, it will check the Symbol and close only the right currency pair.

I have tested this EA myself (some time ago) and I have attached it to multiple pair simultaneously. For me, it worked. The code is right. I don't see the problem.

Could you post a screenshot of a situation when you think that the EA should open a trade and it doesn't? Pls.

Please note that there are extra conditions for entry (besides MACD crossing the signal line).

The EA does open the positions only in the direction of the EMA26 (MATrendPeriod). So, if the MACD is giving a buy signal, but the EMA26 isn't going up, it will not trade.

For shorts, the MACD must be above 0 and it must cross the signal line downwards. For longs, the MACD must be below 0 and it must cross the signal line upwards.

If you find any situations when you think that the EA should have open a trade, please post a screenshot.

Bye.

 

Hi Waw

this is the part limit the EA to Open another Order on different currency

total=OrdersTotal();

if(total<1)

{

}

this part Count Total orders on all currencies, one solution is apart currencies from each other, like the code below:

int EAtotal=0;

total=OrderTotal();

For (int i=0,i<total,i++)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol() = Symbol()) EAtotal++;

}

if (EAtotal<1)

{

Continue your continuation code here

}

i prefer to replace the bolded Area with:

if (EAtotal>0) return(0);

Continue your continuation code after this part

 

Yes. Now I see that

if(total<1)

{

}

You are right. I'm sorry. This is the "problem" which won't let the EA open more than 1 trade.

I have modified the MACD Sample and I'm attaching the MACD Multi.

Please let me know if it's ok. I don't have time to test it.

Bye.

Files:
 
intelligent_14:
this is the part limit the EA to Open another Order on different currency

total=OrdersTotal();

if(total<1)

{

}

this part Count Total orders on all currencies, one solution is apart currencies from each other, like the code below:

int EAtotal=0;

total=OrderTotal();

For (int i=0,i<total,i++)

{

OrderSelect(i,SELECT_BY_POS,MODE_TRADES);

if (OrderSymbol() = Symbol()) EAtotal++;

}

if (EAtotal<1)

{

Continue your continuation code here

}

i prefer to replace the bolded Area with:

if (EAtotal>0) return(0);

Continue your continuation code after this part

daer intelligent_14

alsalam alekoum wa rahmat allaha

I don't know how to thank you, i really appreciate your support and help

i do wish if i you add me to your yahoo massenger my e-mail is waw4you@yahoo.com,

 
cucurucu:
Yes. Now I see that
if(total<1)

{

}

You are right. I'm sorry. This is the "problem" which won't let the EA open more than 1 trade.

I have modified the MACD Sample and I'm attaching the MACD Multi.

Please let me know if it's ok. I don't have time to test it.

Bye.

thank you very much for your kind support ..

 

Hello

WAW:
thank you very much for your kind support ..

Dear WAW

aleykomo salam

i'll be glad if i can help anyone, i start MQL4 coding from 2 weeks ago, and work very hard on it (about 9 hours a day);

thank your for your Yahoo Invitation, i'll add you as soon as posible

 

yahoo messenger

dear intelligent

can you please add me to your yahoo messenger,

my id qutegirl_4_u@yahoo.co.in.

really ineed somebodys help to learn mq4 or to write code for my strategy

bye thanks in advance

shwetha

Reason: