Rank: Advanced Member
  Groups: Registered, Registered Users Joined: 1/20/2012(UTC) Posts: 152
  Was thanked: 1 time(s) in 1 post(s)
  
 
     | 
    
        
            
	      
                xumitcap wrote:Please help me with the codes: 
 
  
For the 20 days window period, I want to take average of last 10 days (including today's close) subtracted by average of previous 10 days. 
  
Ave(Day11 to Day20) - Ave (Day1 to Day10)   
Hi xumit, [:)] 
You can do it in several ways: 
BEGINNER, it helps you focus step by step 
Code:a:=(Mov(C,10,S)+
Ref(Mov(C,10,S),-1)+
Ref(Mov(C,10,S),-2)+
Ref(Mov(C,10,S),-3)+
Ref(Mov(C,10,S),-4)+
Ref(Mov(C,10,S),-5)+
Ref(Mov(C,10,S),-6)+
Ref(Mov(C,10,S),-7)+
Ref(Mov(C,10,S),-8)+
Ref(Mov(C,10,S),-9))/10;
b:=(Ref(Mov(C,10,S),-11)+
Ref(Mov(C,10,S),-12)+
Ref(Mov(C,10,S),-13)+
Ref(Mov(C,10,S),-14)+
Ref(Mov(C,10,S),-15)+
Ref(Mov(C,10,S),-16)+
Ref(Mov(C,10,S),-17)+
Ref(Mov(C,10,S),-18)+
Ref(Mov(C,10,S),-19)+
Ref(Mov(C,10,S),-20)
)/10;
a-b 
 
INTERMEDIATE, here you want to play with formulas you learnt (but which you didn't [:O]) in MS User Manual and Formula Primer 
Code:a:=Sum(Mov(C,10,S),10)/10;
b:=Ref(Sum(Mov(C,10,S),10),-11)/10;
a-b 
 
ADVANCED, the simplest formula but the ugliest line (Attention: some people post bad codes in these threads [6]) The values are different from the other two Indicators above, and it gives earlier price/SMA crossover signals. 
Code:M:=Mov(C,10,S);
M-Ref(M,-11) 
 
(Observe -11, instead of -10). 
There is no point in subtracting the front SMA batch from the back SMA batch. 
Ave(Day11 to Day20) - Ave (Day1 to Day10). 
  
It is much better the other way round: 
Ave (Day1 to Day10) - Ave(Day11 to Day20) 
  
What are you after with this Indicator? [:D]  
            
  
         
     |