How to get the min stop loss aloud

 
So I was playing aroun d with one of my tests an d set my stop loss to 7. I then fire d off my run last night. It faile d to take tra des, after several hours to day attempting to figure out where I went wrong in my co de, I rebuilt all my co de from several versions back, trying to fin d the bug. Turns out that the stop loss was set to 7, I guess the broker does not allouw a stop shorter than that. BUT, in one of my versions of the co de, I compare d the stop loss to MarketInfo(Symbol(), MODE_STOPLEVEL)) an d it still alou d the stop value, but woul d still get a 130 error when attempting to sen dOr der. Finally, I got a suspicion this was the problem, so I manually change d it from 7 to 20, the next thing you know it was working fine. Is there a way to make sure the user has entere d the min stop loss distance? If so, can someone share that co de snippet with me?
 
LEHayes wrote >>
So I was playing aroun d with one of my tests an d set my stop loss to 7. I then fire d off my run last night. It faile d to take tra des, after several hours to day attempting to figure out where I went wrong in my co de, I rebuilt all my co de from several versions back, trying to fin d the bug. Turns out that the stop loss was set to 7, I guess the broker does not allouw a stop shorter than that. BUT, in one of my versions of the co de, I compare d the stop loss to MarketInfo(Symbol(), MODE_STOPLEVEL)) an d it still alou d the stop value, but woul d still get a 130 error when attempting to sen dOr der. Finally, I got a suspicion this was the problem, so I manually change d it from 7 to 20, the next thing you know it was working fine. Is there a way to make sure the user has entere d the min stop loss distance? If so, can someone share that co de snippet with me?

Ok, I have just done some searching where I was lead to: https://book.mql4.com/trading/orders

However, it only talks of the minimum distance. There is not constant in MarketInfo that refers to this value, in the example, they use EURUSD and it's min value in the example is 5 or .0005. There has to be some way of finding it dynamically. Still searching.

 
LEHayes wrote >>

Ok, I have just done some searching where I was lead to: https://book.mql4.com/trading/orders

However, it only talks of the minimum distance. There is not constant in MarketInfo that refers to this value, in the example, they use EURUSD and it's min value in the example is 5 or .0005. There has to be some way of finding it dynamically. Still searching.

Ok, found this:

https://book.mql4.com/appendix/limits

There are charts there that show how it's expected.

So the code I used was:

   if (StopLoss > 0)
   {
      if (StopLoss <= MarketInfo(Symbol(), MODE_STOPLEVEL))
      {
         Print("StopLoss is less than allowed stop level of ", MarketInfo(Symbol(), MODE_STOPLEVEL), " changing to: ", MarketInfo(Symbol(), MODE_STOPLEVEL));
         StopLoss = MarketInfo(Symbol(), MODE_STOPLEVEL);
      }
      sl = StopLoss * PipPoints;
   }

I changed it to this:

   if (StopLoss > 0)
   {
      sl = StopLoss * PipPoints;
      if (sl < MarketInfo(Symbol(), MODE_STOPLEVEL))
      {
         Print("StopLoss is less than allowed stop level of ", MarketInfo(Symbol(), MODE_STOPLEVEL), " changing to: ", MarketInfo(Symbol(), MODE_STOPLEVEL));
         sl = MarketInfo(Symbol(), MODE_STOPLEVEL);
      }
      
   }
I didn't have the PipPoints calculated against the stoploss first. That was the root of my evil.
 

Read the documentation again MODE_STOPLEVEL is in points, not pips

On IBFX Digits=5 MODE_STOPLEVEL=30 ie, .00030

 
LEHayes wrote >>
So I was playing aroun d with one of my tests an d set my stop loss to 7. I then fire d off my run last night. It faile d to take tra des, after several hours to day attempting to figure out where I went wrong in my co de, I rebuilt all my co de from several versions back, trying to fin d the bug. Turns out that the stop loss was set to 7, I guess the broker does not allouw a stop shorter than that. BUT, in one of my versions of the co de, I compare d the stop loss to MarketInfo(Symbol(), MODE_STOPLEVEL)) an d it still alou d the stop value, but woul d still get a 130 error when attempting to sen dOr der. Finally, I got a suspicion this was the problem, so I manually change d it from 7 to 20, the next thing you know it was working fine. Is there a way to make sure the user has entere d the min stop loss distance? If so, can someone share that co de snippet with me?

Hi

some brokers not allow to use stoploss and take profit, or trades doesn't run with stoploss and take profit with certain brokers

you can turn around them, by specifying stoploss or take profit in closing conditions.

in your case see below:

if you want to keep the StopLoss fixed amount (without moving it during trading), you can make stoploss as one of your closing conditions to any figure you want.

e.g ( you can change BID by ASK, as you like)

if(OrderType()==OP_BUY)

{ if ( Ask<(OrderOpenPrice()-7*Point))
OrderClose(OrderTicket(),OrderLots(),Bid,3); continue;

}

-------------------
if(OrderType()==OP_SELL)

{if ( Bid>(OrderOpenPrice()+7*Point))
OrderClose(OrderTicket(),OrderLots(),Ask,3); continue;

Reason: