Navigation

    Backtrader Community

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

    RandomTrader88

    @RandomTrader88

    0
    Reputation
    18
    Profile views
    7
    Posts
    1
    Followers
    0
    Following
    Joined Last Online

    RandomTrader88 Unfollow Follow

    Latest posts made by RandomTrader88

    • RE: Stop orders are generating Margin error

      I found a solution...

      cerebro.broker.set_checksubmit(checksubmit=False)

      posted in General Code/Help
      R
      RandomTrader88
    • Stop orders are generating Margin error

      Lets say that i have $1000 in cash and I want to short a stock that is currently at trading at 90. i want to short at 100 and stop loss at 110 if the trade goes against me (just an example).

      I set the following trade:

      1. limit order to sell 10 stocks at 100.
      2. limit stop order to buy 10 stocks at 110.

      if this trade goes against me, i should lose $100 and have $900 cash remaining.

      BUT when i send these orders to backtrader, I get margin error (order.status == order.Margin) on the stop loss because the engine is thinking that i will need $1100 in order to buy 10 stocks at 110...
      I know that until the price will hit the stop loss, i will have more cash from short selling... but the program cant calculate it and returns an error...

      What is the right way to solve it?
      how can i set stop loss, without getting margin called on me?

      posted in General Code/Help
      R
      RandomTrader88
    • Indicators logarithmic y-scale

      Is it possible to plot a subplot indicator y-scale as logarithmic?

      At https://www.backtrader.com/docu/induse/#controlling-plotting there is no plotlog variable. I also tried it and there is no such variable for indicators.

      posted in Indicators/Strategies/Analyzers
      R
      RandomTrader88
    • RE: cerebro.plot() error

      anybody was able to solve it without installing older version of mathplotlib? maybe it should be an issue on backtrader.

      i have the newest version, and it crashes with the same error ("MemoryError: Unable to allocate 70.8 GiB") only when there was no buy/sell, for example if i don't add any strategy or the strategy did not create a buy/sell order.

      posted in General Discussion
      R
      RandomTrader88
    • RE: Custom Labels/Indicator with events from a strategy

      OK i found a solution
      Observer can access the strategy using self._owner so we can do the following:

      in the Observer, we listen to anything inside an self._owner.events array (i just made up the name .events):

      def next(self):
          while len(self._owner.events)>0:
              event,value = self._owner.events.pop(0)
              getattr(self.lines,event)[0]=value
      

      and in the Strategy, we just send events:

      def __init__(self):
          self.events=[]
      
      if (CONDITION):
          self.events.append(["event_x",1])
      

      Note that event_x must be the name of a line defined in the observer.

      posted in Indicators/Strategies/Analyzers
      R
      RandomTrader88
    • RE: Custom Labels/Indicator with events from a strategy

      Thanks, i see that observers can display events like buys/sells. But how do i signal into an observer from the strategy itself? how can i code something like this?

      if (condition):
         myobserver.event1[0]=1 #change value in the observer somehow
      

      is it possible to do so from the strategy?
      I don't want to duplicate the entire if-logic to the observer just to display a value.

      I will also mention that i do see a specific case that it is possible: in the Observers example i see the OrderObserver that displays information about orders, but it is only because the strategy generates orders and the observer catches them using the next() function. but what about just any events, without generating orders? just generating the event from the strategy?

      posted in Indicators/Strategies/Analyzers
      R
      RandomTrader88
    • Custom Labels/Indicator with events from a strategy

      I developed a strategy, and i would like to visually view specific "events". The logic of determining the events can be found in the strategy. in other words: In the strategy i have all the if statements in order to determine the exact time that i want to see this event on the graph.

      Is it possible to add labels on bars, from the strategy?

      Alternatively, and this is not so pretty solution but it will work, i think about developing a custom indicator and change it from 0 to 1 for just 1 bar when this event occurs, but i'm not sure how to do it from the strategy itself (i don't want to duplicate the entire logic of the strategy to a new indicator)

      How can i do that?
      Do you have any code sample for that?

      posted in Indicators/Strategies/Analyzers
      R
      RandomTrader88