Open dairefagan opened 1 year ago
The red icon cross thing next to the line is not relevant because it use js syntax validation and line(COINBASE:BTC-USD.close)
isn't
Just ignore those, you will notice the script is rendering just fine anyway
Custom functions was never supported, sorry..
For the reference to previous value of a var, it only works if you don't put var keyword in front AND if the script can determine how many version of this var it has to store
When you use it in a loop with i
as index it won't work because it cannot
But when you do price[1] or price[10] etc... it know it has to store up to 10 values
to bypass this you can use myVar(100) = COINBASE:BTC-USD.close
at the initialization of the variable and the script will know it has to store 100 values for that var
Not sure what you were trying to do with the for loop but this is working :
price(5) = COINBASE:BTC-USD.close
var x = 0
for (let i = 0; i < 5; i++) {
console.log(price[i])
x += price[i]
}
line(x)
note the (5)
😃
// to summarize
console.log(hot) // undefined
console.log(cold) // 0 the first execution, then 1234
var hot = 1234 // runtime only variable
cold = 1234 // var preserved from one tick to another
But for most case you shouldn't use any for
loops really... bad performance
Built in function like sum, max, min sma ema etc doesn't use for
because they store the count, sum and keep track of those values over a determined length
Thanks for the prompt and thorough explanation, that worked great!
Reducing complexity is always a good idea, and I will experiment and rework any loop code to use built in functions where possible but it seems sometimes loops will be required.
Similar to how the script knows how many values to store using the price(50) syntax, would it be possible to force the cumulative function to use a certain number of values? I assume this would make the values more stable so that it would be necessary to scroll back much further into off-screen bars to change the value of the bars around realtime?
I appreciate this will not change the direction of CVD or where it pivots etc but it will make CVDs easier to work with, like when comparing just the static deltas.
Then you are looking at sum
function, which allows u to specify the length (ex 50) as argument
last50candlesDelta = sum(vbuy - vsell, options.length || 50)
For more advanced indicators like the auto anchored vwap, as basic vwap (no period) is calculated using with cumulative functions, If you want the VWAP to "restart" at each price pivots you can hack the cumulative function by accessing the underlying *state" of the function with fns[index of function] And overriding it with a new value
exemple here : VWAP AA.txt
Then you are looking at
sum
function, which allows u to specify the length (ex 50) as argumentlast50candlesDelta = sum(vbuy - vsell, options.length || 50)
I wanted to see exactly how similar this is to just using cum, and thinking if I used the correct length I should be able to match both plots I tried doing this manually unsuccessfully. On referencing VWAP AA I saw we can get the series count with:
var count = cum(series.length);
Passing this to sum works although it starts plotting only on recent bars unlike cum:
If I scroll backwards the missing plot is revealed but it turns out this approach mimics cum too well, as the values have also changed when I scroll back to realtime.
I could just only look at present bars on the same screen but visual backtesting and indicator tuning would be easier if the values were fixed, and the same chart can either display a buy or sell signal depending on whether I have it loaded on my monitor or phone.
For more advanced indicators like the auto anchored vwap, as basic vwap (no period) is calculated using with cumulative functions, If you want the VWAP to "restart" at each price pivots you can hack the cumulative function by accessing the underlying *state" of the function with fns[index of function] And overriding it with a new value
I read we reference the functions by the order they appear in the script so for a test script containing just a cum call that would be fns[0] but I am unfamiliar with how the syntax of the cum function definition works exactly and I am unsure how I should change the state or states to achieve what I want, cum that does not change realtime values when I scroll backwards, preferably matching the default when looking at real time.
Since the delta values themselves are fixed maybe manually adding these each bar without using sum or cum would represent the same data as CVD while being static, the delta series alone giving different results.
Also separately, is there any way to pass an options variable to myVar(100) = COINBASE:BTC-USD.close
, and is there a syntax to define a dropdown menu?
The editor is generating errors for simple source referecnes that I do not think it did in the past:
Is there some way to escape the colon if that is the issue? It does not seem to cause an issue with the script, even when there are errors declaring a variable as a source, I would just like to see it without errors.
When I try to create custom functions I receive errors that the function does not exist.
Is it the case you have removed this utility? If so perhaps this is something I can workaround by compiling from source and editing serieUtils.ts.
When I try referencing the current bar from a loop as the 0th element I recieve an error that it is undefined, and when I try a workaround within the loop it generates a NaN. I read up on ES6 scope in case that was the issue and I tried different combinations of var, let, and no keyword, for declarations and re-assignments but I could not make this work. Is there something else I can try please so that I can loop through the last i bars and update a global variable accordingly?