Minimum/Maximun levels.

 

Hello, good day, fellow programmers.

I wanted to ask if there is a better way to get the minimum/maximun values.

I use this function to add and/or subtract to open a position, either buy or sell. but I get different results when changing the values, for example from 1 to another value, for example 5.

It is for a multi-symbol advisor, so I just multiply the value by the points and that's it. but I have been reading the documentation that the SYMBOL_TRADE_FREEZE_LEVEL and SYMBOL_TRADE_STOPS_LEVEL functions

They return the value in "points" and it would not be necessary to multiply it by the points again, would it?

I'd appreciate your help.


//--- GetMinTradeLevel
double GetMinTradeLevel(string symbol)
  {
   int freezeLevel = MathMax(1, MathMin((int)SymbolInfoInteger(symbol, SYMBOL_TRADE_FREEZE_LEVEL), 100));
   int stopsLevel = MathMax(1, MathMin((int)SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL), 100));
   return MathMin(freezeLevel, stopsLevel);
  }
//---
 
Before thinking about a better way, you should focus on the correct way. Doing it your way, you should consider the Max and not the Min.
 

Hi Alan, thanks for your comment, I've been doing some tests and I think this new version is more robust.

I look forward to comments and/or suggestions.

//---
double GetMinTradeLevel(string symbol)
  {
   double minLevel = -1.0;
   double freezeLevel = -1.0;
   double stopsLevel = -1.0;

   freezeLevel = (double)SymbolInfoInteger(symbol, SYMBOL_TRADE_FREEZE_LEVEL);
   stopsLevel = (double)SymbolInfoInteger(symbol, SYMBOL_TRADE_STOPS_LEVEL);
   minLevel = MathMax(freezeLevel, stopsLevel);

   if(freezeLevel == -1 || stopsLevel == -1 || minLevel == -1)
     {
      IsError("Freeze level or Stops level not available for the symbol (-1) " + symbol, __FUNCTION__);
      return -1;
     }

   if(minLevel <= 100.0 && minLevel >= 0.0)
      minLevel += 1.0;
   else
      if(minLevel >= 100.0)
         minLevel = 100.0;

   return minLevel;
  }
//---