peterhw: https://www.mql5.com/en/forum/157900
| Please use the link button (control-K.) for links See the difference: https://www.mql5.com/en/forum/157900 |
any code appreciated
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("50010D BUYorSELL ");
Thanks Marco,
This is the code and haven't seen this error code for a long time (when the S/L & T/P were really wrong) .
I have only seen this with XM
In th examples above the Takeprofit is 150 points and StopLoss 0 for both.
(I put the S/L as zero in attempt to locate the problem).
With zero s/l and T/P 150 points I wouldn't envisage SPREAD being a problem
What a piece of junk !
{
Print("DN ",
" Lots: ",DoubleToString(My_Trading_Lots),
" Symbol: ",My_OrderSymbol,
" SL: ",DoubleToString(My_StopLoss),
" TP: ",DoubleToString(My_TakeProfit));
}
And incomplete as well you are not showing where these values come from.
What a piece of junk !
{
Print("DN ",
" Lots: ",DoubleToString(My_Trading_Lots),
" Symbol: ",My_OrderSymbol,
" SL: ",DoubleToString(My_StopLoss),
" TP: ",DoubleToString(My_TakeProfit));
}
And incomplete as well you are not showing where these values come from.
Fine - if you don't like it but no need to be insulting.
How about we answer the question - if you wish - rather than throw insults. I do appreciate you guys help of your own accord but I have been coding in my own way for years trying to pick up the best when I can and I am happy that the code normally works fine.
I'm happy with the values and how they are calculated but one example fails with incorrect STOPS and another just a few minutes later does not.
Fine - if you don't like it but no need to be insulting.
How about we answer the question - if you wish - rather than throw insults.
Marco has posted code to add to yours (for fault finding) not to replace yours. Once you have printed those values, it may become obvious where your problem is.
You might also want to check your broker's stop level:
Fine - if you don't like it but no need to be insulting.
How about we answer the question - if you wish - rather than throw insults. I do appreciate you guys help of your own accord but I have been coding in my own way for years trying to pick up the best when I can and I am happy that the code normally works fine.
I'm happy with the values and how they are calculated but one example fails with incorrect STOPS and another just a few minutes later does not.
How are we able to help if you post incomplete code and do not show how these values are calculated ?
That's like going to a garage with only your spare tire and asking them to fix your car.
How are we able to help if you post incomplete code and do not show how these values are calculated ?
That's like going to a garage with only your spare tire and asking them to fix your car.
Exactly, that's not the first time, with exact same code snippet.
And you don't have follow people advice, it's all there already :
Forum on trading, automated trading systems and testing trading strategies
whroeder1, 2016.01.04 12:51
- When I tried stops, I couldn't get them to work. I think it was comparing current market to the TP/SL. Perhaps that problem is back; try setting the pending first and then set the stops.
- There is no reason to use pending orders in a EA. Humans can't look at the market continuously, EAs can. Just wait until the market reaches your price.
There is Tick, PIP, and Point. They are all different in general. A tick is the smallest change of price. A Point is the least significant digit quoted. In currencies a pip is defined as 0.0001 (or for JPY 0.01)
On a 4 digit broker a point (0.0001) = pip (0.0001). [JPY 0.01 == 0.01] On a 5 digit broker a point (0.00001) = 1/10 pip (0.00010/10). Just because you quote an extra digit doesn't change the value of a pip. (0.0001 == 0.00010) EA's must adjust pips to points (for mq4.) In currencies a tick is a point. Price can change by least significant digit (1.23456 -> 1.23457)
In metals a Tick is still the smallest change but is larger than a point. If price can change from 123.25 to 123.50, you have a TickSize of 0.25 and a point of 0.01. Pip has no meaning.
This is why you don't use TickValue by itself. Only as a ratio with TickSize. See DeltaValuePerLot()
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it.
It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
Marco has posted code to add to yours (for fault finding) not to replace yours. Once you have printed those values, it may become obvious where your problem is.
You might also want to check your broker's stop level:
Thanks for the response
I do write them to my own log file with results as above ( I don't believe where they are written to changes the results or problem):-
2017.01.11 13:45:02 USDCHF 50020 OBS My_OrderSymbol = USDCHF ASK = 1.02058 BID = 1.02035 BUYorSELL = DN My_Trading_Lots = 0.01 My_Slippage = 40 My_TakeProfit = 1.01908 My_StopLoss= 0.00000 My_Comment = FSC.27.13.34_.2 My_Magic_Nos = -173588486
I just happen to write the details to my own log rather using the PRINT statement
The error refers to invalid stops which I understand to mean the STOPLOSS & TAKEPROFIT figures. The STOPLOSS in all cases is ZERO (used to try track the other problem / snippet Alain refers to). The Takeprofit is 150 points in all cases and I suspect your suggestion WRT the stop level is a possible answer
The following is taken from the JOURNAL at another time
0 00:15:11.250 '8108742': order sell market 0.01 GBPCAD sl: 0.00000 tp: 1.61267
1 00:15:11.377 '8108742': order sell 0.01 GBPCAD opening at market sl: 0.00000 tp: 1.61267 failed [Invalid S/L or T/P]
0 00:15:11.377 '8108742': order sell market 0.01 GBPCHF sl: 0.00000 tp: 1.23777
1 00:15:11.505 '8108742': order sell 0.01 GBPCHF opening at market sl: 0.00000 tp: 1.23777 failed [Invalid S/L or T/P]
0 00:15:11.507 '8108742': order sell market 0.01 GBPUSD sl: 0.00000 tp: 1.21779
0 00:15:11.671 '8108742': order was opened : #112910659 sell 0.01 GBPUSD at 1.21904 sl: 0.00000 tp: 1.21779
The failures occur where the STOPLEVELS are Higher. The attached shows a table I created and using with XM broker and shows some high STOPLEVELS (all figures are points based)
Again Alain's response refers to me to WHRoeders previous post - I already referred to that and believe I understand the content
Marco
" That's like going to a garage with only your spare tire and asking them to fix your car." - I disagree it's more like going to the garage and asking them to figure out what's wrong with the tyre that I know is faulty.
If they fix the tyre and the same problem occurs then my fault and probably need to look deeper at what is causing the problem. honest_knave 's suggestion seems most relevant
Apologies but the way the figures are calculated appears irrelevant to me at the moment - unless there is some hidden meaning behind the error message.
Thanks everyone for contributions
- 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 been using XM brokers and appear to get Invalid Stops occurring more often tyhan elsewhere but in any event don't quite understand what factors can lead to this error
I read the following with WHRoeder's comments - interesting but don't don't think they apply to my circumstances
https://www.mql5.com/en/forum/157900
The following is from my own log file showing a StopLoss of 0 and a TakeProfit 150 points from the OpenPrice (OP) - Option 1 fails Option 2 Fails.
(Just noticed my Magic # appears -ve - must check but doesn't appear to be the problem)
OPTION 1
2017.01.11 13:52:40 EURNZD 66625 LTC Trade_Flag = UP OP = 1.50181 MyTP = 1.50331 MySL = 0.00000, My_Trading_Lots = 0.01 SL pts = 0.01273 TP pts = 0.00150
2017.01.11 13:52:40 EURNZD 50010 OBS UP TradeAllowed = 1
2017.01.11 13:52:40 EURNZD 50020 OBS My_OrderSymbol = EURNZD ASK = 1.50252 BID = 1.50181 BUYorSELL = UP My_Trading_Lots = 0.01 My_Slippage = 40 My_TakeProfit = 1.50331 My_StopLoss= 0.00000 My_Comment = FSC.14.13.34.40 My_Magic_Nos = -1473588448
2017.01.11 13:52:40 EURNZD 50021 OBS Ticket = -1
2017.01.11 13:52:40 EURNZD >>>>>>>>>>>.... 50010D BUYorSELL My_error: 130 invalid stops
2017.01.11 13:52:40 EURNZD 50021 OBS Ticket = -1
Simialar log where using the same EA works
OPTION 2
2017.01.11 13:45:02 USDCHF 66625 LTC Trade_Flag = DN OP = 1.02058 MyTP = 1.01908 MySL = 0.00000, My_Trading_Lots = 0.01 SL pts = 0.00520 TP pts = 0.00150
2017.01.11 13:45:02 USDCHF 50010 OBS DN TradeAllowed = 1
2017.01.11 13:45:02 USDCHF 50020 OBS My_OrderSymbol = USDCHF ASK = 1.02058 BID = 1.02035 BUYorSELL = DN My_Trading_Lots = 0.01 My_Slippage = 40 My_TakeProfit = 1.01908 My_StopLoss= 0.00000 My_Comment = FSC.27.13.34_.2 My_Magic_Nos = -173588486
2017.01.11 13:45:02 USDCHF 50021 OBS Ticket = 113085977
2017.01.11 13:45:02 USDCHF 50027 OBS Created Ticket = 113085977, OP = 1.02035 Magic = -173588486, MyTP = 1.01908, MySL = 0.00000
2017.01.11 13:45:02 USDCHF 50028 OBS Margin_Used = 7.61
2017.01.11 13:45:02 USDCHF 50021 OBS Ticket = 113085977
any help appreciated