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

Create orders from CSV file



  • Hi,

    I have an external strategy that has already created my orders which have date/time stamps and order sizes.

    I would like to:

    1. import these orders and test against OHLC data that I have in CSV files
    2. use backtrader to optimise with different stop and limit values
    3. if possible test with trailing stops
    4. if possible implement a mechanism that has a "trailing start" - where I monitor the status of the last closing bar and decide whether or not execute the order in this CSV file.

    could somebody kindly tell me which of the above is possible with backtrader, and if possible, advise on how to implement?


  • administrators

    @j45p41 said in Create orders from CSV file:

    1. import these orders and test against OHLC data that I have in CSV files

    Yes for sure. See: Blog - Evaluating external historical performance

    1. use backtrader to optimise with different stop and limit values

    You have to switch from historical order evaluation to reading the orders, implementing them as either a data feed or an indicator and use the data points to trigger your orders. This is something that some users have apparently done in the past.

    The data feeds are extensible with new lines, but you may choose to use the existing OHLC fields to code information. This can be as easy as to put this into a GenericCSVData. See Docs - Datafeeds Reference

    In the case of indicators, you would define the lines and then read values from the defined lines

    1. if possible test with trailing stops

    Yes. And Trailing stops with limits and with the trailing amount being an absolute value or a percentage value

    1. if possible implement a mechanism that has a "trailing start" - where I monitor the status of the last closing bar and decide whether or not execute the order in this CSV file.

    Unsure about what you mean. You can always monitor the status of the last closing bar and decide whether to issue the order which is signaled via the data feed or indicator, as pointed out above.



  • @backtrader great! And thank you. Can’t wait to get stuck into this in the morning!