Is there any workaround for arrays in Pine ScriptPine Script Plot Only the Most Recent ConditionCalculate SMA's Slope in pine scriptAngle of Line in Pine ScriptPine Script beginner, plotshapeRenko Box Size Customization (Pine Script)RSI Failure Swing Pine Script Problem for Tradingviewoffset in atr in tradingview - pine scriptI want a pine-script code for plotting VWAP“addressing” a series in a multi time-frame context in Pine-ScriptHow to use leverage in pine script
Can my 2 children, aged 10 and 12, who are US citizens, travel to the USA on expired American passports?
Notation: What does the tilde bellow of the Expectation mean?
What is a common way to tell if an academic is "above average," or outstanding in their field? Is their h-index (Hirsh index) one of them?
What do "Sech" and "Vich" mean in this sentence?
Why is "breaking the mould" positively connoted?
Hostile Divisor Numbers
Are the Night's Watch still required?
How to pass hash as password to ssh server
What to use instead of cling film to wrap pastry
Start job from another SQL server instance
A factorization game
Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?
Nested loops to process groups of pictures
Gerrymandering Puzzle - Rig the Election
Should homeowners insurance cover the cost of the home?
Are there terms in German for different skull shapes?
Desolate vs deserted
Is Soreness in Middle Knuckle of Fretting Hand Index Finger Normal for Beginners?
Outlining A Novel - How do you make it less of a slog?
What is this weird transparent border appearing inside my Smart Object in Photoshop?
Can you use "едать" and "игрывать" in the present and future tenses?
Change in "can't be countered" wording
Would you use "llamarse" for an animal's name?
What are the advantages of luxury car brands like Acura/Lexus over their sibling non-luxury brands Honda/Toyota?
Is there any workaround for arrays in Pine Script
Pine Script Plot Only the Most Recent ConditionCalculate SMA's Slope in pine scriptAngle of Line in Pine ScriptPine Script beginner, plotshapeRenko Box Size Customization (Pine Script)RSI Failure Swing Pine Script Problem for Tradingviewoffset in atr in tradingview - pine scriptI want a pine-script code for plotting VWAP“addressing” a series in a multi time-frame context in Pine-ScriptHow to use leverage in pine script
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
Arrays are not available in PineScript.
Is there any workaround? Has anyone developed a code, which works as array?
What do I need it for? I would like to count number of touches to each trendline or S/R level.
pine-script
add a comment |
Arrays are not available in PineScript.
Is there any workaround? Has anyone developed a code, which works as array?
What do I need it for? I would like to count number of touches to each trendline or S/R level.
pine-script
1
Unfortunately, I have not seen any workarounds for arrays. However, it is possible to implement a counter if that’s what you need. If you show me some code regarding how you get the trendline or S/R levels, I can help you with that.
– Baris Yakut
Mar 23 at 7:30
Thanks. So this is the code for S/R levels. Ideally I would like to have an array of these with a counter of touches with those lines. tradingview.com/script/JwWWwZOD-RSI-MTF-by-PeterO
– PeterO
Mar 23 at 12:15
add a comment |
Arrays are not available in PineScript.
Is there any workaround? Has anyone developed a code, which works as array?
What do I need it for? I would like to count number of touches to each trendline or S/R level.
pine-script
Arrays are not available in PineScript.
Is there any workaround? Has anyone developed a code, which works as array?
What do I need it for? I would like to count number of touches to each trendline or S/R level.
pine-script
pine-script
edited Mar 24 at 15:33
PeterO
asked Mar 23 at 0:55
PeterOPeterO
63
63
1
Unfortunately, I have not seen any workarounds for arrays. However, it is possible to implement a counter if that’s what you need. If you show me some code regarding how you get the trendline or S/R levels, I can help you with that.
– Baris Yakut
Mar 23 at 7:30
Thanks. So this is the code for S/R levels. Ideally I would like to have an array of these with a counter of touches with those lines. tradingview.com/script/JwWWwZOD-RSI-MTF-by-PeterO
– PeterO
Mar 23 at 12:15
add a comment |
1
Unfortunately, I have not seen any workarounds for arrays. However, it is possible to implement a counter if that’s what you need. If you show me some code regarding how you get the trendline or S/R levels, I can help you with that.
– Baris Yakut
Mar 23 at 7:30
Thanks. So this is the code for S/R levels. Ideally I would like to have an array of these with a counter of touches with those lines. tradingview.com/script/JwWWwZOD-RSI-MTF-by-PeterO
– PeterO
Mar 23 at 12:15
1
1
Unfortunately, I have not seen any workarounds for arrays. However, it is possible to implement a counter if that’s what you need. If you show me some code regarding how you get the trendline or S/R levels, I can help you with that.
– Baris Yakut
Mar 23 at 7:30
Unfortunately, I have not seen any workarounds for arrays. However, it is possible to implement a counter if that’s what you need. If you show me some code regarding how you get the trendline or S/R levels, I can help you with that.
– Baris Yakut
Mar 23 at 7:30
Thanks. So this is the code for S/R levels. Ideally I would like to have an array of these with a counter of touches with those lines. tradingview.com/script/JwWWwZOD-RSI-MTF-by-PeterO
– PeterO
Mar 23 at 12:15
Thanks. So this is the code for S/R levels. Ideally I would like to have an array of these with a counter of touches with those lines. tradingview.com/script/JwWWwZOD-RSI-MTF-by-PeterO
– PeterO
Mar 23 at 12:15
add a comment |
1 Answer
1
active
oldest
votes
To implement a counter, you can create a variable and then modify its value by using the History Referencing Operator [].
Below example counts number of crossover/crossunder occurrences in a typical rsi diagram.
//@version=3
study("counter", overlay=false)
rsi_max = 70
rsi_min = 30
cnt_up = 0
cnt_dwn = 0
cnt_up := crossover(rsi(close, 14), rsi_max) ? nz(cnt_up[1]) + 1 : nz(cnt_up[1])
cnt_dwn := crossunder(rsi(close, 14), rsi_min) ? nz(cnt_dwn[1]) + 1 : nz(cnt_dwn[1])
plot(rsi(close, 14), color=orange, title='RSI')
plot(series=cnt_up, title="Up counter", color=green)
plot(series=cnt_dwn, title="Down counter", color=red)
band0 = hline(30)
band1 = hline(70)
fill(band1, band0, color=purple, transp=90)
Green line is the "cnt_up" in my example. After that point, rsi line crosses over the "overbought" zone 7 more times.

And here, you can see that "cnt_up" indeed counted up 7 times.

Unfortunately, this is all you can do.
Thanks Baris. Yes, I knew how to do the counter. The challenge with counting touches to S/R levels is that there can be multiple S/R levels and we don't know how many of them and the goal is to add counter to each of them. As far as I know, this is where arrays come in handy. But like we said - there is no native implementation of arrays and this might be the reason why I'll have to learn another language to code this.
– PeterO
Mar 25 at 10:04
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309584%2fis-there-any-workaround-for-arrays-in-pine-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To implement a counter, you can create a variable and then modify its value by using the History Referencing Operator [].
Below example counts number of crossover/crossunder occurrences in a typical rsi diagram.
//@version=3
study("counter", overlay=false)
rsi_max = 70
rsi_min = 30
cnt_up = 0
cnt_dwn = 0
cnt_up := crossover(rsi(close, 14), rsi_max) ? nz(cnt_up[1]) + 1 : nz(cnt_up[1])
cnt_dwn := crossunder(rsi(close, 14), rsi_min) ? nz(cnt_dwn[1]) + 1 : nz(cnt_dwn[1])
plot(rsi(close, 14), color=orange, title='RSI')
plot(series=cnt_up, title="Up counter", color=green)
plot(series=cnt_dwn, title="Down counter", color=red)
band0 = hline(30)
band1 = hline(70)
fill(band1, band0, color=purple, transp=90)
Green line is the "cnt_up" in my example. After that point, rsi line crosses over the "overbought" zone 7 more times.

And here, you can see that "cnt_up" indeed counted up 7 times.

Unfortunately, this is all you can do.
Thanks Baris. Yes, I knew how to do the counter. The challenge with counting touches to S/R levels is that there can be multiple S/R levels and we don't know how many of them and the goal is to add counter to each of them. As far as I know, this is where arrays come in handy. But like we said - there is no native implementation of arrays and this might be the reason why I'll have to learn another language to code this.
– PeterO
Mar 25 at 10:04
add a comment |
To implement a counter, you can create a variable and then modify its value by using the History Referencing Operator [].
Below example counts number of crossover/crossunder occurrences in a typical rsi diagram.
//@version=3
study("counter", overlay=false)
rsi_max = 70
rsi_min = 30
cnt_up = 0
cnt_dwn = 0
cnt_up := crossover(rsi(close, 14), rsi_max) ? nz(cnt_up[1]) + 1 : nz(cnt_up[1])
cnt_dwn := crossunder(rsi(close, 14), rsi_min) ? nz(cnt_dwn[1]) + 1 : nz(cnt_dwn[1])
plot(rsi(close, 14), color=orange, title='RSI')
plot(series=cnt_up, title="Up counter", color=green)
plot(series=cnt_dwn, title="Down counter", color=red)
band0 = hline(30)
band1 = hline(70)
fill(band1, band0, color=purple, transp=90)
Green line is the "cnt_up" in my example. After that point, rsi line crosses over the "overbought" zone 7 more times.

And here, you can see that "cnt_up" indeed counted up 7 times.

Unfortunately, this is all you can do.
Thanks Baris. Yes, I knew how to do the counter. The challenge with counting touches to S/R levels is that there can be multiple S/R levels and we don't know how many of them and the goal is to add counter to each of them. As far as I know, this is where arrays come in handy. But like we said - there is no native implementation of arrays and this might be the reason why I'll have to learn another language to code this.
– PeterO
Mar 25 at 10:04
add a comment |
To implement a counter, you can create a variable and then modify its value by using the History Referencing Operator [].
Below example counts number of crossover/crossunder occurrences in a typical rsi diagram.
//@version=3
study("counter", overlay=false)
rsi_max = 70
rsi_min = 30
cnt_up = 0
cnt_dwn = 0
cnt_up := crossover(rsi(close, 14), rsi_max) ? nz(cnt_up[1]) + 1 : nz(cnt_up[1])
cnt_dwn := crossunder(rsi(close, 14), rsi_min) ? nz(cnt_dwn[1]) + 1 : nz(cnt_dwn[1])
plot(rsi(close, 14), color=orange, title='RSI')
plot(series=cnt_up, title="Up counter", color=green)
plot(series=cnt_dwn, title="Down counter", color=red)
band0 = hline(30)
band1 = hline(70)
fill(band1, band0, color=purple, transp=90)
Green line is the "cnt_up" in my example. After that point, rsi line crosses over the "overbought" zone 7 more times.

And here, you can see that "cnt_up" indeed counted up 7 times.

Unfortunately, this is all you can do.
To implement a counter, you can create a variable and then modify its value by using the History Referencing Operator [].
Below example counts number of crossover/crossunder occurrences in a typical rsi diagram.
//@version=3
study("counter", overlay=false)
rsi_max = 70
rsi_min = 30
cnt_up = 0
cnt_dwn = 0
cnt_up := crossover(rsi(close, 14), rsi_max) ? nz(cnt_up[1]) + 1 : nz(cnt_up[1])
cnt_dwn := crossunder(rsi(close, 14), rsi_min) ? nz(cnt_dwn[1]) + 1 : nz(cnt_dwn[1])
plot(rsi(close, 14), color=orange, title='RSI')
plot(series=cnt_up, title="Up counter", color=green)
plot(series=cnt_dwn, title="Down counter", color=red)
band0 = hline(30)
band1 = hline(70)
fill(band1, band0, color=purple, transp=90)
Green line is the "cnt_up" in my example. After that point, rsi line crosses over the "overbought" zone 7 more times.

And here, you can see that "cnt_up" indeed counted up 7 times.

Unfortunately, this is all you can do.
answered Mar 25 at 6:09
Baris YakutBaris Yakut
6161412
6161412
Thanks Baris. Yes, I knew how to do the counter. The challenge with counting touches to S/R levels is that there can be multiple S/R levels and we don't know how many of them and the goal is to add counter to each of them. As far as I know, this is where arrays come in handy. But like we said - there is no native implementation of arrays and this might be the reason why I'll have to learn another language to code this.
– PeterO
Mar 25 at 10:04
add a comment |
Thanks Baris. Yes, I knew how to do the counter. The challenge with counting touches to S/R levels is that there can be multiple S/R levels and we don't know how many of them and the goal is to add counter to each of them. As far as I know, this is where arrays come in handy. But like we said - there is no native implementation of arrays and this might be the reason why I'll have to learn another language to code this.
– PeterO
Mar 25 at 10:04
Thanks Baris. Yes, I knew how to do the counter. The challenge with counting touches to S/R levels is that there can be multiple S/R levels and we don't know how many of them and the goal is to add counter to each of them. As far as I know, this is where arrays come in handy. But like we said - there is no native implementation of arrays and this might be the reason why I'll have to learn another language to code this.
– PeterO
Mar 25 at 10:04
Thanks Baris. Yes, I knew how to do the counter. The challenge with counting touches to S/R levels is that there can be multiple S/R levels and we don't know how many of them and the goal is to add counter to each of them. As far as I know, this is where arrays come in handy. But like we said - there is no native implementation of arrays and this might be the reason why I'll have to learn another language to code this.
– PeterO
Mar 25 at 10:04
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55309584%2fis-there-any-workaround-for-arrays-in-pine-script%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Unfortunately, I have not seen any workarounds for arrays. However, it is possible to implement a counter if that’s what you need. If you show me some code regarding how you get the trendline or S/R levels, I can help you with that.
– Baris Yakut
Mar 23 at 7:30
Thanks. So this is the code for S/R levels. Ideally I would like to have an array of these with a counter of touches with those lines. tradingview.com/script/JwWWwZOD-RSI-MTF-by-PeterO
– PeterO
Mar 23 at 12:15