Welcome to the Traders Laboratory Forums.
Coding Forum Collaborate, receive help, or discuss coding related issues.

Reply
Old 08-30-2009, 09:46 PM   #1

Join Date: Dec 2008
Location: athens
Posts: 54
Ignore this user

Thanks: 0
Thanked 4 Times in 3 Posts

Iff Function Different Averages

can anybody explain why this two averages have different values?
regards
this is the code:


Inputs: Price (c),Period (30);
vars : val(0);

if BarType >= 2 then val= volume else val = ticks;

value1 = iff (Momentum (Price, 1) > 0,
momentum(price,1)*val, 0.0001);
value2 = average(value1,period);
value3 = Average (iff (Momentum (Price, 1) > 0,
momentum(price,1)*val, 0.0001), Period);
plot1(value2);
plot2(value3);
Attached Thumbnails
Iff Function Different Averages-different-averages.png  
andypap is offline  
Reply With Quote
Old 08-30-2009, 10:16 PM   #2

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Iff Function Different Averages

value3 = Average (iff (Momentum (Price, 1) > 0, momentum(price,1) * val, 0.0001), Period);


because the current value of val is used for every iteration of the "average" calculation.
__________________



Only an idiot would reply to a stupid post
Tams is offline  
Reply With Quote
Old 08-31-2009, 10:45 AM   #3

Join Date: Dec 2008
Location: athens
Posts: 54
Ignore this user

Thanks: 0
Thanked 4 Times in 3 Posts

Re: Iff Function Different Averages

thanks in advance for the reply..
you mean this average summation is the following

momentum(price,1)*val + momentum(price,1)[1] *val to period instead
momentum(price,1)*val + momentum(price,1)[1] *val[1] to period ..

maybe i havn't understood though.

regards
andypap is offline  
Reply With Quote
Old 08-31-2009, 10:48 AM   #4

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Iff Function Different Averages

Quote:
Originally Posted by andypap »
...
maybe i havn't understood though.

regards

I don't understand what you are talking about either.

just use plot1 and you won't have the problem.
__________________



Only an idiot would reply to a stupid post
Tams is offline  
Reply With Quote
Old 08-31-2009, 11:37 AM   #5

Join Date: Dec 2008
Location: athens
Posts: 54
Ignore this user

Thanks: 0
Thanked 4 Times in 3 Posts

Re: Iff Function Different Averages

Inputs: Price (c),Period (30);
vars : val(0),return(0);

if BarType >= 2 then val= volume else val = ticks;


if 100 - 100 /
(1 + Average (iff (Momentum (Price, 1) > 0,
Momentum (Price, 1) * val, 0), Period) /
Average (iff (Momentum (Price, 1) < 0,
-1 * Momentum (Price, 1) * val, 0), Period)) <> 0
then Return = 100 - 100 /
(1 + Average (iff (Momentum (Price, 1) > 0,
Momentum (Price, 1) * val, 0), Period) /
Average (iff (Momentum (Price, 1) < 0,
-1 * Momentum (Price, 1) * val, 0), Period)) ;


if 100 - 100 /
(1 + Average (iff (Momentum (Price, 1) > 0,
Momentum (Price, 1) * val, 0), Period) /
Average (iff (Momentum (Price, 1) < 0,
-1 * Momentum (Price, 1) * val, 0), Period)) = 0

then Return = .0001;

plot1(return);

the code above is the original indicator..gives floating point errors when period<30..
i try to simplify the code by the following lines


vars :prval(0),plusval(0);

prval = c-c[1];
if prval > 0 then
plusval = prval*val else plusval = 0;



value1 = iff (Momentum (Price, 1) > 0,
momentum(price,1)*val, 0);

value2 = average(value1,period);

value3 = Average (iff (Momentum (Price, 1) > 0,
momentum(price,1)*val, 0), Period);

plusval and value1 are exactly the same so do their averages value2 and the eqivelent average of plusval..
value3 plots slightly different values..
but these is the segment of the original code..
so i was wondering why the average
of the iff value(value2) is different than value3..
i was thinking maybe there is something between these two statments worth exploring

thanks for your patience

regards
andypap is offline  
Reply With Quote
Old 08-31-2009, 11:40 AM   #6

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Iff Function Different Averages

you should wrap codes inside code tags.

see the # symbol in the reply box.


Code:
...
put codes here
...
__________________



Only an idiot would reply to a stupid post

Last edited by Tams; 08-31-2009 at 12:18 PM.
Tams is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Zero Lag Moving Averages phase21 Trading Indicators 2 08-14-2009 02:54 AM
Moving Averages Again... TacTrader Technical Analysis 5 01-12-2009 02:16 PM
MACD with Hull Moving Averages Soultrader Trading Indicators 2 09-06-2007 05:52 PM
Moving Averages: Which one should I use? Blaze Technical Analysis 7 08-27-2006 08:04 AM

All times are GMT -4. The time now is 01:51 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.