StockFetcher Forums · General Discussion · Normalized MACD | << >>Post Follow-up |
zoloftking 4 posts msg #158522 - Ignore zoloftking |
2/6/2022 1:21:38 AM how to you filter for MACD crosses using normalized MACD? Thanks in advance. |
SAFeTRADE 646 posts msg #158537 - Ignore SAFeTRADE |
2/8/2022 10:43:56 AM Maybe this? |
SAFeTRADE 646 posts msg #158547 - Ignore SAFeTRADE modified |
2/8/2022 7:13:37 PM Forgot the normalized part. |
Cheese 1,374 posts msg #158685 - Ignore Cheese |
2/26/2022 5:29:11 PM -------------------------------------------------------------------------- Please note that the above picture may expire in 30 days. -------------------------------------------------------------------------- Below is the best pine script for Normalized Smoothed MACD that I could find. It was written by Dreadblitz https://www.tradingview.com/script/TnOyxqKO-Normalized-Smoothed-MACD/ Unfortunately, I don't know enough about pine script to convert to sF. Perhaps, someone experienced in pine script coding might want to give it a try. -------------------------------------------------------------------------- // © Dreadblitz //@version=4 study(title="Normalized smoothed MACD", shorttitle = "NSM", overlay=false) // inpFastPeriod = input(defval=12, title="MACD fast period", minval=1, type=input.integer) inpSlowPeriod = input(defval=26, title="MACD slow period", minval=1, type=input.integer) inpMacdSignal = input(defval=9, title="Signal period", minval=1, type=input.integer) inpSmoothPeriod = input(defval=5, title="Smoothing period", minval=1, type=input.integer) inpNormPeriod = input(defval=20, title="Normalization period", minval=1, type=input.integer) price = input(close, title="Price Source",type=input.source) // emaf = 0.0 emas = 0.0 val = 0.0 nval = 0.0 sig = 0.0 // red =color.new(#FF0000, 0) green=color.new(#32CD32, 0) black=color.new(#000000, 0) // if bar_index > inpSlowPeriod alphaf = 2.0/(1.0+max(inpFastPeriod,1)) alphas = 2.0/(1.0+max(inpSlowPeriod,1)) alphasig = 2.0/(1.0+max(inpMacdSignal,1)) alphasm = 2.0/(1.0+max(inpSmoothPeriod,1)) emaf := emaf[1]+alphaf*(price-emaf[1]) emas := emas[1]+alphas*(price-emas[1]) imacd = emaf-emas mmax = highest(imacd,inpNormPeriod) mmin = lowest(imacd,inpNormPeriod) if mmin != mmax nval := 2.0*(imacd-mmin)/(mmax-mmin)-1.0 else nval := 0 val := val[1] + alphasm*(nval-val[1]) sig := sig[1] + alphasig*(val-sig[1]) // plot(val, color=val>val[1]?green:red, style=plot.style_line, linewidth=2, title="Reg smooth MACD") plot(sig, color=black, style=plot.style_cross, linewidth=1, title="Signal line") hline(0, title='0', color=color.gray, linestyle=hline.style_dotted, linewidth=1) // alertcondition(crossunder(val,sig),title="Sell",message="Sell") alertcondition(crossover(val,sig),title="Buy",message="Buy") alertcondition(crossunder(val,sig) or crossover(val,sig) ,title="Sell/Buy",message="Sell/Buy") |
nibor100 1,046 posts msg #158703 - Ignore nibor100 |
3/2/2022 12:46:06 PM @Cheese, I can program a little in Pine Script and while most of that algorithm you posted from TradingView can easily translate to SF, it appears that the lines that set a variable using that same variable's values from 1 day prior, cause an issue in SF's Set statements, causing the resulting filter to hang up with no results. Example variables are EMAF, EMAS, Val... Ed S. |
Cheese 1,374 posts msg #158704 - Ignore Cheese |
3/2/2022 1:32:54 PM https://www.stockfetcher.com/forums/General-Discussion/Normalized-MACD/158522 ====================================== Thank you, Ed S If you don't mind, could you please explain to me in plain English the pine script statements bolded above? If that's too much to ask, could you direct me to the URLs of pine script manuals that explain those notations := , != Any hints might help. I've been struggling with learning pine script using their manuals. |
nibor100 1,046 posts msg #158706 - Ignore nibor100 |
3/2/2022 4:18:00 PM if bar_index > inpSlowPeriod this line makes sure at least 26 days have passed since beginning of chart so the 26 day moving avg can be calculated. bar_index is their built in variable that counts the # of bars in a chart, first bar is 0, 2nd bar is 1, total # of bars is bar_index+1 ( since they start with 0) to reference a bar's number for 1 day ago you write "bar_index[1]", 10 days ago would be "bar_index[10]" alphaf = 2.0/(1.0+max(inpFastPeriod,1)) alphas = 2.0/(1.0+max(inpSlowPeriod,1)) alphasig = 2.0/(1.0+max(inpMacdSignal,1)) alphasm = 2.0/(1.0+max(inpSmoothPeriod,1)) These 4 lines set the variable names on the left to the results of the equations on the right. As I interpret their manuals, using the = sign sets the variable one time only and it can't easily be re-assigned like SFs Set command emaf := emaf[1]+alphaf*(price-emaf[1]) emas := emas[1]+alphas*(price-emas[1]) imacd = emaf-emas These 3 lines set the variable names on the left to the results of the equations on the right. As I interpret their manuals, using the := sign sets the variable once and it can' be easily be re-assigned to different values later on as the code processes mmax = highest(imacd,inpNormPeriod) mmin = lowest(imacd,inpNormPeriod) These 2 lines assign the highest imacd and lowest Imacd, for the last 20 bars to the variable names on the left. The highest() function returns the highest value for the specified data and number of bars. the lowest() function returns the lowest value for the specified data and number of bars if mmin != mmax nval := 2.0*(imacd-mmin)/(mmax-mmin)-1.0 else nval := 0 These 4 lines constitute an If then Else function that is executed when mmin is not equal to mmax. != is the Not Equal operator in Pine Script More info on their Operators can be found here: https://www.tradingview.com/pine-script-docs/en/v4/language/Operators.html An excellent source of beginners coding articles on Pine Script can be found here: https://kodify.net/tradingview/bar-data/highest-high-lowest-low/ Hope this is what you wanted... Ed S. val := val[1] + alphasm*(nval-val[1]) sig := sig[1] + alphasig*(val-sig[1]) |
Cheese 1,374 posts msg #158708 - Ignore Cheese |
3/2/2022 4:36:53 PM https://www.stockfetcher.com/forums/General-Discussion/Normalized-MACD/158522 nibor100 3/2/2022 4:18:00 PM ====================================================== THANK YOU VERY MUCH, Ed S. It will surely help me with learning pine script. |
StockFetcher Forums · General Discussion · Normalized MACD | << >>Post Follow-up |
Copyright 2022 - Vestyl Software L.L.C.•Terms of Service | License | Questions or comments? Contact Us
EOD Data sources: DDFPlus & CSI Data
Quotes delayed during active market hours. Delay times are at least 15 mins for NASDAQ, 20 mins for NYSE and Amex. Delayed intraday data provided by DDFPlus