Hello,
I'm having trouble solving a problem with an indicator I've created.
Essentially, I'm trying to get this indicator to return "true" when:
1A). price is up 25% from the 21 bar low or
1B). the 21 bar high is greater than or equal to 25% above the 21 bar low.
AND
2). Close cannot be more than 9% below the 50 MA.
Here is the code:
The purpose of this indicator is to be able to scan for stocks up 25% from a low, but not to lose the stock on the scan when it consolidates, at least until it falls more than 9% below the 50 MA. I was having issues with having these stocks show up on my scans, and then missing the buy spots that evolve from consolidation.
The unanticipated problem that I'm having is that sometimes the indicator will return a true value by anchoring to a "lo" that occurs AFTER a "hi". I'm trying to find a way to get the indicator to only use a "lo" that occurs BEFORE a "hi".
Is there any way prevent this from occurring? I tried to use "GetMaxValueOffset" to return bar numbers with the hope of creating a condition that required the bar number of the "Hi" to be greater than the bar number of the "Lo", but I didn't get anywhere with that idea. Any help would be greatly appreciated.
I'm having trouble solving a problem with an indicator I've created.
Essentially, I'm trying to get this indicator to return "true" when:
1A). price is up 25% from the 21 bar low or
1B). the 21 bar high is greater than or equal to 25% above the 21 bar low.
AND
2). Close cannot be more than 9% below the 50 MA.
Here is the code:
Code:
declare lower;
input range = 21;
input percentabove = 1.25;
input MAlength = 50;
def lo = lowest(low,range);
def hi = highest(high, range);
def MA = simpleMovingAvg(close, MAlength);
def MAcond = close >= 0.91*MA;
plot x = MAcond is true and (close >= percentabove*lo or hi >= percentabove*lo) ;
The purpose of this indicator is to be able to scan for stocks up 25% from a low, but not to lose the stock on the scan when it consolidates, at least until it falls more than 9% below the 50 MA. I was having issues with having these stocks show up on my scans, and then missing the buy spots that evolve from consolidation.
The unanticipated problem that I'm having is that sometimes the indicator will return a true value by anchoring to a "lo" that occurs AFTER a "hi". I'm trying to find a way to get the indicator to only use a "lo" that occurs BEFORE a "hi".
Is there any way prevent this from occurring? I tried to use "GetMaxValueOffset" to return bar numbers with the hope of creating a condition that required the bar number of the "Hi" to be greater than the bar number of the "Lo", but I didn't get anywhere with that idea. Any help would be greatly appreciated.
Last edited by a moderator: