Hi,
Need help coding the following scenario:
input length = 10;
I want to calculate Exp(-(Power(-i, 2) / 128)) for the last X bars
I would like to see in my last 10 bars the following values:
mydef = 8.173035134
mydef[1] = 8.634157081
mydef[2] = 8.996859656
mydef[3] = 9.247021397
mydef[4] = 9.374678698
mydef[5] = 9.374678698
mydef[6] = 9.247021397
mydef[7] = 8.996859656
mydef[8] = 8.634157081
mydef[9] = 8.173035134
I am trying to do a loop to get the first value of 8.173035134
counter result
0 1
-1 0.992217938
-2 0.969233234
-3 0.932102492
-4 0.882496903
-5 0.822577562
-6 0.754839602
-7 0.681940751
-8 0.60653066
-9 0.531095991
and so for
Can you tell me what I am doing wrong?
This is my code:
declare lower;
input length = 10;
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
plot mydef = if lastBar - length < BarNumber() then
fold i = 0 to length - 1 do
(
(fold j = 0 to length with s = 0 do
s + Exp(-(Power(i - j, 2) / 128)))
)
else 0;
AddLabel(yes, "mydef: " +mydef, Color.CYAN);
AddLabel(yes, "mydef[1]: " + mydef[1], Color.CYAN);
AddLabel(yes, "mydef[2]: " + mydef[2], Color.CYAN);
AddLabel(yes, "mydef[3]: " + mydef[3], Color.CYAN);
AddLabel(yes, "mydef[4]: " + mydef[4], Color.CYAN);
AddLabel(yes, "mydef[5]: " + mydef[5], Color.CYAN);
AddLabel(yes, "mydef[6]: " + mydef[6], Color.CYAN);
AddLabel(yes, "mydef[7]: " + mydef[7], Color.CYAN);
AddLabel(yes, "mydef[8]: " + mydef[8], Color.CYAN);
AddLabel(yes, "mydef[9]: " + mydef[9], Color.CYAN);
All my values for mydef are 8.634157081
All loop values:
Need help coding the following scenario:
input length = 10;
I want to calculate Exp(-(Power(-i, 2) / 128)) for the last X bars
I would like to see in my last 10 bars the following values:
mydef = 8.173035134
mydef[1] = 8.634157081
mydef[2] = 8.996859656
mydef[3] = 9.247021397
mydef[4] = 9.374678698
mydef[5] = 9.374678698
mydef[6] = 9.247021397
mydef[7] = 8.996859656
mydef[8] = 8.634157081
mydef[9] = 8.173035134
I am trying to do a loop to get the first value of 8.173035134
counter result
0 1
-1 0.992217938
-2 0.969233234
-3 0.932102492
-4 0.882496903
-5 0.822577562
-6 0.754839602
-7 0.681940751
-8 0.60653066
-9 0.531095991
and so for
Can you tell me what I am doing wrong?
This is my code:
declare lower;
input length = 10;
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
plot mydef = if lastBar - length < BarNumber() then
fold i = 0 to length - 1 do
(
(fold j = 0 to length with s = 0 do
s + Exp(-(Power(i - j, 2) / 128)))
)
else 0;
AddLabel(yes, "mydef: " +mydef, Color.CYAN);
AddLabel(yes, "mydef[1]: " + mydef[1], Color.CYAN);
AddLabel(yes, "mydef[2]: " + mydef[2], Color.CYAN);
AddLabel(yes, "mydef[3]: " + mydef[3], Color.CYAN);
AddLabel(yes, "mydef[4]: " + mydef[4], Color.CYAN);
AddLabel(yes, "mydef[5]: " + mydef[5], Color.CYAN);
AddLabel(yes, "mydef[6]: " + mydef[6], Color.CYAN);
AddLabel(yes, "mydef[7]: " + mydef[7], Color.CYAN);
AddLabel(yes, "mydef[8]: " + mydef[8], Color.CYAN);
AddLabel(yes, "mydef[9]: " + mydef[9], Color.CYAN);
All my values for mydef are 8.634157081
All loop values:
loop 1 | loop 2 | result | Total | |
0 | 0 | 1 | ||
-1 | 0.992218 | |||
-2 | 0.969233 | |||
-3 | 0.932102 | |||
-4 | 0.882497 | |||
-5 | 0.822578 | |||
-6 | 0.75484 | |||
-7 | 0.681941 | |||
-8 | 0.606531 | |||
-9 | 0.531096 | 8.173035 | ||
1 | 1 | 0.992218 | ||
0 | 1 | |||
-1 | 0.992218 | |||
-2 | 0.969233 | |||
-3 | 0.932102 | |||
-4 | 0.882497 | |||
-5 | 0.822578 | |||
-6 | 0.75484 | |||
-7 | 0.681941 | |||
-8 | 0.606531 | 8.634157 | ||
2 | 2 | 0.969233 | ||
1 | 0.992218 | |||
0 | 1 | |||
-1 | 0.992218 | |||
-2 | 0.969233 | |||
-3 | 0.932102 | |||
-4 | 0.882497 | |||
-5 | 0.822578 | |||
-6 | 0.75484 | |||
-7 | 0.681941 | 8.99686 | ||
3 | 3 | 0.932102 | ||
2 | 0.969233 | |||
1 | 0.992218 | |||
0 | 1 | |||
-1 | 0.992218 | |||
-2 | 0.969233 | |||
-3 | 0.932102 | |||
-4 | 0.882497 | |||
-5 | 0.822578 | |||
-6 | 0.75484 | 9.247021 | ||
4 | 4 | 0.882497 | ||
3 | 0.932102 | |||
2 | 0.969233 | |||
1 | 0.992218 | |||
0 | 1 | |||
-1 | 0.992218 | |||
-2 | 0.969233 | |||
-3 | 0.932102 | |||
-4 | 0.882497 | |||
-5 | 0.822578 | 9.374679 | ||
5 | 5 | 0.822578 | ||
4 | 0.882497 | |||
3 | 0.932102 | |||
2 | 0.969233 | |||
1 | 0.992218 | |||
0 | 1 | |||
-1 | 0.992218 | |||
-2 | 0.969233 | |||
-3 | 0.932102 | |||
-4 | 0.882497 | 9.374679 | ||
6 | 6 | 0.75484 | ||
5 | 0.822578 | |||
4 | 0.882497 | |||
3 | 0.932102 | |||
2 | 0.969233 | |||
1 | 0.992218 | |||
0 | 1 | |||
-1 | 0.992218 | |||
-2 | 0.969233 | |||
-3 | 0.932102 | 9.247021 | ||
6 | 7 | 0.681941 | ||
6 | 0.75484 | |||
5 | 0.822578 | |||
4 | 0.882497 | |||
3 | 0.932102 | |||
2 | 0.969233 | |||
1 | 0.992218 | |||
0 | 1 | |||
-1 | 0.992218 | |||
-2 | 0.969233 | 8.99686 | ||
8 | 8 | 0.606531 | ||
7 | 0.681941 | |||
6 | 0.75484 | |||
5 | 0.822578 | |||
4 | 0.882497 | |||
3 | 0.932102 | |||
2 | 0.969233 | |||
1 | 0.992218 | |||
0 | 1 | |||
-1 | 0.992218 | 8.634157 | ||
9 | 9 | 0.531096 | ||
8 | 0.606531 | |||
7 | 0.681941 | |||
6 | 0.75484 | |||
5 | 0.822578 | |||
4 | 0.882497 | |||
3 | 0.932102 | |||
2 | 0.969233 | |||
1 | 0.992218 | |||
0 | 1 | 8.173035 |
Last edited: