EA not trading. Help?

 

Ok, so I've been programming EAs for a while, they work fine normally. I've been trying to run one recently, and it won't trade live (will do in backtest no problem). I have a print statement in the same set of brackets as the ordersend:


{

Print("SHORT! BarsSinceTrade is ", BarsSinceTrade);

OrderSend(Symbol(), OP_SELL, ShortLots, ShortEntry, Slippage, ShortStoploss, 0, "commentsell", 1, 0, Red);

tradeTime = Time[0];

BarsSinceTrade = 0;

}


The print statement turns up, but no order is sent as far as i can see, and i can't find any error messages about. I'm a bit rusty i must admit, but any thoughts?


Thanks muchly.

 
Hotch:

[...] and it won't trade live (will do in backtest no problem)

There are many, many possibilities, but one which particularly explains it working in backtest but not live is that your broker requires you to place stops independently of market orders - i.e. do an OrderSend() and then an OrderModify() to place the t/p and s/l. Typically encountered on brokers using the Boston Technologies bridge.


Failing that, try logging the result of GetLastError().

 
jjc:

There are many, many possibilities, but one which particularly explains it working in backtest but not live is that your broker requires you to place stops independently of market orders - i.e. do an OrderSend() and then an OrderModify() to place the t/p and s/l. Typically encountered on brokers using the Boston Technologies bridge.


Failing that, try logging the result of GetLastError().

Cheers, will give that a go.


EDIT:


Worked, cheers jjc, hope i can repay the favour some day.

 

Well done with crystal ball on that occasion jjc. Respect.


CB

 
cloudbreaker:

Well done with crystal ball on that occasion jjc. Respect.

I've only ever placed pending orders via the BT Bridge, so I've never encountered Hotch's issue personally, but they're always near the top of my mind because their Bridge has led to more swearing, phone calls, and refunds than every other broker put together.

 
jjc:

I've only ever placed pending orders via the BT Bridge, so I've never encountered Hotch's issue personally, but they're always near the top of my mind because their Bridge has led to more swearing, phone calls, and refunds than every other broker put together.

Yeah, I've only used pendings until now. So that would explain why I was suddenly having trouble. Thanks again, all working live now.

 

I'm having this same problem... how would I modify the following code to correct that?


//Buy
if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(DecideToOpenTrade(OP_BUY) && TradeSlotsAvailable()) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("BUY order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
} else {
Print("Error opening BUY order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);
}
}

//Sell
if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
if(DecideToOpenTrade(OP_SELL) && TradeSlotsAvailable()) {
//Check free margin
if (AccountFreeMargin() < (1000 * Lots)) {
Print("We have no money. Free Margin = ", AccountFreeMargin());
return(0);
}

if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
if(Ticket > 0) {
if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
Print("SELL order opened : ", OrderOpenPrice());
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
} else {
Print("Error opening SELL order : ", GetLastError());
}
}
if (EachTickMode) TickCheck = True;
if (!EachTickMode) BarCount = Bars;
return(0);

 
fireslayer26:

I'm having this same problem... how would I modify the following code to correct that?

See https://www.mql5.com/en/forum/124002.

Reason: