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

limit close order syntax..



  • Hello!

    This is the code I'm playing with:

    def next(self):
        if not self.position:  # not in the market
            if self.crossover > 0:  # if fast crosses slow to the upside
                self.buy()  # enter long
        elif self.crossover < 0:  # in the market & cross to the downside
            self.close()  # close long position
    

    It enters a long position on SMA crossover and closes it out if we cross under.

    I'd like to modify so that once I enter a position, it automatically creates a limit close order at say, +25% of the fill price.

    So after self.buy() at a crossover at $100 a share, for example. I want immediately to submit a limit close for $125 to be executed if/when the price reaches that point.

    Any feedback would be appreciated, I'm awful at python but working hard at being less so, but the existing documentation isnt sinking in for me yet.



  • Get entry order execution price from the notify_order(), use it to calculate your limit order price and issue the limit order right in the notify_order() or in the next().



  • To add to @ab_trader great answer, you can get the order execution price in notifiy_order using:

    order.executed.price
    

Log in to reply
 

});