I have a problem with a Study where I'm trying to identify the number of bars since the last time price closed below an exponential moving average. I only get the total number of bars in the dataset as result of the study.
Code: Select all
Input:
LowPrice (Low),
EMALength (20),
Price (close);
variables:
barssince (0),
_EMA_low (0);
_EMA_low = XAverage (EMALength, Lowprice);
if price < _EMA_low then
value1 = value1 + 1
else
value1 = 0;
condition1 = value1 >= 1;
if condition1 then
barssince = 0;
barssince = barssince + 1;
Plot1(barssince, "barssinceDn");
Code: Select all
inputs:
Price( Close ),
ConsecutiveBarsUp( 3 );
variables:
barssince2 (0);
if Price > Price[1] then
Value1 = Value1 + 1
else
Value1 = 0 ;
condition1= Value1 >= ConsecutiveBarsUp ;
if condition1 then
barssince2 = 0;
barssince2 = barssince2 +1;
Plot1(barssince2, "barssince");
I would appreciate any help that would get the first of my two studies to work.