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

Separate datas for indicator/strategy



  • Hi,
    so confused how to implement:

    1. Strategy A uses indicator B for sell/buy orders.
    2. Indicator B has 1 day timeframe data.
    3. Strategy A should keep 1 minute timeframe for triggering Stop orders.

    Already broke my head :)

    Any ideas?



  • @aero108 said in Separate datas for indicator/strategy:

    Strategy A uses indicator B for sell/buy orders.

    There is no problem here.. Or I am not understating it.

    @aero108 said in Separate datas for indicator/strategy:

    Indicator B has 1 day timeframe data.

    Just read 1 min data and resample to Day TimeFrame

    @aero108 said in Separate datas for indicator/strategy:

    Strategy A should keep 1 minute timeframe for triggering Stop orders.

    You can use data baed order.. for example
    self.order ( data=self.datas[0] )



  • There is no problem here.. Or I am not understating it.

    ofc itsn't a problem, it's just a condition.

    Just read 1 min data and resample to Day TimeFrame

    and what I'll achieve with resample? Indicator uses Daily TF but how cerebro will know to follow 1 min data to process Stop orders created based on Daily indicator signals ?



  • @aero108

    Since you mentioned that you want the stop loss to be on 1 min data I assume you have 1 min data to feed in to BT. Its not necessary that one need to resample.. YOU can also input data in day timeframe in addition to 1 min data.

    data = 1min data 
    cerebro.adddata( data ) ## this would self.datas[0]
    cerebro.resampledata(data0, timeframe = bt.TimeFrame.Days, compression = 1)  # this would be self.datas[1]
    
    class TestStrategy(bt.Strategy):
        def __init__(self):
    
            indicatorB = bt.ind.xx(self.datas[1]) # calculate your indicator on Timeframe day 
    
        def next(self):
            if self.datas[1].close[0] > indicatorB :
                 self.buy ( data=self.datas[1] )  # buy order based on day timeframe 
    
            if close < stop.loss :
                 self.close ( data=self.datas[0] )  # stop loss order based in 1 min data 
    
    

    Hope this clears your confusions..



  • @aero108 said in Separate datas for indicator/strategy:

    and what I'll achieve with resample?

    with resample you will get 2nd data feed.

    @aero108 said in Separate datas for indicator/strategy:

    Indicator uses Daily TF but how cerebro will know to follow 1 min data to process Stop orders created based on Daily indicator signals ?

    for orders you will use 1st minute data feed, and for indicator you will use 2nd daily data feed. this way cerebro will know everything it should know. how to pass data feeds into orders and examples is defined in the backtraders docs.



  • @aero108 said in Separate datas for indicator/strategy:

    Any ideas?

    the most evident idea is to read the docs to avoid breaking head.


Log in to reply
 

});