Just sharing some Sunday hacking fun - a framework for building and testing signals which tracks and manages each signal as a trade; closing out the contract for each separately. 

In this example I've made it a "support and resistance" signal - when there are whole numbers that provide a psychological resistance on growth or support on falling. I coded it up 2 months ago and then left it since March 7th and it's OK in the rebound.  

This is intended to help those seeking help "tracking trades". With LEAN you can build any style of strategy. The key concept I'd recommend taking away here is a strong separation of concerns - pull apart the parts of your code into classes and it makes the algorithms very tidy and easy to evolve your strategy. In this case, we've made a TradeManagement class to track each "trade".

  • TradeManagement - tracking positions for PnL and exiting when near expiry.
  • Levels - our signal file in this scaffold; providing the direction to trade.
  • Main - just using trade/levels to orchestrate the strategy. 

Author