Crossover ques

 
Screen Shot


2013.04.12 11:39:04 MTFMACross_v1 EURUSD,M5: i =477 T= 2013.04.11 05:50 cf 1.30541099 cs 1.30539989 pf 1.30539149 ps 1.30539461
2013.04.12 11:39:04 MTFMACross_v1 EURUSD,M5: i =485 T= 2013.04.11 05:10 cf 1.30536063 cs 1.30535464 pf 1.30534094 ps 1.30534987
2013.04.12 11:39:04 MTFMACross_v1 EURUSD,M5: i =489 T= 2013.04.11 04:50 cf 1.30543442 cs 1.30538737 pf 1.30533163 ps 1.30536078

MA 5 and 20.
As you can see from the screen shot the only cross(at left) is at t=04:50. The middle arrow is at t=05:10. The right arrow is at
  
t=05:50.  cf/pf = current/prev fast ma.  CS/PS = current/prev slow ma. The yellow line is 50ema... not important.

Given the code below, I need some help as to why the last two up arrows printed. 


int start()
  {
  double FastMAValueTF1=0;
double SlowMAValueTF1=0;
double PrevFastMAValueTF1=0;
double PrevSlowMAValueTF1=0;
double StochValueTF1=0;
double PrevStochValueTF1=0;

double FastMAValueTF2=0;
double SlowMAValueTF2=0;
double PrevFastMAValueTF2=0;
double PrevSlowMAValueTF2=0;
double StochValueTF2=0;
double PrevStochValueTF2=0;

  
   int counted_bars=IndicatorCounted();
    
    if(Bars<=100) {return(0);}  
   
   int i=Bars-counted_bars-1;
  static datetime tmp;
  //if (tmp!= Time[0]) {
  //  tmp =  Time[0];
  
 if (tmp!= Time[i])
 {
  tmp =  Time[i];
  while(i>=0) 
   
   {
         
        int iTF1 = iBarShift(Symbol(),TimeFrame1,Time[i]),
            iTF2 = iBarShift(Symbol(),TimeFrame2,Time[i]);
       double LowAddition= 30*Point;
       double HiAddition = iHigh(Symbol(),TimeFrame1,iTF1)+ (30*Point);

       //double LowAddition= 30*Point;
       //double HiAddition = iHigh(Symbol(),TimeFrame1,i)+ (30*Point);
         //========================================================================
         //time frame eval
         //TimeFrameRef=iTime(Symbol(),TimeFrame1,i);
         //BarShift=iBarShift(Symbol(),TimeFrame2,TimeFrameRef);
       
       
       //==========================================================================
       //MA points
       FastMAValueTF1=iMA(Symbol(),TimeFrame1,FastMA,0,MODE_EMA,PRICE_CLOSE,i);
       SlowMAValueTF1=iMA(Symbol(),TimeFrame1,SlowMA,0,MODE_EMA,PRICE_CLOSE,i);
       
       PrevFastMAValueTF1=iMA(Symbol(),TimeFrame1,FastMA,0,MODE_EMA,PRICE_CLOSE,i+1);
       PrevSlowMAValueTF1=iMA(Symbol(),TimeFrame1,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+1);
       
       //Stoch Points one tf
        StochValueTF1=iStochastic(Symbol(),TimeFrame1,5,3,2,MODE_SMA,0,0,i);
        PrevStochValueTF1=iStochastic(Symbol(),TimeFrame1,5,3,2,MODE_SMA,0,0,i+1);
        //=========================================================================
        
        //stoc points one tf
        StochValueTF2=iStochastic(Symbol(),TimeFrame2,5,3,2,MODE_SMA,0,0,iTF2);
        PrevStochValueTF2=iStochastic(Symbol(),TimeFrame2,5,3,2,MODE_SMA,0,0,iTF2+1);
        //===========================================================================
        
      
       
       if ((FastMAValueTF1 > SlowMAValueTF1) && (PrevFastMAValueTF1 < PrevSlowMAValueTF1))
       {
      
           
            //moving up
            UpArrow[i]=iLow(Symbol(),TimeFrame1,i)-LowAddition ;
            if ((i>400)&& (i <500))
            {
            Print ("i =" + i + " T= " + TimeToStr(Time[i]) + " cf " + FastMAValueTF1 + " cs " + 
            SlowMAValueTF1 + " pf " + PrevFastMAValueTF1 + " ps " + PrevSlowMAValueTF1);
            }
          
       }
       else if ((FastMAValueTF1 < SlowMAValueTF1) && (PrevFastMAValueTF1 > PrevSlowMAValueTF1))
       {
         
        
         
            
            DownArrow[i]=iHigh(Symbol(),TimeFrame1,i)+LowAddition;
           
            
            
         
       }
       
      
       i--; 
   }
//----
   
//----
   return(0);
   }
 } 
 
  1. Code fails if Period() is not TimeFrame1
            int iTF1 = iBarShift(Symbol(),TimeFrame1,Time[i]),
                iTF2 = iBarShift(Symbol(),TimeFrame2,Time[i]);
             FastMAValueTF1=iMA(Symbol(),TimeFrame1,FastMA,0,MODE_EMA,PRICE_CLOSE,i);
           SlowMAValueTF1=iMA(Symbol(),TimeFrame1,SlowMA,0,MODE_EMA,PRICE_CLOSE,i);
           
           PrevFastMAValueTF1=iMA(Symbol(),TimeFrame1,FastMA,0,MODE_EMA,PRICE_CLOSE,i+1);
           PrevSlowMAValueTF1=iMA(Symbol(),TimeFrame1,SlowMA,0,MODE_EMA,PRICE_CLOSE,i+1);
           
           //Stoch Points one tf
            StochValueTF1=iStochastic(Symbol(),TimeFrame1,5,3,2,MODE_SMA,0,0,i);
            PrevStochValueTF1=iStochastic(Symbol(),TimeFrame1,5,3,2,MODE_SMA,0,0,i+1);
            //=========================================================================
    
  2. Your lines are irrelevant. They are moving averages of the chart's timeframe, not TimeFrame1/2.
 
WHRoeder:
  1. Code fails if Period() is not TimeFrame1
  2. Your lines are irrelevant. They are moving averages of the chart's timeframe, not TimeFrame1/2.

 

1) Thank you --- I realize that. As I get more proficient I will try to solve that issue. For the time being Period(0) and TimeFrame1 will be the same.

2) Since the lines are irrelevant, is it your opinion that the code is working properly?  Each of the arrows in my screen shot are correct?? I notice that the journal ma points do not coincide with the lines. Why are the two calculations so different?

 

You have been very helpful to me and I really appreciate it.

Thanks again. 

Reason: