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

MetaStock PREV constant bugs



PureBytes Links

Trading Reference Links

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;

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