ordersend() coding help...

 

Hey guys,

Really strange but when i run the following code it does nothing. GetLastError() returns 130.

   Print("running");
   OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My order #2",16384,0,Green)


But if take the same code and remove the stop & target info it spits out orders just fine.

   Print("running");
   OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"My order #2",16384,0,Green);


I am using an empty expert template and just have those two lines of code in the start function.

Not sure whats causing it...


Thanks!

 
mugged:

Hey guys,

Really strange but when i run the following code it does nothing. GetLastError() returns 130.


But if take the same code and remove the stop & target info it spits out orders just fine.


I am using an empty expert template and just have those two lines of code in the start function.

Not sure whats causing it...


Thanks!

What kind of broker?

fractional point symbol?

 
diostar:

What kind of broker?

fractional point symbol?


Im using an IBFX mini account.


Im running it on Eur/Usd

 
Also when I run the code in strategy tester it works just fine... when i run it in real life i get problems.
 

You have your SL and TP calculations wrong

If its a Buy:

SL = Bid - StopLoss* Point

TP = Bid + TakeProfit* Point

If its a Sell:

SL = Ask + StopLoss* Point;

TP = Ask - TakeProfit* Point;

Aside from that, with some brokers you have to do the OrderSend() without SL and TP levels then do OrderModify() and enter the TP and SL

 
mugged:

Im using an IBFX mini account.


Im running it on Eur/Usd

Ok.... Sorry for not being specific.

try this:

(1)at ordersend: sl=tp=0. then ordermodify the sl=tp.

(2) eur/usd: what digits? 4 or 5?

 
SDC:

You have your SL and TP calculations wrong

If its a Buy:

SL = Bid - StopLoss* Point

TP = Bid + TakeProfit* Point

If its a Sell:

SL = Ask + StopLoss* Point;

TP = Ask - TakeProfit* Point;


Hey bud, I tried swapping the "Ask" I used to define my SL and TP with "Bid" as you suggested but still no luck.
 

OK it is probably just because you need to do OrderSend() then OrderModify()

 
diostar:

Ok.... Sorry for not being specific.

try this:

(1)at ordersend: sl=tp=0. then ordermodify the sl=tp.

(2) eur/usd: what digits? 4 or 5?



1) Yes this method works! Is there any way around this though? I hate the thought of the worst case where the initial order goes in but the modify doesn't occur (connection dies, error occurs, etc etc.)


2) 5 digit broker

 
for a 5 digit broker you may need to multiply your SL and TP amounts by ten otherwise you TP or stop out at 2.5 pips
 
SDC:
for a 5 digit broker you may need to multiply your SL and TP amounts by ten otherwise you TP or stop out at 2.5 pips

Seems to go through fine with the send then modify method. Any ideas how I can get both the order and stop in on the same shot? Id prefer them to go in together in a production environment.
Reason: