Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    bracket order code example

    General Discussion
    2
    3
    862
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      siavash last edited by siavash

      I am coding a strategy using bracket order and have the following questions :

      1.I am using bracket order example code, bracket order, but when I change the stop and profit limits(p2 and p3) such as they are out of range , for example p2=800, It does orders without issuing any error??!!!

      2.when does the self.position condition get True(being in the market)? I checked this several times, but it doesn't get True at all.

      if not self.position:
      ...
      else:  # in the market
                  if (len(self) - self.holdstart) >= self.p.hold:
                      pass  # do nothing in this case
      

      3.I am using data having 200 length. When It ends and plots, some trades are not shown as colored(green and red triangles) triangles.

      1. is there any method to apply trailing stop in bracket orders?
      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @siavash last edited by

        @siavash said in bracket order code example:

        1.I am using bracket order example code, bracket order, but when I change the stop and profit limits(p2 and p3) such as they are out of range , for example p2=800, It does orders without issuing any error??!!!

        Why is p2=800 out of range? What is the range? Which error are you expecting?

        @siavash said in bracket order code example:

        2.when does the self.position condition get True(being in the market)? I checked this several times, but it doesn't get True at all.

        self.position references a position open for self.data (or self.datas[0], which is the first data feed introduced in the system). If it isn't True, you haven't opened a position.

        @siavash said in bracket order code example:

        1. .I am using data having 200 length. When It ends and plots, some trades are not shown as colored(green and red triangles) triangles

        Unless you give as a chart and the operations log, not much can be said.

        @siavash said in bracket order code example:

        1. is there any method to apply trailing stop in bracket orders?

        That you use a StopTrail or StopTrailLimit order.

        1 Reply Last reply Reply Quote 0
        • S
          siavash last edited by

          Thank you for your reply , but i haven't still got my answer for question 2,3 and 4:

          2.when does the self.position condition get True(being in the market)? I checked this several times, but it doesn't get True at all.

          I want do some calculation when there was an opened order. I put the code print('????????????') in this section, but it does not run at all.This is exactly bracket order example code adding print bookmark code:

            else:  # in the market
                      print('???????????????????????????????????')
                      if (len(self) - self.holdstart) >= self.p.hold:
                          pass  # do nothing in this case
          

          3.I am using data having 200 length. When It ends and plots, some trades are not shown as colored(green and red triangles) triangles.

          This is the requested plot.For example, there is no trade mark for first trade.![alt text](image0_1531926316843_Figure_0.png url)

          4.is there any method to apply trailing stop in bracket orders?

          How can I use StopTrail or StopTrailLimit order inside the bracket order? is there any docs or example?

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors