How do you get a position: by symbol or by ticket?
By Symbol.
for(int i=0;i<PositionsTotal();i++){ ulong iTicket=PositionGetTicket(i); if(PositionGetString(POSITION_SYMBOL)==SName){
By Symbol.
Is your trading account type: netting or hedging?
Is your trading account type: netting or hedging?
Hedging.
Hedging.
Take a position on the ticket.
Standard cycle:
for(int i=PositionsTotal()-1; i>=0; i--) if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==InpMagic) { if(m_position.PositionType()==POSITION_TYPE_BUY) { } if(m_position.PositionType()==POSITION_TYPE_SELL) { } }
Take a position on the ticket.
Standard cycle:
That's the same I wrote.
That's the same I wrote.
You haven't written anything. You choose a symbol position on the hedge account - you are making a mistake.
Correct your mistake. Read the help.
You haven't written anything. You choose a symbol position on the hedge account - you are making a mistake.
Correct your mistake. Read the help.
I just want the AutoSL to trigger when larger than selected ratio.
if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){ //+-------------------------------------- AutoRisk ---! double AutoSL=NormalizeDouble(PO-(TP-PO)/1.618,SDigits); if(PositionGetDouble(POSITION_SL)<AutoSL){ if(!trade.PositionModify(iTicket,AutoSL,TP)){ Print("PositionModify error ",trade.ResultRetcode()); return; } }
I just want the AutoSL to trigger when larger than selected ratio.
Until now, you haven't shown how you choose a position. Correct your mistake - the position must be selected by ticket, not by symbol.
See the example above. Read the help.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi there I wrote this code to set AutoSL based on TP distance, as I've written it only has to change SL if manual is larger than auto. This way, I could manually breakeven an order once reached TP1:
The problem I'm facing is that AutoSL is set automaticly even when SL is lesser than this value, thus I can't breakeven. But I've clearly specificied the rule to AutoSL just when SL is larger than this value.
Don't actually know why isn't working, hope someone can help on this matter. Thank you in advance.