MQL4 - function run in back test but not in Demo account

 

hello every one. 

this is my very First EA am trying to develop. in back testing the flow is exactly like am expecting it to be. 

i tried to put it on a demo account to see if any thing will arise. 

and it actually did not work  as it should be. 

in below snip code  in side the function 

void ShortTrade()

there is two blocks of code. 

1- Looking for first Peak

2- ZERO LEVEL RULE MET


what i do is the following 

i get the value from MACD main line. and compare it to two values (entered  manually)   

first line of code will compare the MACD_Current with the MACD_Target_P1 and if the condition is TRUE it will set a bool variable as true and draw a VObject line on that Bar 

it will always go in this block of code to make sure am holding the highest value 

after that it should go to the second block of code to check for the second bool "MACD_Near_Zero " and  compare it with the value am specifying if  the rule is met it will again draw a VObject 


when i ran the EA in a Demo account, it did not execute any other code block only the first block code even though when i put a print to check the values it should have gone to the next block of code but it did not 


am running it in a AUDUSD 15 minutes currency. 


i do hop my explanation is sufficient. thank you in advance for any advice 


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+


double MACD_Current;
double MACD_Target_P1 = 0.00045;
double MACD_Zero_Level = 0.0003;
bool MACD_P1_Found = false;
int Bar_P1_index, BarCount, ObjCount, MaxBars;
double Bar_P1, MACD_M_P1;
datetime Bar_P1_time;
bool MACD_Near_Zero = false;
string ObjFirstPeak, ObjName3, ObjP1Updated;

int init()
  {   
   P=GetP(); // To account for 5 digit brokers. Used to convert pips to decimal place
   YenPairAdjustFactor=GetYenAdjustFactor(); // Adjust for YenPair
   
   start();
   return(0);
  }
  
  
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
int start()
  {
//---
   MACD_Current = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
   
   ShortTrade();
   
   return (0);
  }
//+------------------------------------------------------------------+


void ShortTrade(){

//################################### Looking for first Peak #########################
      printf("MACD value " + MACD_Current + " MACD_P1_Found: " + MACD_P1_Found);
         if(MACD_Current >=0.00045 ){
             if( MACD_P1_Found == false){
               Print("MACD_P1_Found in P1 block first value " + MACD_P1_Found);
               MACD_M_P1 = MACD_Current;
               Bar_P1_index = iHighest(Symbol(),0,MODE_CLOSE,5,1);
               Bar_P1 = iHigh(Symbol(),0,Bar_P1_index);
               Bar_P1_time = iTime(Symbol(),0,Bar_P1_index);
               MACD_P1_Found = true;
            
               ObjFirstPeak="FirstPeak" + ObjCount;
               ObjectCreate(ObjFirstPeak ,OBJ_VLINE,0,Bar_P1_time,0);
               ObjectSet(ObjFirstPeak,OBJPROP_COLOR,Blue);
               ObjCount++;
               }else{
                     if(MACD_Current >= MACD_M_P1){
                        printf("current MACD_M_P1 Less than MACD Current BLOCK: "+ MACD_Current + " >= " + MACD_M_P1);
                        PeaksFlagReset();                  
                        MACD_M_P1 = MACD_Current;
                        Bar_P1_index = iHighest(Symbol(),0,MODE_CLOSE,5,1);
                        Bar_P1 = iHigh(Symbol(),0,Bar_P1_index);
                        Bar_P1_time = iTime(Symbol(),0,Bar_P1_index);
                        MACD_P1_Found = true; 
                        ObjectDelete(0,ObjP1Updated);
                        ObjP1Updated="FirstPeakUpdated" + ObjCount;
                        ObjectCreate(ObjP1Updated ,OBJ_VLINE,0,Bar_P1_time,0);
                        ObjectSet(ObjP1Updated,OBJPROP_COLOR,clrAquamarine);
                        ObjCount++;   
               }
            }
          }
      
//################################### END #########################


         
//####################################### ZERO LEVEL RULE MET #######################
         if(MACD_P1_Found && MACD_Near_Zero==false){           
            if(BarCount >MaxBars){
            PeaksFlagReset();
            }else{ 
               if(MACD_Current <= 0.0003){
                    printf("inside Zero block for Zero Rule met MACD_Current value: " + MACD_Current);
                    MACD_Near_Zero = true;                    
                    datetime ZeroLevelTime;
                    ZeroLevelTime = iTime(Symbol(),0,1);              
                    ObjName3="ZeroLevel" + IntegerToString(ObjCount);
                    ObjectCreate(ObjName3, OBJ_VLINE, 0, ZeroLevelTime,0);
                    ObjectSet(ObjName3, OBJPROP_COLOR, clrCoral);
                    ObjCount ++;
                    printf(" V Object for zero level has been executed ");
               }
            }
         }
         
         
//####################################### ZERO LEVEL RULE MET END #######################


  
//############################################# END SET TP & SP ##############################
      
      
     if(MACD_P1_Found==true && MACD_Near_Zero ==false){
      BarCount++;
     }
     else { if(MACD_P1_Found==true && MACD_Near_Zero ==true) PeaksFlagReset();  }

}
Reason: