I'm developing a simple MACD cross buy/sell script, but when I run the tester, it opens a buy order for some lots, and then nothing happens. Prior to the script completing, the single order is then closed. Does anyone know what's going on here? Thanks.
Here is the output journal:
2014.11.0316:56:25.019 BTCUSD,Daily: 2303909 tick events (1304 bars, 2304909 bar states) processed within 1937 ms (total time 19078 ms)
2014.11.0316:56:25.0192014.10.3023:59 MACDcrossBTCUSD BTCUSD,Daily: End of MACD cross trading.
2014.11.0316:56:25.0192014.10.3023:59 Tester: order #1is closed
2014.11.0316:56:23.0912014.01.0300:00 MACDcrossBTCUSD BTCUSD,Daily: ORDER: 12014.11.0316:56:23.0912014.01.0300:00 MACDcrossBTCUSD BTCUSD,Daily: open #1buy 12.00 BTCUSD at 792.637 ok
2014.11.0316:56:23.0872014.01.0100:00 MACDcrossBTCUSD BTCUSD,Daily: Start of MACD cross trading.
2014.11.0316:56:23.085 MACDcrossBTCUSD test started
The script is as follows:
int lots = 0;
int thisBarTrade = 0;
bool haveBought = false;
int init()
{
Print("Start of MACD cross trading.");
return(0);
}
int deinit()
{
Print("End of MACD cross trading.");
return(0);
}
int start()
{
if (Bars != thisBarTrade && OrdersTotal() == 0) {
thisBarTrade = Bars;
int orderTicket;
if (iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1) > 0 &&
iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,2) < 0 &&
haveBought == false) {
// Buy when MACD is crossing from sell zone to buy zone
lots = AccountBalance() / Ask;
orderTicket = OrderSend(_Symbol,OP_BUY,lots,Ask,3,0,0,"MACD cross Buy",12345,0,clrBlue);
if (orderTicket < 0) {
Print("BUY OrderSend failed with error #", GetLastError());
} else {
Print("ORDER: ", orderTicket);
haveBought = true;
}
} elseif (iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1) < 0 &&
iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,2) > 0 &&
haveBought == true) {
// Sell when MACD is crossing from buy zone to sell zone
orderTicket = OrderSend(_Symbol,OP_SELL,lots,Bid,3,0,0,"MACD cross Sell",12345,0,clrRed);
if (orderTicket < 0) {
Print("SELL OrderSend failed with error #", GetLastError());
} else {
Print("ORDER: ", orderTicket);
haveBought = false;
}
}
}
// returnreturn(0);
}
Hey everyone,
I'm developing a simple MACD cross buy/sell script, but when I run the tester, it opens a buy order for some lots, and then nothing happens. Prior to the script completing, the single order is then closed. Does anyone know what's going on here? Thanks.
Here is the output journal:
The script is as follows: