For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Peak indicator, logic within __init__ or next()?

  • I am creating an indicator that finds the highest price value during a period at which the price remains above a moving average. i.e when price crosses above MA line, create start point for range. when price crosses below MA line, create end point for range. Then find highest value within range, find index and create peak signal at this point.

    i have completed this with in the next() part of an indicator which makes logical sense to me however I would like to know if it is possible to create a more elegant solution from with in __ init __? As this seems to be achievable with most indicators I have had a look at.

    Not looking for code to be written for me simply a push in the right direction logic wise.

    Thank You

  • administrators

    Indicators can be created in a declarative manner in __init__ when all operations can be done with standard operators and functions overridden (or with a given substitute when the language does not allow to override) by backtrader

  • This post helps clear some things up for me however i'm still struggling with one thing in particular. How would I go about dynamically changing the period from which to find the max value?

    Ultimately whilst signal is 1 find max until signal is 0 then repeat. I may just not be able to rap my head around it properly but i cant see how this can be done in a declarative manner?

    Thank you for the quick response

Log in to reply