Indicator Isnt working right and I cant figure out why on MT4

 

For some reason on certain charts the indicator isnt showing all the text that it is supposed to, specifically the 8'th text object on certain charts for example AUDUSD and GBPUSD.  Also if someone could hint as to how I could have this indicator update live for every new tick that comes in that would be greatly appreciated.

Yes I know I should have comments, but I dont need them for my personal projects, if this brings up any complications please let me know if you need any additional information to help me fix this problem.

 Thank You!! 

 

double a = MarketInfo(NULL,MODE_MARGINREQUIRED);

double b = a/2;

double c = a/10;

double d = AccountInfoDouble(ACCOUNT_EQUITY);

double e = MathFloor(d*90/a)/100;

double f = SymbolInfoDouble(NULL,SYMBOL_TRADE_TICK_VALUE);

double g = e*f;



string Lot_Rule_0 = "Lot Size 1";

string Lot_Rule_1 = DoubleToString(a,2);

string Lot_Rule_2 = "Lot Size .5";

string Lot_Rule_3 = DoubleToString(b,2);

string Lot_Rule_4 = "Lot Size .1";

string Lot_Rule_5 = DoubleToString(c,2);

string Lot_Rule_6 = "PPP at 90%";

string Lot_Rule_7 = DoubleToString(g,2);

string Lot_Rule_8 = "90% Risk of Margin ";

string Lot_Rule_9 = DoubleToString(e,2);

int x = 900;

color colour_Rule  =RoyalBlue;

string fontname    = "kkk";

int fontsize = 7;


//+------------------------------------------------------------------+

int init(){

IndicatorShortName("Keep Rules");


   return(0);

}

//+------------------------------------------------------------------+

int deinit(){

ObjectDelete(Lot_Rule_0);

ObjectDelete(Lot_Rule_1);

ObjectDelete(Lot_Rule_2);

ObjectDelete(Lot_Rule_3);

ObjectDelete(Lot_Rule_4);

ObjectDelete(Lot_Rule_5);

ObjectDelete(Lot_Rule_6);

ObjectDelete(Lot_Rule_7);

ObjectDelete(Lot_Rule_8);

ObjectDelete(Lot_Rule_9);

}


//+------------------------------------------------------------------+

int start()  {

   setLabel(Lot_Rule_0,Lot_Rule_0,colour_Rule,4,x,5,false,fontsize,fontname);

   setLabel(Lot_Rule_1,Lot_Rule_1,colour_Rule,4,x,20,false,fontsize,fontname);

   setLabel(Lot_Rule_2,Lot_Rule_2,colour_Rule,4,x,35,false,fontsize,fontname);

   setLabel(Lot_Rule_3,Lot_Rule_3,colour_Rule,4,x,50,false,fontsize,fontname);

   setLabel(Lot_Rule_4,Lot_Rule_4,colour_Rule,4,x,65,false,fontsize,fontname);

   setLabel(Lot_Rule_5,Lot_Rule_5,colour_Rule,4,x,80,false,fontsize,fontname);

   setLabel(Lot_Rule_6,Lot_Rule_6,colour_Rule,4,x,95,false,fontsize,fontname);

   setLabel(Lot_Rule_7,Lot_Rule_7,colour_Rule,4,x,110,false,fontsize,fontname);

   setLabel(Lot_Rule_8,Lot_Rule_8,colour_Rule,4,x,125,false,fontsize,fontname);

   setLabel(Lot_Rule_9,Lot_Rule_9,colour_Rule,4,x,140,false,fontsize,fontname);

}

//+------------------------------------------------------------------+

void setLabel(string name, string text, color col, int corner,

            int x, int y, bool back = false, int fontsize = 12, 

            string fontname = "MS Sans Serif") {

   if (ObjectFind(name)==-1){

      // aaa

      ObjectCreate(name, OBJ_LABEL, WindowOnDropped(),1,0,0);

      ObjectSetText(name, text, fontsize, fontname, col);

      ObjectSet(name, OBJPROP_CORNER, corner);

      ObjectSet(name, OBJPROP_BACK,back);

      ObjectSet(name, OBJPROP_XDISTANCE, x);

      ObjectSet(name, OBJPROP_YDISTANCE, y);          

   }else{

      ObjectSetText(name, text, fontsize, fontname, col);

      ObjectSet(name, OBJPROP_CORNER, corner);

      ObjectSet(name, OBJPROP_BACK,back);

      ObjectSet(name, OBJPROP_XDISTANCE, x);

      ObjectSet(name, OBJPROP_YDISTANCE, y); 

   }  

Files:
 
Seforoyl:

For some reason on certain charts the indicator isnt showing all the text that it is supposed to, specifically the 8'th text object on certain charts for example AUDUSD and GBPUSD.  Also if someone could hint as to how I could have this indicator update live for every new tick that comes in that would be greatly appreciated.

Yes I know I should have comments, but I dont need them for my personal projects, if this brings up any complications please let me know if you need any additional information to help me fix this problem.

 Thank You!! 

 

double a = MarketInfo(NULL,MODE_MARGINREQUIRED);

double b = a/2;

double c = a/10;

double d = AccountInfoDouble(ACCOUNT_EQUITY);

double e = MathFloor(d*90/a)/100;

double f = SymbolInfoDouble(NULL,SYMBOL_TRADE_TICK_VALUE);

double g = e*f;



string Lot_Rule_0 = "Lot Size 1";

string Lot_Rule_1 = DoubleToString(a,2);

string Lot_Rule_2 = "Lot Size .5";

string Lot_Rule_3 = DoubleToString(b,2);

string Lot_Rule_4 = "Lot Size .1";

string Lot_Rule_5 = DoubleToString(c,2);

string Lot_Rule_6 = "PPP at 90%";

string Lot_Rule_7 = DoubleToString(g,2);

string Lot_Rule_8 = "90% Risk of Margin ";

string Lot_Rule_9 = DoubleToString(e,2);

int x = 900;

color colour_Rule  =RoyalBlue;

string fontname    = "kkk";

int fontsize = 7;


//+------------------------------------------------------------------+

int init(){

IndicatorShortName("Keep Rules");


   return(0);

}

//+------------------------------------------------------------------+

int deinit(){

ObjectDelete(Lot_Rule_0);

ObjectDelete(Lot_Rule_1);

ObjectDelete(Lot_Rule_2);

ObjectDelete(Lot_Rule_3);

ObjectDelete(Lot_Rule_4);

ObjectDelete(Lot_Rule_5);

ObjectDelete(Lot_Rule_6);

ObjectDelete(Lot_Rule_7);

ObjectDelete(Lot_Rule_8);

ObjectDelete(Lot_Rule_9);

}


//+------------------------------------------------------------------+

int start()  {

   setLabel(Lot_Rule_0,Lot_Rule_0,colour_Rule,4,x,5,false,fontsize,fontname);

   setLabel(Lot_Rule_1,Lot_Rule_1,colour_Rule,4,x,20,false,fontsize,fontname);

   setLabel(Lot_Rule_2,Lot_Rule_2,colour_Rule,4,x,35,false,fontsize,fontname);

   setLabel(Lot_Rule_3,Lot_Rule_3,colour_Rule,4,x,50,false,fontsize,fontname);

   setLabel(Lot_Rule_4,Lot_Rule_4,colour_Rule,4,x,65,false,fontsize,fontname);

   setLabel(Lot_Rule_5,Lot_Rule_5,colour_Rule,4,x,80,false,fontsize,fontname);

   setLabel(Lot_Rule_6,Lot_Rule_6,colour_Rule,4,x,95,false,fontsize,fontname);

   setLabel(Lot_Rule_7,Lot_Rule_7,colour_Rule,4,x,110,false,fontsize,fontname);

   setLabel(Lot_Rule_8,Lot_Rule_8,colour_Rule,4,x,125,false,fontsize,fontname);

   setLabel(Lot_Rule_9,Lot_Rule_9,colour_Rule,4,x,140,false,fontsize,fontname);

}

//+------------------------------------------------------------------+

void setLabel(string name, string text, color col, int corner,

            int x, int y, bool back = false, int fontsize = 12, 

            string fontname = "MS Sans Serif") {

   if (ObjectFind(name)==-1){

      // aaa

      ObjectCreate(name, OBJ_LABEL, WindowOnDropped(),1,0,0);

      ObjectSetText(name, text, fontsize, fontname, col);

      ObjectSet(name, OBJPROP_CORNER, corner);

      ObjectSet(name, OBJPROP_BACK,back);

      ObjectSet(name, OBJPROP_XDISTANCE, x);

      ObjectSet(name, OBJPROP_YDISTANCE, y);          

   }else{

      ObjectSetText(name, text, fontsize, fontname, col);

      ObjectSet(name, OBJPROP_CORNER, corner);

      ObjectSet(name, OBJPROP_BACK,back);

      ObjectSet(name, OBJPROP_XDISTANCE, x);

      ObjectSet(name, OBJPROP_YDISTANCE, y); 

   }  

you should always use the SRC button when posting code.  Its more professional!!

The name in ObjectCreate has to be unique.  In your case Lot_Rule_7 and Lot_Rule_9 has the same name for GBPUSD and AUDUSD.  MetaQutoes deletes the first label created and leaves the second one in. (Lot_Rule_7 gets deleted).  

If you want this to update on every tick, then you should declare the variables in "start" body.  You are using an old programming language no longer supported by MetaQuotes, I suggest you move to newer version that uses  OnCalculate(...... instead of start(....

Here is the revised code:

#property indicator_chart_window
#property indicator_buffers 0

string Lot_Rule_0,Lot_Rule_1,Lot_Rule_2,Lot_Rule_3,Lot_Rule_4,Lot_Rule_5,Lot_Rule_6,Lot_Rule_7,Lot_Rule_8,Lot_Rule_9;
int x = 900;
color colour_Rule  =RoyalBlue;
string fontname    = "kkk";
int fontsize = 7;

//+------------------------------------------------------------------+
int init(){
IndicatorShortName("Keep Rules");

   return(0);
}
//+------------------------------------------------------------------+
int deinit(){
ObjectDelete("0"+Lot_Rule_0);
ObjectDelete("1"+Lot_Rule_1);
ObjectDelete("2"+Lot_Rule_2);
ObjectDelete("3"+Lot_Rule_3);
ObjectDelete("4"+Lot_Rule_4);
ObjectDelete("5"+Lot_Rule_5);
ObjectDelete("6"+Lot_Rule_6);
ObjectDelete("7"+Lot_Rule_7);
ObjectDelete("8"+Lot_Rule_8);
ObjectDelete("9"+Lot_Rule_9);
}

//+------------------------------------------------------------------+
int start()  {

double a = MarketInfo(NULL,MODE_MARGINREQUIRED);
double b = a/2;
double c = a/10;
double d = AccountInfoDouble(ACCOUNT_EQUITY);
double e = MathFloor(d*90/a)/100;
double f = SymbolInfoDouble(NULL,SYMBOL_TRADE_TICK_VALUE);
double g = e*f;


Lot_Rule_0 = "Lot Size 1";
Lot_Rule_1 = DoubleToString(a,2);
Lot_Rule_2 = "Lot Size .5";
Lot_Rule_3 = DoubleToString(b,2);
Lot_Rule_4 = "Lot Size .1";
Lot_Rule_5 = DoubleToString(c,2);
Lot_Rule_6 = "PPP at 90%";
Lot_Rule_7 = DoubleToString(g,2);
Lot_Rule_8 = "90% Risk of Margin ";
Lot_Rule_9 = DoubleToString(e,2);



   setLabel("0"+Lot_Rule_0,Lot_Rule_0,colour_Rule,4,x,5,false,fontsize,fontname);
   setLabel("1"+Lot_Rule_1,Lot_Rule_1,colour_Rule,4,x,20,false,fontsize,fontname);
   setLabel("2"+Lot_Rule_2,Lot_Rule_2,colour_Rule,4,x,35,false,fontsize,fontname);
   setLabel("3"+Lot_Rule_3,Lot_Rule_3,colour_Rule,4,x,50,false,fontsize,fontname);
   setLabel("4"+Lot_Rule_4,Lot_Rule_4,colour_Rule,4,x,65,false,fontsize,fontname);
   setLabel("5"+Lot_Rule_5,Lot_Rule_5,colour_Rule,4,x,80,false,fontsize,fontname);
   setLabel("6"+Lot_Rule_6,Lot_Rule_6,colour_Rule,4,x,95,false,fontsize,fontname);
   setLabel("7"+Lot_Rule_7,Lot_Rule_7,colour_Rule,4,x,110,false,fontsize,fontname);
   setLabel("8"+Lot_Rule_8,Lot_Rule_8,colour_Rule,4,x,125,false,fontsize,fontname);
   setLabel("9"+Lot_Rule_9,Lot_Rule_9,colour_Rule,4,x,140,false,fontsize,fontname);
}
//+------------------------------------------------------------------+
void setLabel(string name, string text, color col, int corner,
            int x1, int y, bool back = false, int ifontsize = 12, 
            string sfontname = "MS Sans Serif") {
   if (ObjectFind(name)==-1){
      // aaa
      ObjectCreate(name, OBJ_LABEL, WindowOnDropped(),1,0,0);
      ObjectSetText(name, text, fontsize, fontname, col);
      ObjectSet(name, OBJPROP_CORNER, corner);
      ObjectSet(name, OBJPROP_BACK,back);
      ObjectSet(name, OBJPROP_XDISTANCE, x);
      ObjectSet(name, OBJPROP_YDISTANCE, y);          
   }else{
      ObjectSetText(name, text, fontsize, fontname, col);
      ObjectSet(name, OBJPROP_CORNER, corner);
      ObjectSet(name, OBJPROP_BACK,back);
      ObjectSet(name, OBJPROP_XDISTANCE, x);
      ObjectSet(name, OBJPROP_YDISTANCE, y); 
   }  
}
 
Thank you so much for the help, I've never coded before so this was quite a struggle, but your a savior. Cheers.
Reason: