These are the lines:
double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits); //SET THE BID PRICE TO A VARIABLE double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits); double CurrentTP= PositionGetDouble(POSITION_TP); double CurrentSL = PositionGetDouble(POSITION_SL);
you need to hide it inside the loop.
for(int i=PositionsTotal()-1; i>=0; i--) // returns the number of current position if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if(m_position.Symbol()==Symbol()) { double Ask=SymbolInfoDouble(m_position.Symbol(),SYMBOL_ASK); double Bid=SymbolInfoDouble(m_position.Symbol(),SYMBOL_BID); double CurrentTP=PositionGetDouble(POSITION_TP); double CurrentSL=PositionGetDouble(POSITION_SL);
I didn't look further. You need to fix this error first ...
jmpmilli2019:
Hi,
Can someone tell me whats wrongs with my trailing stop code? I keep getting invalid stops, I run the function during every tick. Any help would be greatly appreciated.
You have to select orders by ticket:
for(int i=0;i<PositionsTotal();i++){ ulong iTicket=PositionGetTicket(i); if(PositionSelectByTicket(iTicket)&& PositionGetString(POSITION_SYMBOL)==_Symbol){ if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){ double TStop=(YOUR TRAILING STOP); if(TStop>PositionGetDouble(POSITION_PRICE_OPEN)){ if(TStop>PositionGetDouble(POSITION_SL)){ if(!trade.PositionModify(iTicket,TStop,PositionGetDouble(POSITION_TP))){ Print("PositionModify error ",trade.ResultRetcode()); return; } } } }
David Diez :
You have to select orders by ticket:
He does it anyway :)
//+------------------------------------------------------------------+ //| Select a position on the index | //+------------------------------------------------------------------+ bool CPositionInfo:: SelectByIndex ( const int index) { ulong ticket= PositionGetTicket (index); return (ticket> 0 ); }
Vladimir Karputov:
These are the lines:
you need to hide it inside the loop.
I didn't look further. You need to fix this error first ...
Thanks that worked. I appreciate it. I thought it was already available before the loop.
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,
Can someone tell me whats wrongs with my trailing stop code? I keep getting invalid stops, I run the function during every tick. Any help would be greatly appreciated.