MQL4 Learning - page 40

 

Programmers, Please Read.

Hey guys,

Im looking for a bit of help. Im learning to code, very slowly, however i was just looking for advice as to how i can write the following EA.

I have been trading this live for a couple of months now, with alot of success.

Apply a 6EMA to the Batfink Trend Change Indicator. On the 4hr chart on your pair of choice (i prefer GBPUSD and GBPJPY):

Short when 6EMA slope changes from positive to negative

Long when 6EMA slope changes from negative to positive.

Im looking for an EA that can enter on these signals immediately, with 2 lots on each order, so the TP's can be managed. External Variable on the following would be great, to chnage up the EA on each pair traded:

- Initial Stop Size

- Initial TP on 1st lot

- Initial TP on 2nd lot

- Point at which Trailing stop is applied. (ive been doing this when first TP is hit)

- Depth of Trailing Stop

The indicator is attached, the 6EMA has to be overlayed. Thanks ALOT to anyone who can take the time to help with this code. I think it is very promising as a set and forget system.

Cheers,

Mitch.

 

Hey Dave,

Thanks,

I already did that thing but it is not working.

Instead of a smiley face, there is a cross with the name of EA.

Still struggling to get the EA work on Live charts as it is working on strategy tester.

Regards

 

Got it right

Thanks to all anyways

 

Process new bar only?

Hi all. Sorry if I post at wrong side of forum. I hope not.

I have a coding question. How can I make sure my piece of code is only executed if a new 5-min bar is formed, and not every new tick? Thanks!

 
ssg10:
Hi all. Sorry if I post at wrong side of forum. I hope not. I have a coding question. How can I make sure my piece of code is only executed if a new 5-min bar is formed, and not every new tick? Thanks!

You can use Time[x], x=0,1,2,3,...

 

closed order

i want to closed order for ea on each day, if i'got my achieve profit..

how can i do that?

do i put;

========

bool ProfitAchieve = true;

int ProfitAchieve = 40;

========

if ProfitAchieve = true;

{

if ProfitAchieve >= 40;

{

ClosedOrder;

{

else

{

are my code were correct? i need help...please

 

I didn't tested but something like this may be what you need.

bool ProfitAchieve = true;

int Profit_Achieve = 40;

int start()

{

if(ProfitAchieve && Profit() >= Profit_Achieve) CloseOrder();

}

int Profit()

{

double pips=0;

int trade;

int trades=OrdersTotal();

for(trade=0;trade<trades;trade++) {

OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) {

if(OrderType() == OP_BUY) pips+= (Bid-OrderOpenPrice())/point;

if(OrderType() == OP_SELL) pips+= (OrderOpenPrice()-Ask)/point; }

} //---- for

return(pips);

}

void CloseOrder()

{

int trades = OrdersTotal();

bool order;

for(int trade=0; trade < trades; trade++) {

OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;

if(OrderType() == OP_BUY) order = OrderClose(OrderTicket(),OrderLots(),Bid,2,Blue);

else if(OrderType() == OP_SELL) order = OrderClose(OrderTicket(),OrderLots(),Ask,2,Pink);

} //---- for

if(!order) CloseOrder();

}
 
FerruFx:
I didn't tested but something like this may be what you need.

thanks mr.ferrufx,

i will try it...

add;

bool ProfitAchieve = true;

int Profit_Achieve = 40;

int MagicNumber = 123456;

int start()

{

if(ProfitAchieve && Profit() >= Profit_Achieve) CloseOrder();

}

int Profit()

{

double pips=0;

int trade;

int trades=OrdersTotal();

for(trade=0;trade<trades;trade++) {

OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) {

if(OrderType() == OP_BUY) pips+= (Bid-OrderOpenPrice())/Point;

if(OrderType() == OP_SELL) pips+= (OrderOpenPrice()-Ask)/Point; }

} //---- for

return(pips);

}

void CloseOrder()

{

int trades = OrdersTotal();

bool order;

for(int trade=0; trade < trades; trade++) {

OrderSelect(trade,SELECT_BY_POS,MODE_TRADES);

if(OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;

if(OrderType() == OP_BUY) order = OrderClose(OrderTicket(),OrderLots(),Bid,2,Blue);

else if(OrderType() == OP_SELL) order = OrderClose(OrderTicket(),OrderLots(),Ask,2,Pink);

} //---- for

if(!order) CloseOrder();

}

 

chart shift coords

Hi,

How does one dynamically find out the coords for the chart shift area?

I'm wanting to put labels in there and have them repaint when charts are resized.

Currently i only know how to put in the physical coords.

Cheers

 

Error Handling question

What Error message would I get if my EA place an BUYLIMIT order @ 1.4000

when the market is 1.3950?

Can solve the error by setting the Slippage to 50 or more?

Reason: