• Get $30 off VIP with code SUMMER30. Ends July 27. Happy trading!

Scan for stocks that is below the lower Bollinger band

Hello,

So I'm trying to write a script for a stocks current price that is below the lower band of the Bollinger band. So far, every script I've written has never shown an error on this word and I don't know what to do to fix it.
everything is good and accepted except for the word "condition" on the very last line. any idea why its not working? I think it has something to do with the Constant--> Price Type--> (PriceType.Last or PriceType.Bid or PriceType.Ask), which is something I haven't used yet.

Also, I seem to be having trouble adding the code and the above paragraph in the original post, I have to edit my post to add either the body text or the code after I post, Any ideas why this is happening?
Code:
#Hint: stocks that are below the lowerband during the day heading into the close

input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

input currentprice = PriceType.LAST;


def sDev = stdev(data = price[-displace], length = length);

def MidLine = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;


plot condition = currentprice < lowerBand;

# The word "condition" above is the only word that shows up with the red box.f
 

BenTen

Administrative
Staff
VIP
No need to make it complicated. Use the conditional wizard.

6VV6ikw.png
 
No need to make it complicated. Use the conditional wizard.
the only issue with this is I want to choose the last price, as I want to do this scan before the market closes, like the last 30 minutes of the day.

The other thing is I see that there is a hl2, hlc3, and a ohlc4. why isn't there a ohl3 function? seems that would be most useful for during the day before the close.
 

rad14733

Well-known member
VIP
@mourningwood4521 First, TOS doesn't like you use of the variable "condition"... I replaced it with "trigger" and that fixed that issue... Now I'm working on a new error - "incompatible parameter: currentprice", expected double... And that is because you are still trying to use Last in a way it can't be used... Switching it to Close, like I stated above, the code verifies... The code below verifies and can be saved... Whether it performs as you desire is subjective as I didn't try it...

Ruby:
#Hint: stocks that are below the lowerband during the day heading into the close

input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

input currentprice = close;


def sDev = stdev(data = price[-displace], length = length);

def MidLine = MovingAverage(averageType, data = price[-displace], length = length);
def LowerBand = MidLine + num_Dev_Dn * sDev;
def UpperBand = MidLine + num_Dev_Up * sDev;


plot trigger = currentprice < lowerBand;

# The word "condition" above is the only word that shows up with the red box.f
 
@mourningwood4521 First, TOS doesn't like you use of the variable "condition"... I replaced it with "trigger" and that fixed that issue... Now I'm working on a new error - "incompatible parameter: currentprice", expected double... And that is because you are still trying to use Last in a way it can't be used... Switching it to Close, like I stated above, the code verifies... The code below verifies and can be saved... Whether it performs as you desire is subjective as I didn't try it...
when I try replacing it with trigger it gives me the same red box over the word trigger.

Im thinking hmmm....

I replaced the Price Type to "low" and it accepted that term. I just have to filter through about 30 stocks to see if they have bounced off the low or are currently trading near the low of the day

DO you think it would be possible to make the system find the (high + low + close) divided by 3? just cuz I don't see that option incorporated into the system.
 

BenTen

Administrative
Staff
VIP
@mourningwood4521 If it's not listed under the conditional wizard, most likely, ThinkorSwim won't let you run the scanner. Like the example you stated, using the "last" price in the scanner's code will not work because ToS' scan system does not support it. Feel free to test out different price types.
 

rad14733

Well-known member
VIP
@mourningwood4521 If it's not listed under the conditional wizard, most likely, ThinkorSwim won't let you run the scanner. Like the example you stated, using the "last" price in the scanner's code will not work because ToS' scan system does not support it. Feel free to test out different price types.
I posted corrected code... For scans Close serves as Last for active bars/candles... Then he failed to notice that hlc3 is in the Price Type list... I have faith that with practice he'll get up to speed on coding Thinkscript...
 
@mourningwood4521 What do you think hlc3 is...??? The code I posted should work... Did you see the code I posted above...???
yeah I saw the code you posted and thank you for that.


I thought high low close 3 is the average of the 3 values. And a hlc3 on a daily chart would be from the day before wouldn't it? because you can't have a close if the market is still open. Unless I'm misunderstanding something and if you say the close, then that would be the close of the most recent bar at the type the operation is being executed.
 
I posted corrected code... For scans Close serves as Last for active bars/candles... Then he failed to notice that hlc3 is in the Price Type list... I have faith that with practice he'll get up to speed on coding Thinkscript...
not hlc3 im sorry that was error in my typing, I was multi tasking.

I meant to type open. so it should read: DO you think it would be possible to make the system find the (high + low + open) divided by 3? just cuz I don't see that option incorporated into the system.


okay now I understand that close would be the last. " For scans Close serves as Last for active bars/candles".

Why did thinkscript not take plot Condition today but every other plot condition I've done has accepted that term?
 

rad14733

Well-known member
VIP
yeah I saw the code you posted and thank you for that.


I thought high low close 3 is the average of the 3 values. And a hlc3 on a daily chart would be from the day before wouldn't it? because you can't have a close if the market is still open. Unless I'm misunderstanding something and if you say the close, then that would be the close of the most recent bar at the type the operation is being executed.
hlc3 will always use the previous candle/bar, not the previous day - unless you set aggregation to day or use day as your timeframe...

hlc3 is in the Price Type list or can be used in Thinkscript...
 

Similar threads

Top