Newbie_789456
New member
Hi Everyone,
have this code for DSS below (N.B it is a lower study):
def divisor = ExpAverage(ExpAverage(Highest(high, length) - Lowest(low, length), s_length), r_length);
def DSS = if divisor == 0 then 0 else 100 * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor;
for simplicity, we assume divisor !=0
I am trying to leverage that code to determine the value for "close" that will make the following equation equal to 80 for example?
100 * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor = 80
It is an algebra problem as much as it is coding, but because of the multiple/embedded ExpAverage() I am really struggling.
given:
DSS= 100 * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor;
where:
input s_length = 5;
input length = 10;
input bottom_line = 20;
input middle_line = 50;
input top_line = 80;
def r_alpha = 2 / (r_length + 1);
def s_alpha = 2 / (s_length + 1);
I am trying to solve the equation DSS = top_line
i.e. what value of variable "close" will make the above true.
Here is the ToS definition of ExpAverage for reference:
The formula for the calculation of the exponential moving average is recursively defined as follows:
EMA1 = price1;
EMA2 = α*price2 + (1 - α)*EMA1;
EMA3 = α*price3 + (1 - α)*EMA2;
EMAN = α*priceN + (1 - α)*EMAN-1;
where α is a smoothing coefficient equal to 2/(length + 1).
So I attempted to break down the ExpAverages formula in order to isolate "close"..
Here are the first steps for reference:
100 * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor = top_line
ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor = (top_line/100)
ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) = (top_line/100)*divisor
(r_alpha)* (ExpAverage(close - Lowest(low , length), s_length))+ (1-r_alpha)* ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) [1] = (top_line/100)*divisor
.......
The closest I got was the code below, but it is still not correct.
price at which DSS is equal to Top_Line = ((((((Top_Line / 100) * divisor) - ((1 - r_alpha) * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length)[1])) / r_alpha) - ( 1 - s_alpha) * ExpAverage(close - Lowest(low , length), s_length)) / s_alpha) + Lowest(low , length);
At the end of the day, I am trying to determine historically on the chart what was the price value in each bar in the top graph, that would have made DSS = top_line in the lower graph.. so that if the high of a candle in the top graph was equal or above that price value, I know that DSS would have touched the top_line in the lower graph..
Any help would be much appreciated. Even if it is just spotting an error I don't see...
Many thanks in advance!
have this code for DSS below (N.B it is a lower study):
def divisor = ExpAverage(ExpAverage(Highest(high, length) - Lowest(low, length), s_length), r_length);
def DSS = if divisor == 0 then 0 else 100 * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor;
for simplicity, we assume divisor !=0
I am trying to leverage that code to determine the value for "close" that will make the following equation equal to 80 for example?
100 * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor = 80
It is an algebra problem as much as it is coding, but because of the multiple/embedded ExpAverage() I am really struggling.
given:
DSS= 100 * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor;
where:
input s_length = 5;
input length = 10;
input bottom_line = 20;
input middle_line = 50;
input top_line = 80;
def r_alpha = 2 / (r_length + 1);
def s_alpha = 2 / (s_length + 1);
I am trying to solve the equation DSS = top_line
i.e. what value of variable "close" will make the above true.
Here is the ToS definition of ExpAverage for reference:
The formula for the calculation of the exponential moving average is recursively defined as follows:
EMA1 = price1;
EMA2 = α*price2 + (1 - α)*EMA1;
EMA3 = α*price3 + (1 - α)*EMA2;
EMAN = α*priceN + (1 - α)*EMAN-1;
where α is a smoothing coefficient equal to 2/(length + 1).
So I attempted to break down the ExpAverages formula in order to isolate "close"..
Here are the first steps for reference:
100 * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor = top_line
ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) / divisor = (top_line/100)
ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) = (top_line/100)*divisor
(r_alpha)* (ExpAverage(close - Lowest(low , length), s_length))+ (1-r_alpha)* ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length) [1] = (top_line/100)*divisor
.......
The closest I got was the code below, but it is still not correct.
price at which DSS is equal to Top_Line = ((((((Top_Line / 100) * divisor) - ((1 - r_alpha) * ExpAverage(ExpAverage(close - Lowest(low , length), s_length), r_length)[1])) / r_alpha) - ( 1 - s_alpha) * ExpAverage(close - Lowest(low , length), s_length)) / s_alpha) + Lowest(low , length);
At the end of the day, I am trying to determine historically on the chart what was the price value in each bar in the top graph, that would have made DSS = top_line in the lower graph.. so that if the high of a candle in the top graph was equal or above that price value, I know that DSS would have touched the top_line in the lower graph..
Any help would be much appreciated. Even if it is just spotting an error I don't see...
Many thanks in advance!