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

Same entry, different exits

  • Hey,

    this might be a bit hard to explain, but I would like to test a strategy with the same buying condition but with varying sellling conditions. Like sell when < 200ma or sell at first profit or after 7 days.

    Do anyone have a suggestion how to do that. Would I write different strategies for each one and then run them with a shell script to compare or could I modularize the exit-criteria somehow to not have so much duplicate code?

    I hope I could explain it in a good way.


  • If you don't want to put several strategies into the system, then you can write single strategy with exit type parameter. Based on this parameter you can run different pieces of code in the next() or __init__() based on if self.p.param == something statements.

  • I understand that sounds very reasonable of course.

    I'm thinking along these lines: I want to keep a bunch of "exits" in a folder somewhere and then I can combine the current entry with those exits. If this could be modularized I dont have to paste in 15 exits into each strategy class.

  • @oakenstream as an idea - setup separate class. Methods of the class will be your exit functions. Then you can pass these methods as parameters into strategy.

  • administrators

    With OOP the obvious approach is having a base class which defines the entry setup (invoked for example with method name check_and_enter.

    That same class defines the logic to call another method for the strategy, for example: check_and_exit.

    Subclasses of the base class have all the same entry method, but override and have different logics for the check_and_exit method.

  • Ok, thanks both! I will experiment with this approach.

Log in to reply