Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. ciceron
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 3
    • Best 0
    • Groups 0

    ciceron

    @ciceron

    0
    Reputation
    91
    Profile views
    3
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    ciceron Unfollow Follow

    Latest posts made by ciceron

    • RE: STOP TRAIL order questions.

      @nikolai Hi Nikolai, Thanks for the answer, the OANDA API I used before come from oandapyV20, the original oanda v20 also support trailing stop.

      [from oandapyV20.contrib.requests import PositionCloseRequest, MarketOrderRequest, TrailingStopLossDetails](https://oanda-api-v20.readthedocs.io/en/latest/contrib/orders/marketorderrequest.html)
      

      What confused me is in oandapyv20, if I open a market order with a trailing stop loss, I just need one command:

      mktOrder = MarketOrderRequest(instrument=instruments, units=units, trailingStopLossOnFill=trailingStopLossOnFill.data)
      

      But in backtrader, if I want to do the same thing I need to open two order:

      self.buy(size=1)
      self.sell(size=1, exectype=bt.Order.StopTrail, price=10.50, trailpercent=0.0.02)
      

      Is my understanding correct?
      Best
      Ciceron

      posted in General Discussion
      ciceron
      ciceron
    • RE: STOP TRAIL order questions.

      Is above understanding correct?

      posted in General Discussion
      ciceron
      ciceron
    • STOP TRAIL order questions.

      Hi all,

      First, thanks for all the contributors' work on Backtrader project, this is a very nice framework compare with what I used before.

      I have a question with the build in stop trail order. I use OANDA api before, maybe this influence my understanding on STOP Orders.

      In OANDA, when I pose a buy market order with trailing stop, the order will be executed as soon. Then if the price go down in a certain percent, then a sell market order active. If price go up, the order will keep trailing.

          mktOrder = MarketOrderRequest(instrument=instruments, units=units, trailingStopLossOnFill=trailingStopLossOnFill.data)
      
      • Question 1
      self.order = self.buy(exectype=bt.Order.StopTrail, trailpercent=self.p.trailingPercent, valid = valid1)
      

      After investigate the API doc of backtrader, in my understanding (if correct), the above buy order with a stop trail type means the order will be actived as market order once the price go up exceed a certain percent = self.p.trailingPercent, within time delta = valid1. And if the price go down within valid time, the buy order won't be executed. Once the order exceed valid time, this order will be cancelled.

      • Question 3
        To achieve what OANDA API do. In backtrader, I need to pose a buy order, and then pose a sell stop trail order (as the example below):
      self.buy(size=1)
      self.sell(size=1, exectype=bt.Order.StopTrail, price=10.50, trailpercent=0.0.02)
      
      • Question 4
        If I do this,
      if not self.position:
           if Signal = buy_signal:
                self.order = self.buy(exectype=bt.Order.StopTrail, trailpercent=self.p.trailingPercent, valid = valid1)
      else:
           if Signal = sell_signal:
                self.order = self.close()
      

      This means,
      If we have a buy signal, we pose a buy trail stop order in the market. Then,

      • a: if the price continue go up to a certain threshold, a buy market order will be posed. Once the buy order active, we wait for sell signal to close the position.

      • b: if the price continue go down, the buy order won't become market buy until exceed time threshold valid1, the order will be cancelled.

      • c: During the price going down period, the trail price will be updated.

      Thanks,
      Ciceron

      posted in General Discussion
      ciceron
      ciceron