[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: MetaStock PREV constant bugs



PureBytes Links

Trading Reference Links

I think you are not quite correct in your definition of PREV and how it
works.

This is how it works.

PREV represents the value for the previous time period ONLY FOR THE
STATEMENT IN WHICH IT EXISTS.

V1 := Mov(c,30,s) + PREV;
if( V1 > 30, PREV, 10);

In the first line, PREV represents the value for this line in the
formula only.  It has no reference to any data manipulated by the if()
function in the second line.  The reference to PREV in the second line
DOES NOT REPRESENT THE PREVIOUS PERIOD'S VALUE FOR THE FIRST LINE.  It
represents the PREVIOUS value only for the if() function itself.

PREV does not reference the previous period's value for an entire
multi-statement formula.  As stated, it only represents the previous
value for the statement in which it exists.

I hope this helps.

Equis Support
http://www.equis.com/
http://www.equis.com/customer/support/
Please include previous email answers and questions in your response. 

Equis and MetaStock and MetaStock Professional are registered trademarks
of Equis International.  Achelis Binary Wave, The DownLoader, Expert
Advisor, OptionScope, Quotecenter, and Smart Charts are trademarks of
Equis International.



-----Original Message-----
From: Randall_Gary@xxxxxxxx [mailto:Randall_Gary@xxxxxxxx]
Sent: Monday, November 09, 1998 11:03 AM
To: MetaStock Group
Subject: MetaStock PREV constant bugs


While trying to develop a simple trading system in MetaStock I ran into
a 
stone wall trying to use the PREV constant.  I've reduced my findings
about 
the PREV constant to the following simple indicators to demonstrate the 
problems.

If you will copy the following code into a new indicator and run it
against 
any set of data with more than 40 bars you will see the results.  Remove

the braces {} around the code you want to test, and isolate code with 
braces you don't want to test.  

If anyone can see where I've gone wrong or suggest workarounds for these

problems I'd really appreciate it.

I suspect that MetaStock is referencing a pointer instead of a value,
but 
the results don't seem consistent.

Gary Randall -- Brunswick, Maine





{ Demonstration of PREV bugs }

{----------------------------------------------}
{ 
  This works. 
  Conclusion: Can use PREV in direct assignment.
  Note that first result doesn't plot even 
  though it must be assigned correctly. 
}

{If(Cum(1) = 10, 1, PREV + 1);}

{----------------------------------------------}
{ 
  This works. 
  Conclusion: Can use PREV in direct assignment
  even if it was set from a variable.
  Note that first result plots correctly. 
}
{
Series := If(Cum(1) = 10, 1, PREV + 1);
Series;
}


{----------------------------------------------}
{ 
  This works.
  Conclusion: Can test PREV directly.
}

{If(PREV = 10, 1, PREV + 1);}


{----------------------------------------------}
{ 
  This works.
  Conclusion: Can test PREV directly even if it
  was set from a variable.
}
{
Series := If(PREV = 10, 1, PREV + 1);
Series;
}
 


{----------------------------------------------}
{ 
  This doesn't work.  Result is always one,
  therefore, Series variable is always zero.
  Conclusion: Can't assign PREV to variable.
}
{
Series := PREV;
If(Cum(1) = 10, 1, Series + 1);
}

{----------------------------------------------}
{ 
  This doesn't work.  Result never resets to
  one, therefore, Series is never 10.
  Conclusion: Can't assign PREV to variable.
}
{
Series := PREV;
If(Series = 10, 1, PREV + 1);
}


{----------------------------------------------}
{ 
  This really gets interesting.

  Trade entry test works OK by setting day 10
  value to 1.  Trade exit test works OK by 
  setting day 34 to zero.  It should then assign
  zero for the rest of the chart.  However, it     
  starts incrementing from 25 instead.

  Conclusion: PREV is not being reset to zero on
  exit test, even though the indicator plots a
  zero.
}

{ Imagine this is trade entry test to enter }
{ trade on day 10                           }
Series := 
If(Cum(1) = 10, 1, If(PREV > 0, PREV + 1, 0));

{ Imagine this is trade exit test to exit   }
{ trade on 25th day in trade (day 34)       }
Series := If(Series = 25, 0, Series);

Series;

{----------------------------------------------}