Percent Shows Only Zero 8-) Still Trying To Learn MQL

 
//
//                                               mtf_ma_comment.mq4
extern int MAPeriod = 20;
extern int ma_shift = 0;
extern int ma_method = 0;
extern int applied_price = 0;
/*
PERIOD_M1   1
PERIOD_M5   5
PERIOD_M15  15
PERIOD_M30  30 
PERIOD_H1   60
PERIOD_H4   240
PERIOD_D1   1440
PERIOD_W1   10080
PERIOD_MN1  43200
*/
double ExtMapBuffer1;
double ExtMapBuffer2;
double ExtMapBuffer3;
double ExtMapBuffer4;
double ExtMapBuffer5;
double ExtMapBuffer6;
double ExtMapBuffer7;
double ExtMapBuffer8;
double ExtMapBuffer9;
//
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
  Comment("");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int S=0, B=0; 
   //
   ExtMapBuffer1=iMA(NULL,43200,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer1 > Close[0]) {string MN = "Sell"; S++;} else {MN = "Buy"; B++;}   
   ExtMapBuffer2=iMA(NULL,10080,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer2 > Close[0]) {string W1 = "Sell"; S++;} else {W1 = "Buy"; B++;}  
   ExtMapBuffer3=iMA(NULL,1440,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer3 > Close[0]) {string D1 = "Sell"; S++;} else {D1 = "Buy"; B++;}  
   ExtMapBuffer4=iMA(NULL,240,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer4 > Close[0]) {string H4 = "Sell"; S++;} else {H4 = "Buy"; B++;}  
   ExtMapBuffer5=iMA(NULL,60,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer5 > Close[0]) {string H1 = "Sell"; S++;} else {H1 = "Buy"; B++;}  
   ExtMapBuffer6=iMA(NULL,30,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer6 > Close[0]) {string M30 = "Sell"; S++;} else {M30 = "Buy"; B++;}  
   ExtMapBuffer7=iMA(NULL,15,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer7 > Close[0]) {string M15 = "Sell"; S++;} else {M15 = "Buy"; B++;}  
   ExtMapBuffer8=iMA(NULL,5,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer8 > Close[0]) {string M5 = "Sell"; S++;} else {M5 = "Buy"; B++;}  
   ExtMapBuffer9=iMA(NULL,1,MAPeriod,ma_shift,ma_method,applied_price,0);
      if(ExtMapBuffer9 > Close[0]) {string M1 = "Sell"; S++;} else {M1 = "Buy"; B++;}  
      //
      if(S>B) {double Percent = ((S/9)*100); string Signal = "Sell";} 
                else {Percent = ((B/9)*100);        Signal = "Buy";}
      //
      Comment("MTF MA - SUPPORT & RESISTANCE" + 
      "\n" + "MONTH: " + MN +
      "\n" + "WEEK: " + W1 +
      "\n" + "DAY: " + D1 +
      "\n" + "4 HOUR: " + H4 +
      "\n" + "1 HOUR: " + H1 +
      "\n" + "30 MIN: " + M30 +
      "\n" + "15 MIN: " + M15 +
      "\n" + "5 MIN: " + M5 +
      "\n" + "1 MIN: " + M1 + 
      "\n" + "Percent: " + DoubleToStr(Percent,0) + "% " + Signal);
      //
   return(0);
  }
//+------------------------------------------------------------------+
Files:
 

Hi Subgenius,

Declare 'em as double

 double S=0.0, B=0.0; 

Is type casting thing (https://docs.mql4.com/basis/types/casting). Integer takes 4 bytes, while double takes 8 bytes.

:D

 
Percent = ((S/9)*100

int/int = int. 2/9=0 not .2222.

RTFM Type casting - MQL4 Documentation

Use this and you would have found Operations and Expressions - Basics of MQL4 - MQL4 Tutorial and Why does 4/6 = 0 - MQL4 forum

  1. Either change B,S to double or
  2. Use (S/9.0) or
  3. use Double(S)/9*100
    int     Int(int a){       return(a); }
    double  Double(double a){ return(a); }
    
Reason: