Draw line object block to represent calculation on screen
-
I would like to draw a line using the charts and objects blocks to represent the following calculation on the screen:
local i; local ii = Period; local LastPeriod; if period == source:size()-1 then LastPeriod = true; else LastPeriod = false; end while ii > 0 do if not(LastPeriod) then ii = 0; else ii = ii-1; end local Sum = 0; local SumW = (Period+2)*(Period+1)/2; for i=0,Period,1 do Sum = Sum + (Period-i+1) * source[period-i]; if Redraw then if i <= source:size()-1 - period and i > 0 then Sum = Sum + (Period-i+1) * source[period+i]; SumW = SumW + (Period-i+1); end end end Line[period] = Sum / SumW;How can I do this ?
Can you help me?Thank you
! -
Hi, i just need to know if an example exists to do it. Thank you for your answer.
-
I wish I were a programmer, but I'm not. If you can explain what you need without that code, I will glad to help you.

-
@l-andorrĂ Yes, of course, I'll explain how it works to get the expected result.
Example with a period of 10 (configurable).
The idea here is to apply a weighting coefficient to each encountered price as we go back in time. Then we'll manipulate this data to get our result.In this example, we go back to progressively gather all the prices to multiply them by a weighting coefficient until we reach the closing price 10 periods ago.
Objective = we're trying to determine the price of the current period.
Step 1
Determine each weighted price to add them up at the end.closing price of period-1 = 14973.54 * 1 = 14973.54
closing price of period-2 = 14934.54 * 2 = 29869.08
closing price of period-3 = 14919.04 * 3 = 44757.12
closing price of period-4 = 14919.03 * 4 = 59676.12
closing price of period-5 = 14933.02 * 5 = 74665.1
closing price of period-6 = 14935.03 * 6 = 89610.18
closing price of period-7 = 14958.52 * 7 = 104709.64
closing price of period-8 = 14,975.04 * 8 = 119800.32
closing price of period-9 = 14,974.52 * 9 = 134770.68
closing price of period-10 = 14,974.03 * 10 = 149740.3Sum of weighted prices = 822572.08
Step 2
Add up all the weighting coefficients as follows:
(1+2+3+4+5+6+7+8+9+10) = 55Step 3 = result = value of the price for the current period
822572.08 / 55 = 14955.85That's it, so if you could help me model this with the blocks, that would be great.
Thank you
! -
You can do that with a loop by using several blocks. However, I don't fully understand the math implied. Why are those close prices multiplied by those higher factors? Isn't it distorting the average value? I'm not good at math, though.

-
explica la lĂłgica amigo para entender, que representa ese calculo