Please help with this variable error...

 

Hello

I have an EA and I am trying to setup different values in a condition statement usign variables, I am new to coding and seem to be getting an error: 'Digit' - variable not defined

I have been wokring for hours to try and solve it but with no success, this is what I have:

External inputs:

extern   bool       MacdVerified                    = true;
extern    int       MacdFastPeriod                  = 14;
extern    int       MacdSlowPeriod                  = 26;
extern    int       MacdSignalPeriod                = 9;
extern    int       Digits3                         = 0.001;
extern    int       Digits5                         = 0.00001;

Condition statement:

  if(Macd(i,1)>=Digit){comm=comm+"\nMacd is positive"; 

And the working out of "Digits":

double Macd(int shift,int mode=0){
   return(iMACD (Symbol (), Period (), MacdFastPeriod, MacdSlowPeriod, MacdSignalPeriod, 0, mode, shift));
}  
double Digit;

if(Digits==4)
Digit = Digits5;
if(Digits==2)
Digit = Digits3;

}

The error I mentioned above is picked up as being in the condition statement.

Thank you

Antony

 

Wrong location of

double Digit;


It should be declared under Global Variable?


Try below;

extern   bool       MacdVerified                    = true;
extern    int       MacdFastPeriod                  = 14;
extern    int       MacdSlowPeriod                  = 26;
extern    int       MacdSignalPeriod                = 9;
extern    int       Digits3                         = 0.001;
extern    int       Digits5                         = 0.00001;

double Digit;

int init() {
if(Digits==4) {
Digit = Digits5;
if(Digits==2)
Digit = Digits3;
}

OPForex
 
tonyjms2005:

Hello

I have an EA and I am trying to setup different values in a condition statement usign variables, I am new to coding and seem to be getting an error: 'Digit' - variable not defined

I have been wokring for hours to try and solve it but with no success, this is what I have:

External inputs:

Condition statement:

And the working out of "Digits":

The error I mentioned above is picked up as being in the condition statement.

Thank you

Antony

There is an obvious problem in your extern variables assignments as you are assigning double values to ints! (Digits3 and Digits5.)

The MT4 compiler is quite stupid and an earlier error can cause it to not see definitions. Your code snippet is coming after a function definition. Which function is it supposed to be in?


OPForex's code is not syntactically valid. Re-written here ...

extern   bool       MacdVerified                    = true;
extern    int       MacdFastPeriod                  = 14;
extern    int       MacdSlowPeriod                  = 26;
extern    int       MacdSignalPeriod                = 9;
extern    double    Digits3                         = 0.001;
extern    double    Digits5                         = 0.00001;

double Digit;

int init() {
     if(Digits==4)
         Digit = Digits5;

     if(Digits==2)
         Digit = Digits3;
}

 

Hi

Basically I have this condition statement:

if(Macd(i,1)>digit){comm=comm+"\nMacd is positive (At least 0.00001)";  
               

Where you see I have insterted "Digit" so when the EA is attached a pair that has four digits after the decimal it returns : 0.00001 and on a pair with two digits after the decimal, it return 0.001

Unforatunately that is not working it just returns 0.00000 for some reason.

Here is part of the EA with some of the statements, the statement in question is at the bottom:

string d_str(double in){return(DoubleToStr(in,Digits+1));}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int Pattern(){
int maxlen = 6;//maximal length of pattern<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
int minlen = 3;//minimal length of pattern
int i,c,co,ts,tc,trade=0;
double x,y,z,spr = MarketInfo(Symbol(),MODE_SPREAD)*Point*mno*2; 

//+------------------------------------------------------------------+
for(i=minlen-1;i<maxlen;i++){string comm = TimeToStr(TimeCurrent())+"\nPattern Length = "+i;
         if(Candle(i)<0){comm=comm+"\nFirst Candle is bullish "+d_str(spr)+"";// if bullish candle
        if(Close[i]<PivotLine("R2")){comm=comm+"\nFirst Candle crossed R2";
         if(Close[i]-(Pointnoreturn*Point*mno)<PivotLine(PivotResistLineName,i)-DistanceFromThePivot*Point*mno){comm=comm+"\nFirst Candle at a distance "+MathAbs(Close[i]-(PivotLine(PivotResistLineName)-DistanceFromThePivot*Point*mno))/Point+" to the Near Pivot line";
            if(Close[i]-(Pointnoreturn*Point*mno)>BB("up",i)){ comm=comm+"\nClosed out of upper band"+d_str(Close[i])+" > "+d_str(BB("up",i));
               if(Macd(i,0)>(Macd(i,1))){comm=comm+"\nMacd is positive  "+d_str(Macd(i,0))+" > "+d_str(Macd(i,1))+" ";   
                 if(Macd(i,1)>=Digit){comm=comm+"\nMacd is positive (At least 0.00001)";  
               

For now I have to have two EA files, one for the 4 digit and one for the 2 digit pairs.

Thanks

Antony

 
No, just have the EA automatically adjust TP, SL, AND slippage
//++++ These are adjusted for 5 digit brokers.
double  pips2points,    // slippage  3 pips    3=points    30=points
        pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
Reason: