MA & CCI combo scan


Category:
0
0

Hi Pete, i am having problems getting the TOS scan to find stocks that met these conditions

1. When price close within the defined range
2. When the CCI is below 100

This is the drafted codes, but was unable to get the scan to provide the correct scan results with both conditions are met.

#declare lower;

input bars = 30;
def ma = SimpleMovingAvg(close, bars);
def s = ma * 0.01;
def scan = AbsValue(close – ma) <= s;

input CCI = -100;
def PB = CCI<100;

plot Signal = scan and PB;

May i seek your advise pls.

Separately, how do i write the code if i want to replace the CCI with stochastic RSI when the stock is oversold or below 20?

Thank you very much

Marked as spam
Posted by (Questions: 8, Answers: 15)
Asked on June 5, 2020 6:37 am
96 views
0
Private answer

Wow, I am running out of time here and have so much to say.

  1. You list condition one as the close being within a range. But nowhere in your code or in your specifications do you define exactly what that range is. The only thing your code attempts to do is to find when the close is less than or equal to the moving average times 0.01. So if the moving average is at 300 the close must be below 3. Impossible, right?
  2. You do not have any CCI code in this whatsoever. So the statement that checks if CCI is below -100 completely fails, but only because it does not compute the value of the CCI indicator anywhere in the code.

I am completely out of time here and I cobbled together a working code but I have no idea if it does what you expect because you did not provide sufficient details in your request:

input length = 30;
input cciLimit = -100;
def maOne = SimpleMovingAvg(close, length);
def maOneCondition = close <= maOne * 1.01;
def cciValue = CCI();
def cciCondition = cciValue < cciLimit;
plot scan = maOneCondition and cciCondition;

Line 4 has been updated to compute the moving average times 1.01, because that is a more reasonable value than 0.01. But again I have no way to know because you failed to describe this portion in sufficient detail. Line 5 is where the CCI value is captured from the built-in version that comes with Thinkorswim.

Otherwise, please take note of the variable names and the way things are organized. Notice how the variable names tell you exactly what each line is doing. This is a huge improvement over the readability and layout of the code you provided. Above all else, it is very important that folks learn the proper way to write code.

Ok, that's all I have. I am actually over my time limit for this request.

Marked as spam
Posted by (Questions: 37, Answers: 4079)
Answered on June 5, 2020 8:16 am