How to code? - page 19

 

Thanks for your effort Nicholishen. Unfortunately it didnt work. It is modifying the orders but both ways. What I mean just for clairification is in a buy situation it will move the stop up by the trail points, but it will also move it down. i need to stop the moving down.

 

I understand what you mean, but the code is correct. There is either another EA modifying these orders or there is other code in the EA that is doing it becuase it is certainly not this code. You will need to stop all other EA's and check the primary EA code for other calls to OrderModify()

Good luck =)

Files:
 

Thanks for your time with my noobish self

the only other ordermodify in the code is a break even and lock pips. i will attach it.

BEx=amount of pips to lock in

I have been thru it so many times im sure it is looking right at me, but I am no pro, a hack at best.

Thanks again Nicholishen!

void DoBE(int byPips)

{

for (int i = 0; i < OrdersTotal(); i++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == uniqueGridMagic) || (OrderComment() == GridName)) ) // only look if mygrid and symbol...

{

if (OrderType() == OP_BUY) if (Bid - OrderOpenPrice() > byPips * MarketInfo(OrderSymbol(), MODE_POINT)) if (OrderStopLoss() != (OrderOpenPrice() + MarketInfo(OrderSymbol(), MODE_POINT))) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + MarketInfo(OrderSymbol(), MODE_POINT)*BEx, OrderTakeProfit(), Red);

if (OrderType() == OP_SELL) if (OrderOpenPrice() - Ask > byPips * MarketInfo(OrderSymbol(), MODE_POINT)) if (OrderStopLoss() != (OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_POINT))) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_POINT)*BEx, OrderTakeProfit(), Red);

}

}

}

Oh forgot to add, this is the only EA. Just currently backtesting.

 
C.E.O.:
Thanks for your time with my noobish self

the only other ordermodify in the code is a break even and lock pips. i will attach it.

BEx=amount of pips to lock in

I have been thru it so many times im sure it is looking right at me, but I am no pro, a hack at best.

Thanks again Nicholishen!

void DoBE(int byPips)

{

for (int i = 0; i < OrdersTotal(); i++) {

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == uniqueGridMagic) || (OrderComment() == GridName)) ) // only look if mygrid and symbol...

{

if (OrderType() == OP_BUY) if (Bid - OrderOpenPrice() > byPips * MarketInfo(OrderSymbol(), MODE_POINT)) if (OrderStopLoss() != (OrderOpenPrice() + MarketInfo(OrderSymbol(), MODE_POINT))) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + MarketInfo(OrderSymbol(), MODE_POINT)*BEx, OrderTakeProfit(), Red);

if (OrderType() == OP_SELL) if (OrderOpenPrice() - Ask > byPips * MarketInfo(OrderSymbol(), MODE_POINT)) if (OrderStopLoss() != (OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_POINT))) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_POINT)*BEx, OrderTakeProfit(), Red);

}

}

}[/PHP]

Oh forgot to add, this is the only EA. Just currently backtesting.

Probably what is happen is that one fuction is nullifying the other. You will need to check your logic so that only one operates at a time.

[PHP]void DoBE(int byPips)

{

for (int i = 0; i < OrdersTotal(); i++)

{

OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

if ( OrderSymbol()==Symbol() && ( (OrderMagicNumber() == uniqueGridMagic) || (OrderComment() == GridName)) ) // only look if mygrid and symbol...

{

if (OrderType() == OP_BUY)

{

if (Bid - OrderOpenPrice() > byPips * MarketInfo(OrderSymbol(), MODE_POINT))

{

if (OrderStopLoss() != (OrderOpenPrice() + MarketInfo(OrderSymbol(), MODE_POINT)))

{

OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + MarketInfo(OrderSymbol(), MODE_POINT)*BEx, OrderTakeProfit(), Red);

}

}

}

if (OrderType() == OP_SELL)

{

if (OrderOpenPrice() - Ask > byPips * MarketInfo(OrderSymbol(), MODE_POINT))

{

if (OrderStopLoss() != (OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_POINT)))

{

OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_POINT)*BEx, OrderTakeProfit(), Red);

}

}

}

}

}

return;

}
 

MQL4 commands/code verification

Message deleted. Sorry for the inconvenience.

 

Code for 'Allow live trading'

Hello, for EA's to work we have to enable the 'Allow live trading' option so in stead of having to tick it all the time when loading the EA what line of code do I add to automatically have that option enabled in the EA?

Thanks

 

You dont need code to do that..

matrixebiz:
Hello, for EA's to work we have to enable the 'Allow live trading' option so in stead of having to tick it all the time when loading the EA what line of code do I add to automatically have that option enabled in the EA? Thanks

Hallo Matrixebiz,

You can do that easily by going to MetaTrader's menu. Go to "Tools" then "Options" (or just type CRTL-O). Then, in the "Expert Advisor" tab, check the Allow live trading options. There you go, all the EA you attach after that will be allowed live trading.

-RJ1-

 

Oh, ok, that was easy Thanks

 

EA time code

I want EA time code. Example that it would enable only trading 18:00-1:00. Is it possible?

 

Found this

if (UseHourTrade){

if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade)){

Comment("Non-Trading Hours!");

return(0);

One question:

It uses my forex broker time : Yes or No??

I think yes but I want to be sure

And how can I put there minutes there like 15:30 ?? There is only hours??

Reason: