Hello...not being an expert coder, I would like to modify this code
https://usethinkscript.com/threads/basic-scoring-system.4954/
to create a strategy. Any help would be appreciated.
Here is my logic:
MACD Histogram - Daily Timeframe - End of Day Entry and Exit
MACD Line: (12-day EMA - 26-day EMA)
Signal Line: 9-day EMA of MACD Line
MACD Histogram: MACD Line - Signal Line
Condition 1: SPX Closing price is > SMA5
Condition 2: SPX Closing price is > SMA10
Condition 3: MACD Histogram is > 0
If Condition 1 AND 2 AND 3 then Buy to Open
Condition 4: SPX Closing price is < SMA5
Condition 5: SPX Closing price is < SMA10
Condition 6: MACD Histogram is < 0
If Condition 4 AND 5 AND 6 then Sell to Close
Thank you.
the code is as follows:
A screenshot of the indicator follows:
https://usethinkscript.com/threads/basic-scoring-system.4954/
to create a strategy. Any help would be appreciated.
Here is my logic:
MACD Histogram - Daily Timeframe - End of Day Entry and Exit
MACD Line: (12-day EMA - 26-day EMA)
Signal Line: 9-day EMA of MACD Line
MACD Histogram: MACD Line - Signal Line
Condition 1: SPX Closing price is > SMA5
Condition 2: SPX Closing price is > SMA10
Condition 3: MACD Histogram is > 0
If Condition 1 AND 2 AND 3 then Buy to Open
Condition 4: SPX Closing price is < SMA5
Condition 5: SPX Closing price is < SMA10
Condition 6: MACD Histogram is < 0
If Condition 4 AND 5 AND 6 then Sell to Close
Thank you.
the code is as follows:
Code:
# https://usethinkscript.com/threads/addorder-thinkscript-backtest-buy-sell-#in-thinkorswim.741/
# https://usethinkscript.com/threads/basic-scoring-system.4954/
# Multiple Variables Scoring System - MS 10/30/23
declare lower;
# SMA5PriceVariables
input price5 = close;
input length5 = 5;
input displace5 = 0;
# SMA10PriceVariables
input price10 = close;
input length10 = 10;
input displace10 = 0;
# MACD HistogramVariables
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input DiffLength = 9;
def SMAPrice5 = Average(price5[-displace5], length5);
def SMAPrice10 = Average(price10[-displace10], length10);
def Diff = MACD(fastLength, slowLength, MACDLength, averageType.exponential).Diff;
# Variables Scoring
def ScoreSMAPrice5 = if close > SMAPrice5 then 1 else 0;
def ScoreSMAPrice10 = if close > SMAPrice10 then 1 else 0;
def ScoreDiff = if Diff > 0 then 1 else 0;
plot FinalScore = (ScoreSMAPrice5+ScoreSMAPrice10+ScoreDiff);
# End Script
A screenshot of the indicator follows:
Last edited: