//+------------------------------------------------------------------+
//|               Lot Size Calc v2   Burton 6-11-2019                |
//+------------------------------------------------------------------+

#property indicator_chart_window
extern double StopLoss1    = 30;
extern double StopLoss2    = 40;
extern double StopLoss3    = 50;
extern double RiskPercent1 = 1;
extern double RiskPercent2 = 1;
extern double RiskPercent3 = 1;
extern color font_color = Black;
extern int font_size = 10;
extern string font_face = "Arial";
extern int corner = 0; //0 - for top-left corner, 1 - top-right, 2 - bottom-left, 3 - bottom-right
extern int distance_x = 10;
extern int distance_y = 15;

//+------------------------------------------------------------------+

int init()   { return(0); }

//+------------------------------------------------------------------+

int deinit()
  {
     // Clear screen objects when removed
          
   ObjectDelete("RiskPercent");
   ObjectDelete("StopLoss");
   ObjectDelete("LotSize");
   ObjectDelete("RiskPercent2");
   ObjectDelete("StopLoss2");
   ObjectDelete("LotSize2");
   ObjectDelete("RiskPercent3");
   ObjectDelete("StopLoss3");
   ObjectDelete("LotSize3");
     return(0);
  } 

//+------------------------------------------------------------------+

int start()  
{
   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()*(RiskPercent1/100.0)/(StopLoss1*pipValue);
          lots   = NormalizeDouble(lots,norm);
   double lots2   = AccountBalance()*(RiskPercent2/100.0)/(StopLoss2*pipValue);
          lots2   = NormalizeDouble(lots2,norm);
   double lots3   = AccountBalance()*(RiskPercent3/100.0)/(StopLoss3*pipValue);
          lots3   = NormalizeDouble(lots3,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);
       
//+------------------------------------------------------------------+
          
 string text1 ="Risk %:"+RiskPercent1;        
 string text2 ="SL:"+StopLoss1;
 string text3 ="Lots:"+lots;
 
   ObjectCreate("RiskPercent", OBJ_LABEL, 0, 0, 0);
   ObjectSet("RiskPercent", OBJPROP_CORNER, corner);
   ObjectSet("RiskPercent", OBJPROP_XDISTANCE, distance_x);
   ObjectSet("RiskPercent", OBJPROP_YDISTANCE, distance_y + 15);
   ObjectSetText("RiskPercent", text1, font_size, font_face, font_color); 
          
   ObjectCreate("StopLoss", OBJ_LABEL, 0, 0, 0);
   ObjectSet("StopLoss", OBJPROP_CORNER, corner);
   ObjectSet("StopLoss", OBJPROP_XDISTANCE, distance_x + 80);
   ObjectSet("StopLoss", OBJPROP_YDISTANCE, distance_y + 15);
   ObjectSetText("StopLoss", text2, font_size, font_face, font_color); 
   
    ObjectCreate("LotSize", OBJ_LABEL, 0, 0, 0);
   ObjectSet("LotSize", OBJPROP_CORNER, corner);
   ObjectSet("LotSize", OBJPROP_XDISTANCE, distance_x + 135);
   ObjectSet("LotSize", OBJPROP_YDISTANCE, distance_y + 15);
   ObjectSetText("LotSize", text3, font_size, font_face, font_color); 
 
 //+------------------------------------------------------------------+
   
 string text4 ="Risk %:"+RiskPercent2;        
 string text5 ="SL:"+StopLoss2;
 string text6 ="Lots:"+lots2;
  
   ObjectCreate("RiskPercent2", OBJ_LABEL, 0, 0, 0);
   ObjectSet("RiskPercent2", OBJPROP_CORNER, corner);
   ObjectSet("RiskPercent2", OBJPROP_XDISTANCE, distance_x);
   ObjectSet("RiskPercent2", OBJPROP_YDISTANCE, distance_y + 35);
   ObjectSetText("RiskPercent2", text4, font_size, font_face, font_color); 
          
   ObjectCreate("StopLoss2", OBJ_LABEL, 0, 0, 0);
   ObjectSet("StopLoss2", OBJPROP_CORNER, corner);
   ObjectSet("StopLoss2", OBJPROP_XDISTANCE, distance_x + 80);
   ObjectSet("StopLoss2", OBJPROP_YDISTANCE, distance_y + 35);
   ObjectSetText("StopLoss2", text5, font_size, font_face, font_color); 
   
   ObjectCreate("LotSize2", OBJ_LABEL, 0, 0, 0);
   ObjectSet("LotSize2", OBJPROP_CORNER, corner);
   ObjectSet("LotSize2", OBJPROP_XDISTANCE, distance_x + 135);
   ObjectSet("LotSize2", OBJPROP_YDISTANCE, distance_y + 35);
   ObjectSetText("LotSize2", text6, font_size, font_face, font_color);
   
//+------------------------------------------------------------------+
   
 string text7 ="Risk %:"+RiskPercent3;        
 string text8 ="SL:"+StopLoss3;
 string text9 ="Lots:"+lots3;
  
   ObjectCreate("RiskPercent3", OBJ_LABEL, 0, 0, 0);
   ObjectSet("RiskPercent3", OBJPROP_CORNER, corner);
   ObjectSet("RiskPercent3", OBJPROP_XDISTANCE, distance_x);
   ObjectSet("RiskPercent3", OBJPROP_YDISTANCE, distance_y + 55);
   ObjectSetText("RiskPercent3", text7, font_size, font_face, font_color); 
          
   ObjectCreate("StopLoss3", OBJ_LABEL, 0, 0, 0);
   ObjectSet("StopLoss3", OBJPROP_CORNER, corner);
   ObjectSet("StopLoss3", OBJPROP_XDISTANCE, distance_x + 80);
   ObjectSet("StopLoss3", OBJPROP_YDISTANCE, distance_y + 55);
   ObjectSetText("StopLoss3", text8, font_size, font_face, font_color); 
   
   ObjectCreate("LotSize3", OBJ_LABEL, 0, 0, 0);
   ObjectSet("LotSize3", OBJPROP_CORNER, corner);
   ObjectSet("LotSize3", OBJPROP_XDISTANCE, distance_x + 135);
   ObjectSet("LotSize3", OBJPROP_YDISTANCE, distance_y + 55);
   ObjectSetText("LotSize3", text9, font_size, font_face, font_color);      
          
   return(0);
}