Price touches MA at least twice in past 4 bars


Category:
0
0

Hello! I am trying to write a code which scans for the price crossing/hitting a particular moving average atleast twice within the past 4 bars. I coded the crossing/hitting portion to where the price is within a certain percentage of the MA. However I cannot correctly code the price crossing/hitting the MA atleast twice within the past 4 bars. As of now it is coded to where two consecutive bars hit the respective MA. The code runs and the majority of tickers follow the code, however there are some which don’t which has made me question if the code is correct. Here is what I have so far.

def ma = SimpleMovingAvg(close,50);

def s = ma*0.002;

def consecutive = absvalue(close – ma) is less than or equal to s;

def x = consecutive[1] and consecutive;

plot scan = x;

Thank you!!!!

Sincearly: Someone who can’t code

Marked as spam
Posted by (Questions: 3, Answers: 0)
Asked on October 12, 2020 4:49 pm
114 views
1
Private answer

def maOne = Average(close, 50);
def touchesMaOne = high > maOne and low < maOne;
plot scan = Sum(touchesMaOne, 4) >= 2;

That code captures your pattern for two or more touches with the last four bars. You can add the code you already created for the price with x percent of the ma.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 12, 2020 6:42 pm