Tucsky / aggr

Cryptocurrency trades aggregator
https://charts.aggr.trade/
GNU General Public License v3.0
830 stars 240 forks source link

Script Question #249

Closed pattty847 closed 1 year ago

pattty847 commented 1 year ago

Hello again,

I'm just trying to make a script and I seem to be stuck on the last two wt1/wt2.

src = (($price.high + $price.low + $price.close) / 3)
esa = ema(src, 9)
de = ema(Math.abs(src - esa), 9)
ci = (src - esa) / (0.015 * de)
wt1 = ema(ci, 3)
wt2 = sma(wt1, 12)

line(wt1, color = 'green')
line(wt2, color = 'green')

It seems that the wt1, and wt2 do not do anything. I have ran console.log on ci, de, esa, src and they all have values but wt1/wt2 are labeled NaN. I get no errors after saving either.

Maybe you should also create a Discord too, Tucsky! I'm sure tons of ppl would join.

Screenshot 2022-09-28 184751

Tucsky commented 1 year ago

looks like de can be 0 in your script dividing by 0 lead to NaN (not a number) which doesnt work on the chart

ci = (src - esa) / (0.015 * (de || 1))

scripting is very raw... and does not have much verifications to prevent too much performance impact

so to debug the script you can use your browser dev tool, and type "debugger" in the script code image although variables will have different names, it can help understanding the why it's not printing anything :)

wrap it in a condition like if (!src) debugger at the very beginning of the script to ensure the breakpoint will be active before the first bar is rendered (click in and out the code box to re render all bars)

pattty847 commented 1 year ago

Bless Tucsky. Thanks for your help again.

Question: So, if de evaluates to 0 it will use 1 instead? Will that effect the output anyway?

If anyone wants the script I had two variables swapped. The corrected version is:

src = (($price.high + $price.low + $price.close) / 3)
esa = ema(src, 15)
de = ema(Math.abs(src - esa), 15)
ci = (src - esa) / (0.015 * (de || 1))
wt1 = ema(ci, 26)
wt2 = sma(wt1, e)

cloudarea(0, wt1, positiveColor=options.bullColor, negativeColor=options.bearColor, title = 'Wavetrend', linewidth=1)
cloudarea(wt2, wt1, positiveColor=options.bullColor, negativeColor=options.bearColor, linewidth=1)