Options Score / Algo Trading

Drak

New member
Good day to all.
I created a lower chart to ToS charts that scores the option based on a series of checks. These checks where 'made' by u/dj_options from reddit r/algotrading, original post can be found here: The chart plots the score, and displays the all of the checks values in labels, color coded for pass/fail

Here are all the checks for B-Score. If they are True, the counter gets increased by 1.

RSI <=40

Volume >=100

Filled price <= Lower Bollinger band

SMA ( 5 days) <= VWAP

Spread >=0.05 (This might change in future)

Filled price = Current Bid

IV<=40

Today gain <= 0

Code:
declare lower;

input p = FundamentalType.CLOSE;
input length = 20;
input averageType = AverageType.SIMPLE;

def _rsi = if IsNaN(RSI()) then 0 else RSI();
def step1 = If(_rsi <= 40, 1, 0);
def _vol = if IsNaN(volume()) then 0 else volume();
def step2 = If(_vol >= 100, 1, 0);

def filled = if IsNaN(close(priceType = PriceType.LAST)) then 0 else close(priceType = PriceType.LAST);
def lowerband = if IsNaN(MovingAverage(averageType, Fundamental(fundamentalType = p), length) - StDev(close, 20) * 2) then 0 else MovingAverage(averageType, Fundamental(fundamentalType = p), length) - StDev(close, 20) * 2;

def step3 = If(filled <= lowerband, 1, 0);

def sma5 = if IsNaN(MovingAverage(averageType,Fundamental(fundamentalType = p), 5)) then 0 else MovingAverage(averageType, Fundamental(fundamentalType = p), 5);
def vw = vwap();
def step4 = If(sma5 <= vw, 1, 0);


def bid = if IsNaN(close(priceType = PriceType.BID)) then 0 else close(priceType = PriceType.BID);
def ask = if IsNaN(close(priceType = PriceType.ASK)) then 0 else close(priceType = PriceType.ASK);

def spread = ask - bid;
def step5 = If(spread >= 0.05, 1, 0);

def step6 = If(filled equals bid, 1, 0);
def iv = if IsNaN(imp_volatility(getUnderlyingSymbol(), priceType = PriceType.LAST) * 100) then 0 else imp_volatility(getUnderlyingSymbol(),priceType = PriceType.LAST) * 100;

def step7 = if(iv <= 40, 1, 0);


def dailyOpen = if IsNaN(open(period = AggregationPeriod.DAY)) then (if isNaN(open()) then 0 else open()) else open(period = AggregationPeriod.DAY);

def todaysGain = filled - dailyOpen;
def step8 = If(todaysGain <= 0, 1, 0);

def put = IsPut();
def putcheck = if put then -8 else 0;
def score = step1 + step2 + step3 + step4 + step5 + step6 + step7 + step8 + putcheck;
plot plotscore = score;

AddLabel(yes, if put then "PUT" else "CALL", if put then Color.ORANGE else Color.GREEN);
AddLabel(yes, "Score:" + score, if score >= 6 then if put then Color.RED else Color.GREEN else Color.RED);
AddLabel(yes, "RSI:" + _rsi, if _rsi <= 40 then Color.GREEN else Color.RED);
AddLabel(yes, "Vol:" + _vol, if _vol >= 100 then Color.GREEN else Color.RED);
AddLabel(yes, "Bolngr:" + filled + "<=" + lowerband, if filled <= lowerband then Color.GREEN else Color.RED);
AddLabel(yes, "SMAVWAP:" + sma5 + "<=" + vw, if sma5 <= vw then Color.GREEN else Color.RED);
AddLabel(yes, "Spread:" + bid + "|" + ask, if spread >= 0.05 then Color.GREEN else Color.RED);
AddLabel(yes, "Filled:" + filled + "=" + bid, if filled equals bid then Color.GREEN else Color.RED);
AddLabel(yes, "IV:" + iv, if iv <= 40 then Color.GREEN else Color.RED);
AddLabel(yes, "Gain:" + todaysGain, if todaysGain <= 0 then Color.GREEN else Color.RED);



Would very very very much appreciate some help. Can someone tell my why this Code is not working and could improve it. Thanks
 
Last edited:
Good day to all.
I created a lower chart to ToS charts that scores the option based on a series of checks. These checks where 'made' by u/dj_options from reddit r/algotrading, original post can be found here: The chart plots the score, and displays the all of the checks values in labels, color coded for pass/fail

Here are all the checks for B-Score. If they are True, the counter gets increased by 1.

RSI <=40

Volume >=100

Filled price <= Lower Bollinger band

SMA ( 5 days) <= VWAP

Spread >=0.05 (This might change in future)

Filled price = Current Bid

IV<=40

Today gain <= 0

Code:
declare lower;

input p = FundamentalType.CLOSE;
input length = 20;
input averageType = AverageType.SIMPLE;

def _rsi = if IsNaN(RSI()) then 0 else RSI();
def step1 = If(_rsi <= 40, 1, 0);
def _vol = if IsNaN(volume()) then 0 else volume();
def step2 = If(_vol >= 100, 1, 0);

def filled = if IsNaN(close(priceType = PriceType.LAST)) then 0 else close(priceType = PriceType.LAST);
def lowerband = if IsNaN(MovingAverage(averageType, Fundamental(fundamentalType = p), length) - StDev(close, 20) * 2) then 0 else MovingAverage(averageType, Fundamental(fundamentalType = p), length) - StDev(close, 20) * 2;

def step3 = If(filled <= lowerband, 1, 0);

def sma5 = if IsNaN(MovingAverage(averageType,Fundamental(fundamentalType = p), 5)) then 0 else MovingAverage(averageType, Fundamental(fundamentalType = p), 5);
def vw = vwap();
def step4 = If(sma5 <= vw, 1, 0);


def bid = if IsNaN(close(priceType = PriceType.BID)) then 0 else close(priceType = PriceType.BID);
def ask = if IsNaN(close(priceType = PriceType.ASK)) then 0 else close(priceType = PriceType.ASK);

def spread = ask - bid;
def step5 = If(spread >= 0.05, 1, 0);

def step6 = If(filled equals bid, 1, 0);
def iv = if IsNaN(imp_volatility(getUnderlyingSymbol(), priceType = PriceType.LAST) * 100) then 0 else imp_volatility(getUnderlyingSymbol(),priceType = PriceType.LAST) * 100;

def step7 = if(iv <= 40, 1, 0);


def dailyOpen = if IsNaN(open(period = AggregationPeriod.DAY)) then (if isNaN(open()) then 0 else open()) else open(period = AggregationPeriod.DAY);

def todaysGain = filled - dailyOpen;
def step8 = If(todaysGain <= 0, 1, 0);

def put = IsPut();
def putcheck = if put then -8 else 0;
def score = step1 + step2 + step3 + step4 + step5 + step6 + step7 + step8 + putcheck;
plot plotscore = score;

AddLabel(yes, if put then "PUT" else "CALL", if put then Color.ORANGE else Color.GREEN);
AddLabel(yes, "Score:" + score, if score >= 6 then if put then Color.RED else Color.GREEN else Color.RED);
AddLabel(yes, "RSI:" + _rsi, if _rsi <= 40 then Color.GREEN else Color.RED);
AddLabel(yes, "Vol:" + _vol, if _vol >= 100 then Color.GREEN else Color.RED);
AddLabel(yes, "Bolngr:" + filled + "<=" + lowerband, if filled <= lowerband then Color.GREEN else Color.RED);
AddLabel(yes, "SMAVWAP:" + sma5 + "<=" + vw, if sma5 <= vw then Color.GREEN else Color.RED);
AddLabel(yes, "Spread:" + bid + "|" + ask, if spread >= 0.05 then Color.GREEN else Color.RED);
AddLabel(yes, "Filled:" + filled + "=" + bid, if filled equals bid then Color.GREEN else Color.RED);
AddLabel(yes, "IV:" + iv, if iv <= 40 then Color.GREEN else Color.RED);
AddLabel(yes, "Gain:" + todaysGain, if todaysGain <= 0 then Color.GREEN else Color.RED);



Would very very very much appreciate some help. Can someone tell my why this Code is not working and could improve it. Thanks
What is it not doing for you?
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Good day to all.
I created a lower chart to ToS charts that scores the option based on a series of checks. These checks where 'made' by u/dj_options from reddit r/algotrading, original post can be found here: The chart plots the score, and displays the all of the checks values in labels, color coded for pass/fail

Here are all the checks for B-Score. If they are True, the counter gets increased by 1.

RSI <=40

Volume >=100

Filled price <= Lower Bollinger band

SMA ( 5 days) <= VWAP

Spread >=0.05 (This might change in future)

Filled price = Current Bid

IV<=40

Today gain <= 0

Code:
declare lower;

input p = FundamentalType.CLOSE;
input length = 20;
input averageType = AverageType.SIMPLE;

def _rsi = if IsNaN(RSI()) then 0 else RSI();
def step1 = If(_rsi <= 40, 1, 0);
def _vol = if IsNaN(volume()) then 0 else volume();
def step2 = If(_vol >= 100, 1, 0);

def filled = if IsNaN(close(priceType = PriceType.LAST)) then 0 else close(priceType = PriceType.LAST);
def lowerband = if IsNaN(MovingAverage(averageType, Fundamental(fundamentalType = p), length) - StDev(close, 20) * 2) then 0 else MovingAverage(averageType, Fundamental(fundamentalType = p), length) - StDev(close, 20) * 2;

def step3 = If(filled <= lowerband, 1, 0);

def sma5 = if IsNaN(MovingAverage(averageType,Fundamental(fundamentalType = p), 5)) then 0 else MovingAverage(averageType, Fundamental(fundamentalType = p), 5);
def vw = vwap();
def step4 = If(sma5 <= vw, 1, 0);


def bid = if IsNaN(close(priceType = PriceType.BID)) then 0 else close(priceType = PriceType.BID);
def ask = if IsNaN(close(priceType = PriceType.ASK)) then 0 else close(priceType = PriceType.ASK);

def spread = ask - bid;
def step5 = If(spread >= 0.05, 1, 0);

def step6 = If(filled equals bid, 1, 0);
def iv = if IsNaN(imp_volatility(getUnderlyingSymbol(), priceType = PriceType.LAST) * 100) then 0 else imp_volatility(getUnderlyingSymbol(),priceType = PriceType.LAST) * 100;

def step7 = if(iv <= 40, 1, 0);


def dailyOpen = if IsNaN(open(period = AggregationPeriod.DAY)) then (if isNaN(open()) then 0 else open()) else open(period = AggregationPeriod.DAY);

def todaysGain = filled - dailyOpen;
def step8 = If(todaysGain <= 0, 1, 0);

def put = IsPut();
def putcheck = if put then -8 else 0;
def score = step1 + step2 + step3 + step4 + step5 + step6 + step7 + step8 + putcheck;
plot plotscore = score;

AddLabel(yes, if put then "PUT" else "CALL", if put then Color.ORANGE else Color.GREEN);
AddLabel(yes, "Score:" + score, if score >= 6 then if put then Color.RED else Color.GREEN else Color.RED);
AddLabel(yes, "RSI:" + _rsi, if _rsi <= 40 then Color.GREEN else Color.RED);
AddLabel(yes, "Vol:" + _vol, if _vol >= 100 then Color.GREEN else Color.RED);
AddLabel(yes, "Bolngr:" + filled + "<=" + lowerband, if filled <= lowerband then Color.GREEN else Color.RED);
AddLabel(yes, "SMAVWAP:" + sma5 + "<=" + vw, if sma5 <= vw then Color.GREEN else Color.RED);
AddLabel(yes, "Spread:" + bid + "|" + ask, if spread >= 0.05 then Color.GREEN else Color.RED);
AddLabel(yes, "Filled:" + filled + "=" + bid, if filled equals bid then Color.GREEN else Color.RED);
AddLabel(yes, "IV:" + iv, if iv <= 40 then Color.GREEN else Color.RED);
AddLabel(yes, "Gain:" + todaysGain, if todaysGain <= 0 then Color.GREEN else Color.RED);



Would very very very much appreciate some help. Can someone tell my why this Code is not working and could improve it. Thanks
You can add the following code before the the first addlabel:
addlabel(1," " + step1 + " " + step2 + " " + step3 +" " +step4 + " " + step5 + " " + step6 + " " + step7 + " " + step8 +" " + putcheck);
Then you can tweak each individual step to get the results you want.
Hope this helps.
 
Last edited:
Awesome ideas and work. The labels work now. How do we interpret the labels? For example, for SPY it shows gain in RED 4.68

Since this is an implementation of the algo linked to this thread. The Original Poster (dj_options) mentioned that he takes a trade whenever the gain is less than 0 (green label) or as close to 0 and the Score is >= 6 or 7 (higher number is the most probable trade).
 
You can add the following code before the the first addlabel:
addlabel(1," " + step1 + " " + step2 + " " + step3 +" " +step4 + " " + step5 + " " + step6 + " " + step7 + " " + step8 +" " + putcheck);
Then you can tweak each individual step to get the results you want.
Hope this helps.
I cleaned the labels : (delete all addlabel at the end and replace with this):
addlabel(1," " + step1 + " " + step2 + " " + step3 +" " +step4 + " " + step5 + " " + step6 + " " + step7 + " " + step8 +" " + putcheck, color.yellow);
AddLabel(yes, if put then "PUT" else "CALL", if put then Color.ORANGE else Color.GREEN);
AddLabel(yes, "Score:" + round(score,2), if score >= 6 then if put then Color.RED else Color.GREEN else Color.RED);
AddLabel(yes, "RSI:" + round(_rsi,2), if _rsi <= 40 then Color.GREEN else Color.RED);
AddLabel(yes, "Bar Vol:" + _vol, if _vol >= 100 then Color.GREEN else Color.RED);
AddLabel(yes, "LBB:" + round(filled,2) + "<=" + round(lowerband,2), if filled <= lowerband then Color.GREEN else Color.RED);
AddLabel(yes, "SMAVWAP:" + round(sma5,2) + "<=" + round(vw,2), if sma5 <= vw then Color.GREEN else Color.RED);
AddLabel(yes, "Spread:" + bid + "|" + round(ask,2), if spread >= 0.05 then Color.GREEN else Color.RED);
AddLabel(yes, "Filled:" + round(filled,2)+ "=" + round(bid,2), if filled equals bid then Color.GREEN else Color.RED);
AddLabel(yes, "IV:" + round(iv,2), if iv <= 40 then Color.GREEN else Color.RED);
AddLabel(yes, "Gain:" + round(todaysGain,2), if todaysGain <= 0 then Color.GREEN else Color.RED);

I do weekly options and don't see how this helps you make any money.
Good luck!
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
287 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top