StockFetcher Forums · Filter Exchange · ALMA - Arnaud Legoux Moving Average<< >>Post Follow-up
binque
6 posts
msg #143514
Ignore binque
modified
5/10/2018 11:49:46 AM

Need some help with the ALMA indicator. Not sure how to program it in Stock Fetcher.

I found some source code on a different website and not sure what language it is as follows:

https://www.prorealcode.com/prorealtime-indicators/alma-arnaud-legoux-moving-average/

// parameters
// Window = 9
// Sigma = 6
// Offset = 0.85

Price = Close

m = (Offset * (Window - 1))
s = Window/Sigma

WtdSum = 0
CumWt = 0

for k = 0 to Window - 1 do
Wtd = Exp(-((k-m)*(k-m))/(2*s*s))
WtdSum = WtdSum + Wtd * Price[Window - 1 - k]
CumWt = CumWt + Wtd
next

ALAverage = WtdSum / CumWt

RETURN ALAverage

// --- END ---

Any help would be appreciated. Thank you.

data-miner
11 posts
msg #144174
Ignore data-miner
7/23/2018 4:06:48 PM

I was curious about ALMA and I discovered found your post here. I have tried to duplicate this from the formula you had listed.

There is so much code here, that you may get a performance limit error if you try to add anything. I have a base subscription so when I tried to plot the average on the price chart I got an error. So I stripped out all of the comments and posted them separately. Sometimes it works, sometimes it does not. One option may be to scale it down and do a window of 5 instead of 9

I don't believe looping is possible in stockfetcher. So I am having to add each line

I would be curious if this has any correlation to the original site's code.

Fetcher[
set{Window, 9 }
set{Sigma, 6}
set{Offset,0.85}
set{varm1, Window - 1}
set{m, Offset * varm1}
set{s, Window / Sigma}

set{k0,0}
set{k1,1}
set{k2,2}
set{k3,3}
set{k4,4}
set{k5,5}
set{k6,6}
set{k7,7}
set{k8,8}


set{WtdSum, 0.0000}

set{varss1, s * s}
set{varss2, 2 * varss1}

set{varkm0, k0 - m}
set{varkm1, k1 - m}
set{varkm2, k2 - m}
set{varkm3, k3 - m}
set{varkm4, k4 - m}
set{varkm5, k5 - m}
set{varkm6, k6 - m}
set{varkm7, k7 - m}
set{varkm8, k8 - m}

set{varkmA, varkm0 * varkm0}
set{varkmB, varkm1 * varkm1}
set{varkmC, varkm2 * varkm2}
set{varkmD, varkm3 * varkm3}
set{varkmE, varkm4 * varkm4}
set{varkmF, varkm5 * varkm5}
set{varkmG, varkm6 * varkm6}
set{varkmH, varkm7 * varkm7}
set{varkmI, varkm8 * varkm8}

set{varExpA1, varkmA / varss2}
set{varExpB1, varkmB / varss2}
set{varExpC1, varkmC / varss2}
set{varExpD1, varkmD / varss2}
set{varExpE1, varkmE / varss2}
set{varExpF1, varkmF / varss2}
set{varExpG1, varkmG / varss2}
set{varExpH1, varkmH / varss2}
set{varExpI1, varkmI / varss2}

set{varExpA, -1 * varExpA1}
set{varExpB, -1 * varExpB1}
set{varExpC, -1 * varExpC1}
set{varExpD, -1 * varExpD1}
set{varExpE, -1 * varExpE1}
set{varExpF, -1 * varExpF1}
set{varExpG, -1 * varExpG1}
set{varExpH, -1 * varExpH1}
set{varExpI, -1 * varExpI1}

set{WtdA, Exp(varExpA) }
set{WtdB, Exp(varExpB) }
set{WtdC, Exp(varExpC) }
set{WtdD, Exp(varExpD) }
set{WtdE, Exp(varExpE) }
set{WtdF, Exp(varExpF) }
set{WtdG, Exp(varExpG) }
set{WtdH, Exp(varExpH) }
set{WtdI, Exp(varExpI) }

set{WtdSum0, WtdA * Price 8 days ago}
set{WtdSum1, WtdB * Price 7 days ago}
set{WtdSum2, WtdC * Price 6 days ago}
set{WtdSum3, WtdD * Price 5 days ago}
set{WtdSum4, WtdE * Price 4 days ago}
set{WtdSum5, WtdF * Price 3 days ago}
set{WtdSum6, WtdG * Price 2 days ago}
set{WtdSum7, WtdH * Price 1 day ago}
set{WtdSum8, WtdI * Price}


Set{WtdSumA, WtdSum0}
Set{WtdSumB, WtdSum1 + WtdSumA}
Set{WtdSumC, WtdSum2 + WtdSumB}
Set{WtdSumD, WtdSum3 + WtdSumC}
Set{WtdSumE, WtdSum4 + WtdSumD}
Set{WtdSumF, WtdSum5 + WtdSumE}
Set{WtdSumG, WtdSum6 + WtdSumF}
Set{WtdSumH, WtdSum7 + WtdSumG}
Set{WtdSumI, WtdSum8 + WtdSumH}

set{CumWt0, WtdA}
set{CumWt1, CumWt0 + WtdB}
set{CumWt2, CumWt1 + WtdC}
set{CumWt3, CumWt2 + WtdD}
set{CumWt4, CumWt3 + WtdE}
set{CumWt5, CumWt4 + WtdF}
set{CumWt6, CumWt5 + WtdG}
set{CumWt7, CumWt6 + WtdH}
set{CumWt8, CumWt7 + WtdI}

set{ALAverage, WtdSumI / CumWt8}

show stocks where price is between 10 and 100

draw ALAverage on plot price
]



COMMENTS BELOW:

set{Window, 9 }
set{Sigma, 6}
set{Offset,0.85}
set{varm1, Window - 1}
set{m, Offset * varm1}
set{s, Window / Sigma}


/* for k = 0 to Window - 1 do */
/* FOR K = 0 TO 8 so there are 9 loops including 0 */
set{k0,0}
set{k1,1}
set{k2,2}
set{k3,3}
set{k4,4}
set{k5,5}
set{k6,6}
set{k7,7}
set{k8,8}


set{WtdSum, 0.0000}


/* I don't believe looping is possible in stockfetcher.*/
/* if it is someody please let me know */
/* BEGINNING OF WHAT WOULD BE THE LOOP*/
/* Here is the section for the equation Wtd = Exp(-((k-m)*(k-m))/(2*s*s)) */
set{varss1, s * s}
set{varss2, 2 * varss1}

set{varkm0, k0 - m}
set{varkm1, k1 - m}
set{varkm2, k2 - m}
set{varkm3, k3 - m}
set{varkm4, k4 - m}
set{varkm5, k5 - m}
set{varkm6, k6 - m}
set{varkm7, k7 - m}
set{varkm8, k8 - m}

set{varkmA, varkm0 * varkm0}
set{varkmB, varkm1 * varkm1}
set{varkmC, varkm2 * varkm2}
set{varkmD, varkm3 * varkm3}
set{varkmE, varkm4 * varkm4}
set{varkmF, varkm5 * varkm5}
set{varkmG, varkm6 * varkm6}
set{varkmH, varkm7 * varkm7}
set{varkmI, varkm8 * varkm8}

set{varExpA1, varkmA / varss2}
set{varExpB1, varkmB / varss2}
set{varExpC1, varkmC / varss2}
set{varExpD1, varkmD / varss2}
set{varExpE1, varkmE / varss2}
set{varExpF1, varkmF / varss2}
set{varExpG1, varkmG / varss2}
set{varExpH1, varkmH / varss2}
set{varExpI1, varkmI / varss2}

set{varExpA, -1 * varExpA1}
set{varExpB, -1 * varExpB1}
set{varExpC, -1 * varExpC1}
set{varExpD, -1 * varExpD1}
set{varExpE, -1 * varExpE1}
set{varExpF, -1 * varExpF1}
set{varExpG, -1 * varExpG1}
set{varExpH, -1 * varExpH1}
set{varExpI, -1 * varExpI1}

set{WtdA, Exp(varExpA) }
set{WtdB, Exp(varExpB) }
set{WtdC, Exp(varExpC) }
set{WtdD, Exp(varExpD) }
set{WtdE, Exp(varExpE) }
set{WtdF, Exp(varExpF) }
set{WtdG, Exp(varExpG) }
set{WtdH, Exp(varExpH) }
set{WtdI, Exp(varExpI) }


/*Here is the section for WtdSum = WtdSum + Wtd * Price[Window - 1 - k] */
/*Window - 1 - k */
/*9-1-0 = 8 price 8 days ago*/
/*...*/
/*9-1-2 = 2 price 2 days ago*/
/*9-1-2 = 1 price one day ago*/
/*9-1-2 = 0 current price*/

set{WtdSum0, WtdA * Price 8 days ago}
set{WtdSum1, WtdB * Price 7 days ago}
set{WtdSum2, WtdC * Price 6 days ago}
set{WtdSum3, WtdD * Price 5 days ago}
set{WtdSum4, WtdE * Price 4 days ago}
set{WtdSum5, WtdF * Price 3 days ago}
set{WtdSum6, WtdG * Price 2 days ago}
set{WtdSum7, WtdH * Price 1 day ago}
set{WtdSum8, WtdI * Price}


/* Here is where the totals are accumulated */
/* it does not appear that you can var = var +1 in stockfetcher*/
Set{WtdSumA, WtdSum0}
Set{WtdSumB, WtdSum1 + WtdSumA}
Set{WtdSumC, WtdSum2 + WtdSumB}
Set{WtdSumD, WtdSum3 + WtdSumC}
Set{WtdSumE, WtdSum4 + WtdSumD}
Set{WtdSumF, WtdSum5 + WtdSumE}
Set{WtdSumG, WtdSum6 + WtdSumF}
Set{WtdSumH, WtdSum7 + WtdSumG}
Set{WtdSumI, WtdSum8 + WtdSumH}

set{CumWt0, WtdA}
set{CumWt1, CumWt0 + WtdB}
set{CumWt2, CumWt1 + WtdC}
set{CumWt3, CumWt2 + WtdD}
set{CumWt4, CumWt3 + WtdE}
set{CumWt5, CumWt4 + WtdF}
set{CumWt6, CumWt5 + WtdG}
set{CumWt7, CumWt6 + WtdH}
set{CumWt8, CumWt7 + WtdI}


/*END OF WHAT WOULD BE THE LOOP*/
/*This is the main average that is sought*/
set{ALAverage, WtdSumI / CumWt8}

show stocks where price is between 10 and 100

draw ALAverage on plot Price


graftonian
1,089 posts
msg #144175
Ignore graftonian
7/24/2018 8:11:56 AM

Data miner:
Nice job. I've been searching for the elusive zero lag MA, my best attempt has been the Hull MA. I've copied my Hull work onto your code to compare.
Fetcher[

set{Window, 9 }
set{Sigma, 6}
set{Offset,0.85}
set{varm1, Window - 1}
set{m, Offset * varm1}
set{s, Window / Sigma}

set{k0,0}
set{k1,1}
set{k2,2}
set{k3,3}
set{k4,4}
set{k5,5}
set{k6,6}
set{k7,7}
set{k8,8}


set{WtdSum, 0.0000}

set{varss1, s * s}
set{varss2, 2 * varss1}

set{varkm0, k0 - m}
set{varkm1, k1 - m}
set{varkm2, k2 - m}
set{varkm3, k3 - m}
set{varkm4, k4 - m}
set{varkm5, k5 - m}
set{varkm6, k6 - m}
set{varkm7, k7 - m}
set{varkm8, k8 - m}

set{varkmA, varkm0 * varkm0}
set{varkmB, varkm1 * varkm1}
set{varkmC, varkm2 * varkm2}
set{varkmD, varkm3 * varkm3}
set{varkmE, varkm4 * varkm4}
set{varkmF, varkm5 * varkm5}
set{varkmG, varkm6 * varkm6}
set{varkmH, varkm7 * varkm7}
set{varkmI, varkm8 * varkm8}

set{varExpA1, varkmA / varss2}
set{varExpB1, varkmB / varss2}
set{varExpC1, varkmC / varss2}
set{varExpD1, varkmD / varss2}
set{varExpE1, varkmE / varss2}
set{varExpF1, varkmF / varss2}
set{varExpG1, varkmG / varss2}
set{varExpH1, varkmH / varss2}
set{varExpI1, varkmI / varss2}

set{varExpA, -1 * varExpA1}
set{varExpB, -1 * varExpB1}
set{varExpC, -1 * varExpC1}
set{varExpD, -1 * varExpD1}
set{varExpE, -1 * varExpE1}
set{varExpF, -1 * varExpF1}
set{varExpG, -1 * varExpG1}
set{varExpH, -1 * varExpH1}
set{varExpI, -1 * varExpI1}

set{WtdA, Exp(varExpA) }
set{WtdB, Exp(varExpB) }
set{WtdC, Exp(varExpC) }
set{WtdD, Exp(varExpD) }
set{WtdE, Exp(varExpE) }
set{WtdF, Exp(varExpF) }
set{WtdG, Exp(varExpG) }
set{WtdH, Exp(varExpH) }
set{WtdI, Exp(varExpI) }

set{WtdSum0, WtdA * Price 8 days ago}
set{WtdSum1, WtdB * Price 7 days ago}
set{WtdSum2, WtdC * Price 6 days ago}
set{WtdSum3, WtdD * Price 5 days ago}
set{WtdSum4, WtdE * Price 4 days ago}
set{WtdSum5, WtdF * Price 3 days ago}
set{WtdSum6, WtdG * Price 2 days ago}
set{WtdSum7, WtdH * Price 1 day ago}
set{WtdSum8, WtdI * Price}


Set{WtdSumA, WtdSum0}
Set{WtdSumB, WtdSum1 + WtdSumA}
Set{WtdSumC, WtdSum2 + WtdSumB}
Set{WtdSumD, WtdSum3 + WtdSumC}
Set{WtdSumE, WtdSum4 + WtdSumD}
Set{WtdSumF, WtdSum5 + WtdSumE}
Set{WtdSumG, WtdSum6 + WtdSumF}
Set{WtdSumH, WtdSum7 + WtdSumG}
Set{WtdSumI, WtdSum8 + WtdSumH}

set{CumWt0, WtdA}
set{CumWt1, CumWt0 + WtdB}
set{CumWt2, CumWt1 + WtdC}
set{CumWt3, CumWt2 + WtdD}
set{CumWt4, CumWt3 + WtdE}
set{CumWt5, CumWt4 + WtdF}
set{CumWt6, CumWt5 + WtdG}
set{CumWt7, CumWt6 + WtdH}
set{CumWt8, CumWt7 + WtdI}

set{ALAverage, WtdSumI / CumWt8}

show stocks where price is between 10 and 100

draw ALAverage on plot price

/*HULL MA */
set{slow1, cwma(close, 5)}
set{slow2, 2 * slow1}
set{slow3, cwma(close, 10)}
set{valslow, slow2 - slow3}
set{HULL10MA, cwma(valslow, 3)}
draw HULL10MA on plot price
]



data-miner
11 posts
msg #144188
Ignore data-miner
7/24/2018 6:28:04 PM

I do like the simplicity of your HULL code and the results are very close. I've got them almost identical by changing the slow3 from close to Open + Close / 2 and shortening the slow3 from 10 to 6

Thanks for contributing,
Fetcher[
set{Window, 9 }
set{Sigma, 6}
set{Offset,0.85}
set{varm1, Window - 1}
set{m, Offset * varm1}
set{s, Window / Sigma}

set{k0,0}
set{k1,1}
set{k2,2}
set{k3,3}
set{k4,4}
set{k5,5}
set{k6,6}
set{k7,7}
set{k8,8}


set{WtdSum, 0.0000}

set{varss1, s * s}
set{varss2, 2 * varss1}

set{varkm0, k0 - m}
set{varkm1, k1 - m}
set{varkm2, k2 - m}
set{varkm3, k3 - m}
set{varkm4, k4 - m}
set{varkm5, k5 - m}
set{varkm6, k6 - m}
set{varkm7, k7 - m}
set{varkm8, k8 - m}

set{varkmA, varkm0 * varkm0}
set{varkmB, varkm1 * varkm1}
set{varkmC, varkm2 * varkm2}
set{varkmD, varkm3 * varkm3}
set{varkmE, varkm4 * varkm4}
set{varkmF, varkm5 * varkm5}
set{varkmG, varkm6 * varkm6}
set{varkmH, varkm7 * varkm7}
set{varkmI, varkm8 * varkm8}

set{varExpA1, varkmA / varss2}
set{varExpB1, varkmB / varss2}
set{varExpC1, varkmC / varss2}
set{varExpD1, varkmD / varss2}
set{varExpE1, varkmE / varss2}
set{varExpF1, varkmF / varss2}
set{varExpG1, varkmG / varss2}
set{varExpH1, varkmH / varss2}
set{varExpI1, varkmI / varss2}

set{varExpA, -1 * varExpA1}
set{varExpB, -1 * varExpB1}
set{varExpC, -1 * varExpC1}
set{varExpD, -1 * varExpD1}
set{varExpE, -1 * varExpE1}
set{varExpF, -1 * varExpF1}
set{varExpG, -1 * varExpG1}
set{varExpH, -1 * varExpH1}
set{varExpI, -1 * varExpI1}

set{WtdA, Exp(varExpA) }
set{WtdB, Exp(varExpB) }
set{WtdC, Exp(varExpC) }
set{WtdD, Exp(varExpD) }
set{WtdE, Exp(varExpE) }
set{WtdF, Exp(varExpF) }
set{WtdG, Exp(varExpG) }
set{WtdH, Exp(varExpH) }
set{WtdI, Exp(varExpI) }

set{WtdSum0, WtdA * Price 8 days ago}
set{WtdSum1, WtdB * Price 7 days ago}
set{WtdSum2, WtdC * Price 6 days ago}
set{WtdSum3, WtdD * Price 5 days ago}
set{WtdSum4, WtdE * Price 4 days ago}
set{WtdSum5, WtdF * Price 3 days ago}
set{WtdSum6, WtdG * Price 2 days ago}
set{WtdSum7, WtdH * Price 1 day ago}
set{WtdSum8, WtdI * Price}


Set{WtdSumA, WtdSum0}
Set{WtdSumB, WtdSum1 + WtdSumA}
Set{WtdSumC, WtdSum2 + WtdSumB}
Set{WtdSumD, WtdSum3 + WtdSumC}
Set{WtdSumE, WtdSum4 + WtdSumD}
Set{WtdSumF, WtdSum5 + WtdSumE}
Set{WtdSumG, WtdSum6 + WtdSumF}
Set{WtdSumH, WtdSum7 + WtdSumG}
Set{WtdSumI, WtdSum8 + WtdSumH}

set{CumWt0, WtdA}
set{CumWt1, CumWt0 + WtdB}
set{CumWt2, CumWt1 + WtdC}
set{CumWt3, CumWt2 + WtdD}
set{CumWt4, CumWt3 + WtdE}
set{CumWt5, CumWt4 + WtdF}
set{CumWt6, CumWt5 + WtdG}
set{CumWt7, CumWt6 + WtdH}
set{CumWt8, CumWt7 + WtdI}

set{ALAverage, WtdSumI / CumWt8}

show stocks where price is between 10 and 100

draw ALAverage on plot price

/*HULL MA ===MODIFIED=== */
set{varOC, Open + Close}
set{varOC2, varOC /2}
set{slow1, cwma(close, 5)}
set{slow2, 2 * slow1}
set{slow3, cwma(varOC2, 6)}
set{valslow, slow2 - slow3}
set{HULL10MA, cwma(valslow, 3)}
draw HULL10MA on plot price
]



StockFetcher Forums · Filter Exchange · ALMA - Arnaud Legoux Moving Average<< >>Post Follow-up

*** Disclaimer *** StockFetcher.com does not endorse or suggest any of the securities which are returned in any of the searches or filters. They are provided purely for informational and research purposes. StockFetcher.com does not recommend particular securities. StockFetcher.com, Vestyl Software, L.L.C. and involved content providers shall not be liable for any errors or delays in the content, or for any actions taken based on the content.


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


This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.