Troubleshooting: Why no trade is entered?

Hi,

Playing with MQL4. I made this simple program but no order is executed. I try to let the limit order automatically expire in 2 minutes, but when I backtest it no trader order is sent.

I suspect that there is something wrong with the OrderSend function, but can’t pinpoint where the mistake is.

I appreciate any kind of input.

:confused:

int start()
{
//----

double Stochastics_Main[5];
double Stochastics_Signal[5];

for (int i=0; i<=5; i++)
{
Stochastics_Main[i]=iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, PRICE_CLOSE, MODE_MAIN, 0); //Stochastics Main Line
Stochastics_Signal[i]=iStochastic(NULL, 0, 5,3,3, MODE_SMA, PRICE_CLOSE, MODE_SIGNAL,0 ); //Stochastics Signal Line
}
//-------------------------------------------------------------------------------------------------------------
//Set lot rule
if(AccountBalance()<1000)//If the account Balance is smaller than 1000 bucks, trading size is .1 standard lot
LOTS=0.1;
else
LOTS=0.1*NormalizeDouble(AccountBalance()/1000,0);//Otherwise the size of the trading lots depends on the account balance

//----------------------------------------------------------------------

if (Stochastics_Main[0]>Stochastics_Signal[0] && Stochastics_Main[1]<Stochastics_Signal[1])
{

OrderSend(Symbol(), OP_BUYLIMIT, LOTS, (Bid+Ask)/2, 3, Low[2], (Bid+Ask)/2+100*Point, NULL, 0, Time[0]+120, Green);
//Note that I want the order to expire in 2 mins

}

Most brokers will not accept an order which has an non zero value for expiry.

You should always do an error check for every trading function. Here is an example.

    if (GetLastError() != 0) Print(Symbol(), " Order Send Error:  ", GetLastError());

I made some changes, but now it says OrderSend error 130?

I looked it up and it said it’s invalid stop? LOL

int start()
{
//----

double Stochastics_Main[5];
double Stochastics_Signal[5];

for (int i=0; i<=5; i++)
{
Stochastics_Main[i]=iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, PRICE_CLOSE, MODE_MAIN, i); //Stochastics Main Line
Stochastics_Signal[i]=iStochastic(NULL, 0, 5,3,3, MODE_SMA, PRICE_CLOSE, MODE_SIGNAL,i ); //Stochastics Signal Line
}
//-------------------------------------------------------------------------------------------------------------
//Set lot rule
if(AccountBalance()<1000)//If the account Balance is smaller than 1000 bucks, trading size is .1 standard lot
LOTS=0.1;
else
LOTS=0.1*NormalizeDouble(AccountBalance()/1000,0);//Otherwise the size of the trading lots depends on the account balance

//----------------------------------------------------------------------

if (Stochastics_Main[0]>Stochastics_Signal[0] && Stochastics_Main[1]<Stochastics_Signal[1])
{
Print("Bid price is: ", Bid, " Ask Price is: ", Ask);
OrderSend(Symbol(), OP_BUYLIMIT, LOTS, NormalizeDouble((Bid+Ask)/2, 5), 3, NormalizeDouble((Bid+Ask)/2, 5)-50Point, NormalizeDouble((Bid+Ask)/2, 5)+100Point, NULL, 0, 0, Green);
//Note that I want the order to expire in 2 mins
if (GetLastError() != 0) Print(Symbol(), " Order Send Error: ", GetLastError());

}

for (i=0; i<=OrdersTotal(); i++)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true)
{
if(TimeCurrent()-OrderOpenTime() >= 2*60) {OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, White);}

}
}

//----
return(0);
}

Is your broker an ECN? They will not accept orders with a non zero TP/SL. You need to use OrderModify() or leave the values at zero and manage the trade on the client.

I use Alpari US. Is that a STP broker or something?

No idea, I use FXDD.

I think your stoploss & takeprofit formulas needs to include parentheses around the amount x’s the Point otherwise it calculates literally as i.e. subtracting 50 from the price which will be a negative number which it then multiplies by the point value…and is not a valid price.

…NormalizeDouble((Bid+Ask)/2, 5)-(50Point), // stop loss
NormalizeDouble((Bid+Ask)/2, 5)+(100
Point)… //takeprofit