Error Handling according to the docs.
For 130: Does your ECN allow you to send Sl and Tp with pending? Other things you can check, does the Sl and Tp exceed the absolute value of math maximum of the Market Info: StopLevel and FreezeLevel.
For 138: Usually its because the Ask and Bid are flipped around. But with this being an ECN I'll say go ahead and check the general format of the price itself for stuff like extra .decimals etc.
thank
for send order i must do
1) ordersend, without SL e TP
after
2) insert SL and TP
I do this procedure for all orders
i'm newbie in this language code
my broker is ATC
can you show me how would you do with example??
Well my codes would have allot of other stuff which clouds the example. Basically you're doing most of what needs to be done already within your example code. I believe what you are seeking now comes with experience of coding and testing. If I was coding this for a live real money EA. I would need the following.
- Market_Info()=Give me all the market info and place them within Global variables (Not the GlobalVariableSet).
- Check for TradeContexBusy. If the Trading Thread is Busy then Sleep() for a random time between 2-4 seconds.
- Refresh() after Sleep() or re-run the Market_Info()
- OrderSend(Sl=0, Tp=0); this returns a Ticket#> -1 if it works.
- Therefore if Ticket==(-1) then you want to GetLastError(). Save this Value because it goes away after the first time you check GetLastError().
- Given your case you should run into error 138, but this is more of an experience error and something you could have avoided and found during testing. Like I said above you can fix this making sure your price variable is not looking for Ask where it should be looking for Bid and vice-versa.
- Once you fix that and your order goes through. Your Ticket Variable will have the value of the Ticket# which you have to Immediately try to search for and correct the Sl and Tp.
- For initial order sl and tp. I'll do something like asking if sl=0 {after the order search of course}. Then you have to make sure the MathAbs(OrderOpenPrice() - New_StopLoss_Price ) is Greater> StopLevel*Point and Greater than FreezeLevel*Point.
Example from my code:
double Oop=OrderOpenPrice(); double Ocp=OrderClosePrice();
if(MathAbs(Oop-Ocp)>Bkr_Freeze*Point2Pips){ Close(.......); }
- The StopLevel and Freezelevels are Global variables you would have saved when you ran you Market_Info function.
- In the case of Pending Orders, you also have to make sure that the Stoploss and TakeProfit values are not anywhere near the current Price-Action. So again you'll also have to check if(mathabs(ask-PendingOpenPerice)>Bkr_StopLv*Points)<---for pending orders above current price obviously. And check reverse for pending orders below.
Well... I don't code any EA's anymore with pending orders and stop-losses anymore. I just use Market_Orders to get In and Out. If you really want to look through codes then try looking at WHRoeders Codes for Pending Orders Stop considerations. You can look here for help on constructing a Reliable OrderSend Routine.
Lastly, don't think you can just get-by on copy and pasting codes. You'll lack the insights the experience brings so I recommend reading the docs, articles, codes in the code base, etc ... which relates to what ever you're stuck on.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
function for management
//***************************************
pending config., problem err 130 invalid stop???
//*****************************************
normal ordersend, problem err 138 requote??
my broker is ECN broker, but i have this problem and i don't understand
thanks