indicator using a value from the data other than close
-
I believe most of the built in indicators are using close value from the data for computation, for example SMA indicator is using close values of all the bars to derive sma... (is this correct)
I have following 2 scenarios to build indicators- if I would like to force this to use say high values of the bar to compute the average, what would be the change.
- if I would like to use volume from the bar to compute volume average over a period, what would be the change.
appreciate any example if available.
-
@skytrading54 said in indicator using a value from the data other than close:
I believe most of the built in indicators are using close value from the data for computation, for example SMA indicator is using close values of all the bars to derive sma... (is this correct)
This is wrong. The
SMA
uses the value from the 1st line of the data feed passed to it. For regular data feeds containing prices this happens to be theclose
price because this is the de-facto industry standard.See this post from yesterday where you can see that you can pass anything which is a line to any indicator:
Just pass
self.data.high
orself.data.volume
to the indicator of your choice.The exception are indicators which rely on specific price points like the
Stochastic
which uses 3 of the for usual price components (high
,low
,close
... leavingopen
unused) -
@backtrader What about Fractals indicator? Actually it's under studies so idk if it works like an indicator. I'm trying to use it like Fractals(self.close) and it's not working.
-
You can create the indicator lines in the init section of your strategy then call them in next.
def __init__(self): self.mysma = bt.ind.SMA(self.datas[0].volume) def next(self): self.log(self.mysma[0])
-
@run-out I have no idea how this ended up in the wrong question.
-
@Wayne-Filkins said in indicator using a value from the data other than close:
I'm trying to use it like Fractals(self.close) and it's not working.
It requires
high
andlow
prices, therefore the whole data feed should be passed, not onlyclose
prices.