How to find data of wma at the open position?

Viewed 80

I have this plot:

WMA_point = wma(close, 9)

plot(WMA_point, title='WMA', color=#000000)

It makes a line on the chart. When the price goes up, the line moves up, and vice versa, when the price goes down, it moves down.

I know that it depends on the "close" data.

I would like to find the price data of this wma when (close == open)

EDIT:

I mean: I want to get the first data of the close line wma(close, 9), when the new candle appears, when the (close == open) . I dont need the data of the open line wma(open, 9)

3 Answers

Try using open as your source:

WMA_point = wma(open, 9)

plot(WMA_point, title='WMA', color=#000000)

Cheers, and best of luck with your trading and coding

So, you need to store the price in a var when your condition is true.

var float p = na
WMA_point = wma(close, 9)

if (open == close)
    p := WMA_point  // This will have the wma value of the last time open == close

plot(WMA_point, title='WMA', color=#000000)

You can either use WMA_point[1], which is generally where the price value of the current bar will open at. If you want to take into consideration gapping, you'll need to calculate the wma using n-1 historical close values and with the nth value the current bar's open.

//@version=5
indicator("wma open", overlay = true)

len = input.int(10)
     
float wtd_close_sum = 0.0
int denom = 0

for i = 1 to len - 1
    wt = len - i
    wtd_close_sum += close[i] * wt
    denom += wt

wtd_close_sum += open * len
denom += len

wma_open = wtd_close_sum / denom

plot(wma_open)

as a function :

f_wma_open(_open, _close, _len) =>
    float _wtd_close_sum = 0.0
    int _denom = 0

    for i = 1 to _len - 1
        _wt = _len - i
        _wtd_close_sum += _close[i] * _wt
        _denom += _wt

    _wtd_close_sum += _open * _len
    _denom += _len

    _wma_open = _wtd_close_sum / _denom
    _wma_open
Related