Max Lot indicator for MT4 (not displaying anything)

 

This is a very old code and is not working on the current build of MT4

https://www.mql5.com/ru/code/10769


I'm not an MQL4 developer, this is an attempt to convert it, but nothing is seen on the chart:


//+------------------------------------------------------------------+
//|                                                      MAX_LOT.mq4 |
//|                                                          Argon71 |
//|                                      http://argon71.blogspot.com |
//+------------------------------------------------------------------+
#property copyright "Argon71"
#property link      "http://argon71.blogspot.com"
#property indicator_chart_window

input int Lot = 100000;  // Standard lot value in trading.
input int Leverage = 0;  // If the leverage value is known, it is better to enter it manually.

int AL;
int Find;
double AFM;
string AC;
double LotS;
double LotB;
string OutS;
string OutB;

//+------------------------------------------------------------------+
//| Deinitialization when the indicator is removed                    |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   // Simply delete all created objects
   ObjectDelete(0,"MAX Lot for Sell");
   ObjectDelete(0,"MAX Lot for Buy");
   ObjectDelete(0,"Leverage");
  }
//+------------------------------------------------------------------+
//| Start of execution                                                |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   if (Leverage == 0) 
      AL = AccountLeverage(); // Returns the leverage value for the current account. 
   else 
      AL = Leverage;

   AFM = AccountFreeMargin(); // Returns the value of free margin allowed to open positions on the current account.
   AC = AccountCurrency(); // Returns the name of the currency for the current account.
   Find = StringFind(Symbol(), AC, 0); // Searches for the name of the currency for the current account in the chart name.

   // Calculation of the maximum lot value
   if (Find == 0) { // Currency in the numerator:
      LotS = AFM * AL / Lot;
      LotB = LotS;
   }
   else if (Find == 3) { // Currency in the denominator:
      LotS = AFM * AL / (Lot * Ask);
      LotB = AFM * AL / (Lot * Bid);
   }
   else {
      AFM = -1.0; // Currency not found - skip.
   }

   // Output text on the chart
   if (AFM > 0) {
      OutS = "MAX Lot for Sell: " + DoubleToString(LotS, 2); // Maximum lot value for selling.
      OutB = "MAX Lot for Buy: " + DoubleToString(LotB, 2); // Maximum lot value for buying.
   }
   else {
      OutS = "You can't!"; // No possibility to make a deal.
      OutB = OutS;
   }

   // MAX Lot for Sell - Red color
   if (!ObjectFind("MAX Lot for Sell")) {
      ObjectCreate("MAX Lot for Sell", OBJ_LABEL, 0, 0, 0);
   }
   ObjectSetText("MAX Lot for Sell", OutS, 8, "Comic Sans MS", clrTomato);
   ObjectSetInteger(0, "MAX Lot for Sell", OBJPROP_CORNER, 0);
   ObjectSetInteger(0, "MAX Lot for Sell", OBJPROP_XDISTANCE, 5);
   ObjectSetInteger(0, "MAX Lot for Sell", OBJPROP_YDISTANCE, 10);

   // MAX Lot for Buy - Blue color
   if (!ObjectFind("MAX Lot for Buy")) {
      ObjectCreate("MAX Lot for Buy", OBJ_LABEL, 0, 0, 0);
   }
   ObjectSetText("MAX Lot for Buy", OutB, 8, "Comic Sans MS", clrLightSkyBlue);
   ObjectSetInteger(0, "MAX Lot for Buy", OBJPROP_CORNER, 0);
   ObjectSetInteger(0, "MAX Lot for Buy", OBJPROP_XDISTANCE, 5);
   ObjectSetInteger(0, "MAX Lot for Buy", OBJPROP_YDISTANCE, 22);

   // Leverage - Yellow color
   if (!ObjectFind("Leverage")) {
      ObjectCreate("Leverage", OBJ_LABEL, 0, 0, 0);
   }
   ObjectSetText("Leverage", "(Leverage 1:" + IntegerToString(AL) + ")", 8, "Comic Sans MS", clrYellow);
   ObjectSetInteger(0, "Leverage", OBJPROP_CORNER, 0);
   ObjectSetInteger(0, "Leverage", OBJPROP_XDISTANCE, 5);
   ObjectSetInteger(0, "Leverage", OBJPROP_YDISTANCE, 36);

   return(rates_total);
  }
//+------------------------------------------------------------------+
MAX_LOT
MAX_LOT
  • www.mql5.com
Рассчитывает максимальный лот исходя из свободных средств. Очень полезен в конкурсах трейдеров.
 

Nevermind, here is a script solution instead of an indicator


It should be compiled in MQL4/Scripts

Files:
Max_Lot.mq4  21 kb