...
Any help or pointers appreciated
Alain Verleyen: You are trying to open a SELL at Ask and a BUY at Bid price. Should be the reverse.
| And using the same SL (and TP) for both directions. |
I changed the code to 0 SL, 0 TP, etc to
whroederAnd using the same SL (and TP) for both directions. |
The TP & SL are setup elsewhere and are different for "DN" or "UP"
I have invalid stops in the past and been able to locate the problem but this has me puzzled.
I have been essentially using the same code for a long time and not aware of any changes that I have made
if( BUYorSELL == "DN" ) My_Ticket = OrderSend(My_OrderSymbol,OP_SELL,0.01,MarketInfo(My_OrderSymbol,MODE_BID),40,0,0,"None",100,0,CLR_NONE); //CLR_NONE instead of colour
if( BUYorSELL == "UP" ) My_Ticket = OrderSend(My_OrderSymbol,OP_BUY ,0.01,MarketInfo(My_OrderSymbol,MODE_ASK),40,0,0,"None",100,0,CLR_NONE);
Write_my_Error("Open_Buy_Sel1_1 ");
{ My_error=GetLastError();
string st_99999 = MyDT+">>>>>>>>>>>.... "+mylabel+" My_error: "+IntegerToString(My_error)+" "+ErrorDescription(My_error);
if( My_error > 0 ) FileWrite(My_Handle,st_99999);
return;
}
Write_my_Error just writes the error code and description to my own log file
Can't find any reference to error code 2
I have verified that My_OrderSymbol has a value. The following is my log output (the TP,SL,Comment & Magic# are all overwritten with values in the OrderSend statement.
Still get error code 2 ~ common error
2016.12.23 17:23:33 EURJPY 50010 OBS UP TradeAllowed = 1
2016.12.23 17:23:33 EURJPY 50020 OBS My_OrderSymbol = EURJPY ASK = 122.45800 BID = 122.44300 BUYorSELL = UP My_Trading_Lots = 0.01 My_Slippage = 40 My_TakeProfit = 0.00000 My_StopLoss= 0.00000 My_Comment = Panic My_Magic_Nos = 1
2016.12.23 17:23:33 EURJPY >>>>>>>>>>>.... Open_Buy_Sel1_1 My_error: 2 common error
Please don't write inside the quote.
Why are you checking for an error without even using the ticket value returned by OrderSend() (as already stated by WHRoeder) ?
Alain,
I use this routine in many places and and do look at returned ticket number (is -1) in the next statement.
[surely a -1 states it has failed and the Error Code should hopefully provide an explanation of why it failed together with the error description]
I understood whroeder (in the articles he refers to) suggests I examine the error code which is what I have done and have a value of 2 with a description of "common error".
No where can I find a reference to the error code 2.
I have taken code from a previous EA which was know to work and that is generating the same error code (2)
peterhw: [surely a -1 states it has failed and the Error Code should hopefully provide an explanation of why it failed together with the error description]
| Exactly. Do not look at _LastError unless you do have a failed OrderSend. |
My_StopLoss, My_TakeProfit, My_Comment , My_Magic_Nos, 0, CLR_NONE); //CLR_NONE instaed of colour
if( BUYorSELL == "UP" ) My_Ticket = OrderSend(My_OrderSymbol, OP_BUY , My_Trading_Lots, MarketInfo(My_OrderSymbol,MODE_ASK), My_Slippage,
My_StopLoss, My_TakeProfit, My_Comment , My_Magic_Nos, 0, CLR_NONE);
FileWrite(My_Handle,MyDT+"50021 OBS Ticket = "+IntegerToString(My_Ticket));
if (My_Ticket < 0 ) Write_my_Error("Open_Buy_Sell_1 ");
MyDT is just a date & time
In this case I have a Ticket = -1 and still have error code 2 - Common Error
Whilst I have read these comments with interest I don't seem to be getting much closer.
My original question was any help with finding a meaningful error description for error code 2.
All the minor changes I have made to 'play' with the code all appear to fail to resolve the error code 2
Alain - first time I have received a reply from yourself but many replies from whroeder1 - your help is always appreciated
Merry Christmas and a Happy New Year to you all
Alain - first time I have received a reply from yourself but many replies from whroeder1 - your help is always appreciated
Merry Christmas and a Happy New Year to you all
How are you checking that when the market is close ?
Anyway, this "Common error" happens when there is some bad parameter, so it all depends of the values.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I have code which has worked for a while and for some reason I am now getting the above error
the code is
string st_50020=MyDT+"50020 OBS ASK = "+DoubleToString(MarketInfo(My_OrderSymbol,MODE_ASK),5)+
" BID = "+DoubleToString(MarketInfo(My_OrderSymbol,MODE_BID),5)+" BUYorSELL = "+BUYorSELL+
" My_Trading_Lots = "+DoubleToString(My_Trading_Lots,2)+" My_Slippage = "+IntegerToString(My_Slippage)+
" My_TakeProfit = "+DoubleToString(My_TakeProfit,5)+" My_StopLoss= "+DoubleToString(My_StopLoss,5)+
" My_Comment = "+My_Comment+" My_Magic_Nos = "+IntegerToString(My_Magic_Nos);
FileWrite(My_Handle,st_50020); FileFlush(My_Handle);
if( BUYorSELL == "DN" ) My_Ticket = OrderSend(My_OrderSymbol, OP_SELL, My_Trading_Lots, MarketInfo(My_OrderSymbol,MODE_ASK), My_Slippage,
My_StopLoss, My_TakeProfit, My_Comment , My_Magic_Nos, 0, Red);
if( BUYorSELL == "UP" ) My_Ticket = OrderSend(My_OrderSymbol, OP_BUY , My_Trading_Lots, MarketInfo(My_OrderSymbol,MODE_BID), My_Slippage,
My_StopLoss, My_TakeProfit, My_Comment , My_Magic_Nos, 0, Green);
Write_my_Error("Open_Buy_Sel1_1 ");
the results are:-
My own log shows the following - i.e. results from code above. Write_my_Error - generates the >>>>>>>>> line
2016.12.22 18:50:18 GBPCAD 50010 OBS UP TradeAllowed = 1
2016.12.22 18:50:18 GBPCAD 50020 OBS ASK = 1.65653 BID = 1.65626 BUYorSELL = UP My_Trading_Lots = 0.01 My_Slippage = 40 My_TakeProfit = 1.65776 My_StopLoss= 1.64508 My_Comment = FSC_12995018 My_Magic_Nos = 12995018
2016.12.22 18:50:18 GBPCAD >>>>>>>>>>>.... Open_Buy_Sel1_1 My_error: 2 common error
2016.12.22 18:50:18 GBPCAD 50021 OBS Ticket = -1
The JOURNAL SHOWS
2016.12.22 16:51:04.308 '2000096303': order buy 0.01 GBPCAD opening at market sl: 1.64488 tp: 1.65756 failed [Common error]
2016.12.22 16:51:03.882 '2000096303': order buy market 0.01 GBPCAD sl: 1.64488 tp: 1.65756
I read something about common errors but nothing specific about 2 and just can't figure out what I may have changed
Any help or pointers appreciated