Download MetaTrader 5

Help with positioning indicator in bottom left hand corner

To add comments, please log in or register
Interested in MetaTrader 5 features? Learn more about them!
kcomplex
378
kcomplex 2013.11.27 12:15 

Could someone please help me amend this code so the text is shown in the bottom left hand corner of the chart window rather than the top left corner which is where it currently appears?

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window
extern double StopLoss    = 30;
extern double RiskPercent = 10;

//
//
//
//
//

int init()   { return(50); }
int deinit() { 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()*(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);
   return(0);
}
Ian Flanagan
549
Ian Flanagan 2013.11.27 12:32  

Comment is always in the top left. A very cheap, quick way is to add \n a few times to the comment, eg:

               comment = "\n\n\n\n\n\n\n\n\n\nlot 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)+"%";

Each one adds a new line so you might need a lot.

A better way if you have time is to use ObjectCreate to make a label which can be anchored to any corner (which means, it will work even if you change screen resolution).

Tjipke de Vries
6314
Tjipke de Vries 2013.11.27 14:07  

See the code of clock displaying time in main chart

to find out how to do it with Objects

kcomplex
378
kcomplex 2013.11.27 16:05  
hmmmm,,, i put the \n\n\n\n\n\n\n\n\n\n into the code as you wrote above and it didn't seem to have any effect at all. I'm just looking for an easy solution as my coding skills are bad. even if it only moved the line of text away or down a few lines that would help - its just being covered over by my one-click EA at the moment (i can't move the one click trading ea). Any ideas why its not working?
whroeder1
14470
whroeder1 2013.11.27 16:40  
kcomplex: Any ideas why its not working?
  1. You didn't save it
  2. You didn't compile it
  3. You didn't exit and restart the tester
  4. You installed in \program files* and have UAC issues.
kcomplex
378
kcomplex 2013.11.28 10:26  

I don't think it can be any of those things because when i change other parts of the code i can see the indicator has changed on the charts (except for its position). Perhaps i have misunderstood something, here is the code

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window
extern double StopLoss    = 20;
extern double RiskPercent = 10;

//
//
//
//
//

int init()   { return(50); }
int deinit() { 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()*(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 = "\n\n\n\n\n\n\n\n\n\nlot 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);
   return(0);
}
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.11.28 10:41  
kcomplex:

I don't think it can be any of those things because when i change other parts of the code i can see the indicator has changed on the charts (except for its position). Perhaps i have misunderstood something, here is the code

You missed something . . .

          string comment =   "\n\n\n\n\n\n\n\n\n\n"    + DoubleToStr(StopLoss,0)+"SL     "+DoubleToStr(RiskPercent,0)+"% risk      "+DoubleToStr(lots,norm);
whroeder1
14470
whroeder1 2013.11.28 16:03  
  1. Or simply combine
    string comment = DoubleToStr(StopLoss,0)+"SL ...
    :
         comment = "lot size less than minimal ...
    :          
    Comment(\n\n\n\n\n\n\n\n\n\n"+comment);
    
  2. kcomplex: its just being covered over by my one-click EA at the moment (i can't move the one click trading ea).
    How can you be running any code when you have a "one-click EA" running? You can't run two EAs on the same chart.
    If you mean the one-click just minimize it
To add comments, please log in or register