I get ordersend error 138, be it buy or sell, but only in back testing not in live demo. I have try to adjust slippage to no avail. Does anyone have any idea what's wrong?
double price = iClose(Symbol(), PERIOD_H1, 1);
if (up > down && up > sideway){
double stoploss = NormalizeDouble(price-piploss*Point, Digits);
double takeprofit = NormalizeDouble(price+pipgain*Point, Digits);
int ticket = OrderSend(Symbol(), OP_BUY, 1, price, 5, stoploss, takeprofit, "buy", 16384, 0, clrGreen);
if (ticket<0){
Print("Order send error: ", GetLastError());
} else{
Print("Order success");
}
} else if (down > up && down > sideway) {
double stoploss = NormalizeDouble(price+piploss*Point, Digits);
double takeprofit = NormalizeDouble(price-pipgain*Point, Digits);
int ticket = OrderSend(Symbol(), OP_SELL, 1, price, 5, stoploss, takeprofit, "sell", 16384, 0, clrGreen);
if (ticket<0){
Print("Order send error: ", GetLastError());
} else{
Print("Order success");
}
} else {
Print("sideway");
}
}