To set the StopLoss and TakeProfit levels, use the CSymbolInfo trade class and the CSymbolInfo::NormalizePrice
To set the StopLoss and TakeProfit levels, use the CSymbolInfo trade class and the CSymbolInfo::NormalizePrice
Thank you for your answer. You mean somehow like that?
void Modify(string ptype,double stpl,double tkpf) { //--- New Stop Loss, New Take Profit, bid, ask double ntp,nsl,pbid,pask; long tsp=Trail_point; //--- adjust for 5 & 3 digit prices if(_Digits==5 || _Digits==3) tsp=tsp*10; //--- Check the minimal possible adjustment of the stop level long stplevel=mysymbol.StopsLevel(); if(tsp<stplevel) tsp=stplevel; if(ptype=="BUY") { pbid=mysymbol.Bid(); if(tkpf-pbid<=stplevel*_Point) { ntp=NormalizeDouble(pbid+tsp*_Point,_Digits); nsl=NormalizeDouble(pbid-tsp*_Point,_Digits); } else { ntp=NormalizeDouble(tkpf,_Digits); nsl=NormalizeDouble(pbid-tsp*_Point,_Digits); } } else//---Sell { pask=mysymbol.Ask(); if(pask-tkpf<=stplevel*_Point) { ntp=NormalizeDouble(pask-tsp*_Point,_Digits); nsl=NormalizeDouble(pask+tsp*_Point,_Digits); } else { ntp=NormalizeDouble(tkpf,_Digits); nsl=NormalizeDouble(pask+tsp*_Point,_Digits); } } if(mytrade.PositionModify(_Symbol,nsl,ntp)) { Alert("An open position position has been modified successfully!"); return; } else { Alert("The position modify request could not be completed. Error: ",mytrade.ResultRetcodeDescription()); return; } }
However it still doesn't work. I get the exact same result after testing it. I'm not quite sure if it's really this part of the code that doesn't work properly... The Backtesting graph looks pretty awkward. The EA does not only ignore the modify functio but also does not take the TakeProfits or closes the position in any way...
No, it's wrong. You do not take into account the price quotation. It is necessary so:
Forum on trading, automated trading systems and testing trading strategies
Vladimir Karputov, 2017.06.26 17:48
To set the StopLoss and TakeProfit levels, use the CSymbolInfo trade class and the CSymbolInfo::NormalizePrice
Example: N-_Candles_v4:
//+------------------------------------------------------------------+ //| Open Buy position | //+------------------------------------------------------------------+ void OpenBuy(double sl,double tp) { sl=m_symbol.NormalizePrice(sl); tp=m_symbol.NormalizePrice(tp); ... //+------------------------------------------------------------------+ //| Open Sell position | //+------------------------------------------------------------------+ void OpenSell(double sl,double tp) { sl=m_symbol.NormalizePrice(sl); tp=m_symbol.NormalizePrice(tp); ...
To set the StopLoss and TakeProfit levels, use the CSymbolInfo trade class and the CSymbolInfo::NormalizePrice
Your code use trailing stop point only. Before send command PositionModify you must compare trailing stop point with stop level
like this
int stop_level = (int)SymbolInfoInteger(eaposition.Symbol(), SYMBOL_TRADE_STOPS_LEVEL);
Your code use trailing stop point only. Before send command PositionModify you must compare trailing stop point with stop level
like this
What code? I have a lot of codes: for beginners, for those who already know. Are you sure you understand what you are talking about? Have you read the article THE CHECKS A TRADING ROBOT MUST PASS BEFORE PUBLICATION IN THE MARKET ? Have you read the code of 'Trading engine 4.mq5'?

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys
I'm new to the mql5 programming and I want to modify my open positions. But if i run the EA in a Backtest, I always get the "Error: Invalid Stops". Can anyone help me with this?