I've attached the code for reference. But I am having issue on the strategy tester because eventhough the TP of Position 1 is hit, the SL did not moved to the entry price.
You have not posted any code, use the code button (Alt+S) when pasting code.
The Fundamentals of Testing in MetaTrader 5
- www.mql5.com
The idea of automated trading is appealing by the fact that the trading robot can work non-stop for 24 hours a day, seven days a week. The robot does not get tired, doubtful or scared, it's is totally free from any psychological problems. It is sufficient enough to clearly formalize the trading rules and implement them in the algorithms, and...
Keith Watford:
Apologies Keith. I have updated the code. I thought it was added yesterday. I am using a class in an include file for the the opening and modification position.I've attached the code for reference. But I am having issue on the strategy tester because eventhough the TP of Position 1 is hit, the SL did not moved to the entry price.
You have not posted any code, use the code button (Alt+S) when pasting code.
// Trade opening shortcuts ulong CTrade::Buy(string pSymbol,double pVolume,double pStop=0.000000,double pProfit=0.000000,string pComment=NULL) { ulong ticket = OpenPosition(pSymbol,ORDER_TYPE_BUY,pVolume,pStop,pProfit,pComment); return(ticket); } bool CTrailing::BreakEven(ulong pTicket,double pBreakStart) { if(PositionSelectByTicket(pTicket) == true) { request.action = TRADE_ACTION_SLTP; request.position = pTicket; long posType = PositionGetInteger(POSITION_TYPE); double currentSL = PositionGetDouble(POSITION_SL); double openPrice = PositionGetDouble(POSITION_PRICE_OPEN); string symbol = PositionGetString(POSITION_SYMBOL); double point = SymbolInfoDouble(symbol,SYMBOL_POINT); int digits = (int)SymbolInfoInteger(symbol,SYMBOL_DIGITS); double breakEvenStop = openPrice; breakEvenStop = NormalizeDouble(breakEvenStop, digits); double bid = 0, ask = 0; if(posType == POSITION_TYPE_BUY) { bid = SymbolInfoDouble(symbol,SYMBOL_BID); if(bid >= pBreakStart) { request.sl = breakEvenStop; bool sent = OrderSend(request,result); } else return(false); } else if(posType == POSITION_TYPE_SELL) { ask = SymbolInfoDouble(symbol,SYMBOL_ASK); if(pBreakStart >= ask) { request.sl = breakEvenStop; bool sent = OrderSend(request,result); } else return(false); } } else return(false); return(false); }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, I am having trouble in the EA I am making.
To give a brief background:
My EA will open two positions every time a signal is given.
- One position has both TP and SL (Position 1)
- One position has SL only (Position 2)
When position 1 hits its TP, Position 2 SL will move to its Entry Price.
I've attached the code for reference. But I am having issue on the strategy tester because eventhough the TP of Position 1 is hit, the SL did not moved to the entry price.
Any advice on how to solve this issue will be really appreciated. Thank you very much.