# Can't breakeven

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:

```            if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY){
//+-------------------------------------- AutoRisk ---!
double AutoSL=NormalizeDouble(PO-(TP-PO)/1.618,SDigits);
if(PositionGetDouble(POSITION_SL)<AutoSL){ // Modify
return;
}
}

if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL){
//+-------------------------------------- AutoRisk ---!
double AutoSL=NormalizeDouble(PO+(PO-TP)/1.618,SDigits);
if(PositionGetDouble(POSITION_SL)==0
||PositionGetDouble(POSITION_SL)>AutoSL){ // Modify
return;
}
}```

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.

How do you get a position: by symbol or by ticket?

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){```

David Diez :

By Symbol.

Hedging.

David Diez :

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_SELL)
{

}
}```

Take a position on the ticket.

Standard cycle:

That's the same I wrote.

David Diez :

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.

You haven't written anything. You choose a symbol position on the hedge account - you are making a mistake.

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){
return;
}
}```

David Diez :

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.

Reason: