//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window
extern double StopLoss    = 30;
extern double RiskPercent = 2;
  extern color  FontColor = Lime;
  extern int    FontSize=12;
  extern string FontType="Arial";
  extern string note5 = "Display the price in what corner?";
  extern string note6 = "Upper left=0; Upper right=1";
  extern string note7 = "Lower left=2; Lower right=3";
  extern int    WhatCorner=2;

//
//
//
//
//

int init()   { return(0); }
int deinit() {
  ObjectDelete("Lots_Text");
 return(0);
}
int start()  
{
   string strLots;
   double pipValue = MarketInfo(Symbol(),MODE_TICKVALUE); if (Digits==3 || Digits==5) pipValue *= 10;
   double step     = MarketInfo(Symbol(),MODE_LOTSTEP);
      int norm     = 0;
            if (step==1)    norm = 0;
            if (step==0.1)  norm = 1;
            if (step==0.01) norm = 2;
   double minLot = MarketInfo(Symbol(),MODE_MINLOT);
   double maxLot = MarketInfo(Symbol(),MODE_MAXLOT);
   double lots   = AccountBalance()*(RiskPercent/100.0)/(StopLoss*pipValue);
          lots   = NormalizeDouble(lots,norm);
          
          //
          //
          //
          //
          //
          
          double actualRisk; 
          string comment = DoubleToStr(StopLoss,0)+"SL     "+DoubleToStr(RiskPercent,0)+"% risk      "+DoubleToStr(lots,norm);
          if (lots<minLot)
            {
               actualRisk = (100*minLot*StopLoss*pipValue)/AccountBalance();
               comment = "lot size less than minimal allowed lot for risk and stop loss setting\n"+
                         "calculated lot size : "+DoubleToStr(lots,norm)+" minimal allowed : "+DoubleToStr(minLot,norm)+"\n"+
                         "risk with minimal lot size and stop loss set to : "+DoubleToStr(StopLoss,2)+"pips is : "+DoubleToStr(actualRisk,2)+"%";
            }
//          Comment(comment);
   strLots = "Lots : " + DoubleToStr(lots, norm);
  	if(ObjectFind("Lots_Text") != 0)
   {
     ObjectCreate("Lots_Text", OBJ_LABEL, 0, 0, 0);
     ObjectSet("Lots_Text", OBJPROP_CORNER, WhatCorner);
     ObjectSet("Lots_Text", OBJPROP_XDISTANCE, 1);
     ObjectSet("Lots_Text", OBJPROP_YDISTANCE, 12);
   }
   ObjectSetText("Lots_Text", strLots, FontSize, FontType, FontColor);
   return(0);
}