-
Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum #25 (2019)
Messages Editor
Forum rules and recommendations - General - MQL5 programming forum (2023) -
Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you?
Code debugging - Developing programs - MetaEditor Help
Error Handling and Logging in MQL5 - MQL5 Articles (2015)
Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
Please EDIT your post and use the CODE button (Alt-S) when inserting code.
The attached code tries to move stoploss to breakeven when current price is "InpBE" risk multiple away from entry, so if user input "1.0" as InpBE, sl will be moved to entry + Inpbuffer points when price is 1 RR multiple from entry. The function i wrote here does not move my stop, Can anyone help me identify why? Im new to mql5 in eneral. Any help will be appreciated :)
General debugging approach: put Print statements at key points when values change and output the key values.
Right now, we don't know where it's failing. Is it the newSL/currSL comparison? What are the values of newSL and currSL at that point?
Or is it failing on the PositionModify? In which case you need the return code, which you can get with trade.ResultRetcode().
You might also need to check if it's a valid stop loss value. Depending on the specifications of the symbol, is it possible that it's trying to set the stop loss too close to the current price?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The attached code tries to move stoploss to breakeven when current price is "InpBE" risk multiple away from entry, so if user input "1.0" as InpBE, sl will be moved to entry + Inpbuffer points when price is 1 RR multiple from entry. The function i wrote here does not move my stop, Can anyone help me identify why? Im new to mql5 in eneral. Any help will be appreciated :)
...
...