I'm building an open-source robot trader framework.

Discussion in 'App Development' started by jbax, Dec 2, 2019.

  1. jbax

    jbax

    Here is the github link

    This framework allows anyone who can code a bit to build and test a strategy then run a trading robot. It even emails you every time a trade is made.

    Right now there is out-of-the-box support for Binance if anyone here is interested in crypto, but I built this to be extensible: implement 2 interfaces to integrate with another exchange or broker to trade stocks, forex or whatever instrument you want to trade. This is code you'd have to write regardless – e.g. to receive ticks or candles, submit a buy order, or update your trading account balance.

    I added some indicators to this framework, among them a few that I could not find anywhere in existing open source libraries (namely ConnorsRSI and Instantaneous trendline).

    There is a DirectionIndicator that I created myself which uses linear regression to predict what the next value in a sequence will be, so you can try to predict if a crossover will happen soon and act before most of the movement happens, or simply identify if a line is moving up or down.

    The readme shows a few examples and I hope you guys find it useful.

    Feel free to contribute if you can: suggestions, bugs or code are welcome. I plan to add way more indicators there over time.

    Cheers!
     
  2. gaussian

    gaussian

    Oh look another framework.
     
    MrKJoe likes this.
  3. jbax

    jbax

    "Another?" I couldn't find anything worth the time. Most are collections of technical indicators with poor to no support for proper backtesting. Nothing that helps you manage a candlestick database. Nothing that can easily be moved from testing to trading live.

    Please help me and everyone else with suggestions of open-source frameworks that aim to do the same thing that this one does.
     
    MrKJoe likes this.
  4. Hey, I'm all for new frameworks if it helps you trade. I'm not interested in using your framework, but I would look at it for ideas to steal.

    In this code here, where does boll1h and boll5m get their data? It looks magical, which would scare me.

    Code:
    public Signal getSignal(Candle candle) {   
      //price jumped below lower band on the 1 hour time frame
      if (candle.high < boll1h.getLowerBand()) {   
       //on the 5 minute time frame, the lowest price of the candle is above the lower band.
       if (candle.low > boll5m.getLowerBand()) {           
        //still on the 5 minute time frame, the close price of the candle is under the middle band
        if (candle.close < boll5m.getMiddleBand()) {
         // if the slope of the 5 minute bollinger band is starting to point up, BUY
         if (boll5m.movingUp()) {
          return Signal.BUY;
         }
        }
       }
      }
                                                 
      //candle hitting the upper band on the 1 hour time frame
      if (candle.high > boll1h.getUpperBand()) { 
       //on the 5 minute time frame, the lowest price of the candle is under the middle band
       if (candle.low < boll5m.getMiddleBand()) {
        //if the slope of the 5 minute bollinger band is starting to point down, SELL
        if (boll5m.movingDown()) {
         return Signal.SELL;
        }
       }
      }
      return Signal.NEUTRAL;
    }
    }
    
     
    MrKJoe likes this.
  5. jbax

    jbax

    Not magic, but great to know, as the purpose of the framework is to relieve programmers of the bulk of the work.

    In that example the candles are coming from the database, but could very well be coming from a live exchange (no changes required to that code).

    From top to bottom:

    Code:
    +- MarketSimulator.run() //loads the candles from the database and passes them one by one to the engine responsible for trading a given symbol.
    | //It has a "clock" that will tick every "x" amount of time so that the candles available within that time period are sent down for processing.
    | //This is done like this because some symbols may not have data at a given point in time).
    |
    +- Engine.process(candle) // will send every candle received from the history or live environment to all strategies that consume candles
    |
    +- IndicatorGroup.accumulate(candle) // will iterate over all indicators to call indicator.accumulate(candle)
    |
    +- ExampleStrategy.getSignal(candle) // this is the method you mentioned (ExampleStrategy extends from IndicatorGroup, above).
    
    When trading live, the only thing that changes is the first step. The candles will come from from an implementation of the `Exchange` interface, which is basically a connector to the live thing.

    Hope this helps
     
    MrKJoe likes this.
  6. gaussian

    gaussian

    What language? There are about 10 different frameworks of varying quality. If you want easy I am pretty sure NinjaTrader, and other EasyLanguage based platforms fully support your feature set. Your feature set is not unique:

    You may have a corner on the Java market because most Java enterprise programmers work on internal tools to do the same thing. In terms of feature set though, nearly every popular Python framework supports this feature set (with faster iteration time - bolting on email is trivial from Python and you can likely just pass it on to `sendmail` without needing a library), C# has a handful of them (Lean being the most popular) as well, QuantMod for R is pretty close with a little fudging needed, and MATLAB comes with a full suite of fully customizable tools. The market you are catering to is almost fully served by Python. Once a strategy is developed, it's ported to a better language - C# being very popular in this sector but C++ is still used in industry. As a result, the public favors rapid iteration over anything else because the original strategy code will be rewritten and thrown out as soon as it's at go-to-market. I can't name a single trader that would trust a guy on the internet to execute their orders through a framework they have no control over and haven't audited (this is why there are far more backtesting frameworks than trading frameworks).

    This project is basically taken on by every person new to the industry. A new trading framework is released just about every day because broker APIs are getting so refined it takes almost nothing to build your own. Congratulations on your stars (247 is a lot for a Java project in this area). Most people write their own, myself included. I've yet to find a trading framework that gives me what I need without a car's weight worth of other cruft I don't need.

    Also I really, really dislike it when people's first post is shilling their own garbage.
     
    Last edited: Dec 3, 2019
    peaspipe, .sigma and MrKJoe like this.
  7. The reason it looks weird to me is you have a piece of code that takes in a candle, but then presumably the Bollinger bands use that same candle from a separate place. That seems like duplication of data which always has the potential for a bug.

    Suggestions to change it, if you were so inclined. I would expect something like:

    Code:
    public Signal getSignal(Candle candle) {   
       boll1h.update(candle);
       boll5m.update(candle);
       ...
    }
    
    Then it would make sense to me. Take a look at how backtrader does it. It's a little magical, but not too magical. Though it's definitely Python magical.
     
  8. jbax

    jbax

    Incoming candles might be real time ticks or anything else. In the example above they are 1 minute candles.

    Internally the indicators have an 'Aggregator' for the time the indicator is looking into. So boll1h merges all incoming candles/ticks into an internal candle until it closes 1 hour, that "final" 1 hour candle is used to calculate the value of the 1 hour bollinger band, and then the next 1 hour candle starts to be filled.

    Same principle applies to the boll5m aggregates incoming ticks/candles into a 5 minute candle which is used to calculate the value of the 5 minute bollinger band.

    The main idea of this framework is to allow you to work with multiple time scales at the same time. Every framework I saw out there is fixed to the same time scale and merging signals from different time scales is either hard or impossible.
     
    SteveH and expiated like this.
  9. Got it. OK I would just make sure that is clear in your docs (I may have missed it.) Looks like you've got practical use for it, but crypto? Really? Come on man. Counter party risk is ridiculous.
     
  10. jbax

    jbax

    It's not specific for crypto. The idea is that any broker/exchange for any sort of instrument can work with this. I personally trade with binance and created a connector for it (again, just implement 2 interfaces and it should work for your broker of preference).

    Thanks for the suggestions on the documentation, I'll make sure to mention that. It's still a work in progress.
     
    #10     Dec 3, 2019