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

How to implement custom indicator ?



  • Hello,
    First of all, I want to create code which use ccxt to get OHLCV from exchange. Then it will calculate anomaly volume score for each line. However, I don't know how to implement anomaly volume score column. Can you tell me the right way to do that ? I will save all info to csv and add new column (anomaly volume score) then read all again ?

    Thank you very much :)



  • You will have a data feed from the exchange. Develop your own indicator which will calculate whatever you want, no need to save csv and re-read it again. Also remember that data feed is passed to indicator by default, no need to use params for it.

    Docs - Indicator Development



  • @ab_trader Thank you :). Now I understand how backtrader work



  • @ab_trader Hi,
    i am stuck at developing custom indicator.
    For example:
    My data feed is:

    Date,Time,Symbol,Vol
    01/03/16,23:43:11,BTC/USD,1
    01/03/16,23:43:27,BTC/USD,2
    01/03/16,23:49:19,BTC/USD,10
    

    The Vol_score method which help to calculate volume score. The output is:

    Date,Time,Symbol,Vol,Vol_Score
    01/03/16,23:43:11,BTC/USD,1, 0.1
    01/03/16,23:43:27,BTC/USD,2, 0.2
    01/03/16,23:49:19,BTC/USD,10, 2.1
    

    So, because this method return a list. So, I don't know how to implement this custom indicator. Can you give me advice, please ? Thank you :)



  • From the document linked above by @ab_trader

    class DummyInd(bt.Indicator):
        lines = ('dummyline',)
    
        params = (('value', 5),)
    
        def next(self):
            self.lines.dummyline[0] = max(0.0, self.params.value)
    

    You need to put your Vol_Score at index 0 of the line you define as output.