OrderSend not working with demo account

 
I recently opened a demo account, and my script gets an error every time the code tries to make a trade. I using a simple buy order:

ticket=OrderSend(Symbol(),OP_BUY,1,Ask,1,Ask-10*Point,Ask+10*Point);

I get an error code 4109, which is "Trading Not Allowed"

Also, the IsTradeAllowed() function returns false.

Does OrderSend not work with a demo account?


Thanks!

 
What currency chart do you use?
 
Roger:
What currency chart do you use?

EURUSD

 

Have you ticked the "Allow Live Trading" checkbox in Tools|Options|Experts ?


CB

 

CB is right on the money. That error comes from experts trying to send orders when it's disabled in its properties. Just make sure that it is checked and that the expert advisors button at the top of MT4 is pushed. This will make the top right of your chart have the name of your EA with a happy face.

Happy face: EA is working.

Sad face: EA is not allowed to trade live in the EA properties.

Dagger (looks like a fancy X): Expert Advisors button is not pushed at the top of MT4. It's not even being run at every tick.

Jon

 
Archael:

CB is right on the money. That error comes from experts trying to send orders when it's disabled in its properties. Just make sure that it is checked and that the expert advisors button at the top of MT4 is pushed. This will make the top right of your chart have the name of your EA with a happy face.

Happy face: EA is working.

Sad face: EA is not allowed to trade live in the EA properties.

Dagger (looks like a fancy X): Expert Advisors button is not pushed at the top of MT4. It's not even being run at every tick.

Jon

 

Negative - already tried all that. I started with an EA, that had the "Allow to Trade Live" property checked. The EA was running with the happy smiley face in the upper right. The EA gives a 130 error code whenever OrderSend is fired.


I then dumbed it down into just a simple script to see if I could get the buy order working (see code below). When I run the script, I get the error 4109 on OrderSend, and IsTradeAllowed = false.


int ticket;
if(IsTradeAllowed())
{
Alert("Trade allowed");
}
else
{
Alert("Trade not allowed");
}
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,1,Ask-10*Point,Ask+10*Point);
if (ticket<0)
{
Alert("Order failed with #",GetLastError());
}
else
{
Alert("Order successful with ticket #",ticket);
}
return(0);

 
dmking999:

Negative - already tried all that. I started with an EA, that had the "Allow to Trade Live" property checked. The EA was running with the happy smiley face in the upper right. The EA gives a 130 error code whenever OrderSend is fired.


I then dumbed it down into just a simple script to see if I could get the buy order working (see code below). When I run the script, I get the error 4109 on OrderSend, and IsTradeAllowed = false.


int ticket;
if(IsTradeAllowed())
{
Alert("Trade allowed");
}
else
{
Alert("Trade not allowed");
}
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,1,Ask-10*Point,Ask+10*Point);
if (ticket<0)
{
Alert("Order failed with #",GetLastError());
}
else
{
Alert("Order successful with ticket #",ticket);
}
return(0);

I just tried the IsTradeAllowed() in my EA, instead of the script, and I'm getting a 1 (true) for a result, however I get the error 130 when the OrderSend fires.

 

I was talking about error 4109, not error 130. Nowhere in your previous posts does it say error 130.

That said, since you're doing an OP_BUY order, the error 130 means you either have a faulty SL or TP. Judging by your current code, I'm thinking you have a 5-digit broker and you're using pip values instead of point values when using the Point variable.

On a 5 digit broker "Ask-10*Point" means Ask - 1pip. This is probably too close and causes the 130 error "Invalid Stops".

Jon

 
Archael:

I was talking about error 4109, not error 130. Nowhere in your previous posts does it say error 130.

That said, since you're doing an OP_BUY order, the error 130 means you either have a faulty SL or TP. Judging by your current code, I'm thinking you have a 5-digit broker and you're using pip values instead of point values when using the Point variable.

On a 5 digit broker "Ask-10*Point" means Ask - 1pip. This is probably too close and causes the 130 error "Invalid Stops".

Jon

Bingo! You are correct - I have a 5 digit broker. Once I adjusted my SL & TP, I get the OrderSend to fire correctly.


Thanks for your help!!

Reason: