Calculating smallest possible allowed stop loss using STOP_LEVEL

 

In a custom trade class I am updating, I just want to detect if the stop loss size is too small and display a helpful message if it is the case.

Here is my code, it's custom but self explanatory

bool Trade::CheckStopLimits(const TradeOrder &order) const {
   
   int currentSLPoints = _chartAPI.PriceDistanceToPoints( MathAbs(order.entryPrice - order.stopLossPrice) );
   int minPoints = ( _chartAPI.StopLevelPoints() + _chartAPI.SpreadPoints() );
   
   // Stop loss size is at least the legal limit
   if( currentSLPoints >= minPoints ) 
      return true;
   
   // User notification are disabled just return a fail here   
   if( !_userNotificationsEnabled ) 
      return false;  
}

I found a test market with a whopping 160 point stop level limit and 80 points in spread.

From my trial and error testing, it seems that it will not accept any orders unless the stop loss size is at least the stop level limit plus market spread.

Is this the correct math? 

I was only testing market orders. But I assume pending orders will go through to the broker fine, and actually place like a successful trade - but when they try to convert to a market order, they will fail quietly if the stop loss size is too small.

Let me know if I have this correct.

 
dazamate:

In a custom trade class I am updating, I just want to detect if the stop loss size is too small and display a helpful message if it is the case.

Here is my code, it's custom but self explanatory

I found a test market with a whopping 160 point stop level limit and 80 points in spread.

From my trial and error testing, it seems that it will not accept any orders unless the stop loss size is at least the stop level limit plus market spread.

Is this the correct math? 

I was only testing market orders. But I assume pending orders will go through to the broker fine, and actually place like a successful trade - but when they try to convert to a market order, they will fail quietly if the stop loss size is too small.

Let me know if I have this correct.

Pending orders are okay as long as they are "stop level" away from the closest price point (ask , bid)

Personally ,if the sl is smaller than the stop level i provide a multiple to the user so they can choose to replace it with a stop 1+x times the limit.(if you are one point above the limit and the market is whipsawing it may reject it again)

 
Lorentzos Roussos:

Pending orders are okay as long as they are "stop level" away from the closest price point (ask , bid)

Personally ,if the sl is smaller than the stop level i provide a multiple to the user so they can choose to replace it with a stop 1+x times the limit.(if you are one point above the limit and the market is whipsawing it may reject it again)

Yes I have some customers who like scalping, so every point needs to be accounted for.

I did find the best solution to be "stop level points" + "spread points" to be the best approach. 1 point lower than this, and the order was rejected with the invalid stops 130 error.

Reason: