A free tool i just build to find algorithmic strategies

Discussion in 'App Development' started by Colleague, Aug 1, 2020.

  1. Colleague

    Colleague

    Hi all,

    so i continue my unemployment side project work :D

    Its a web tool so a browser i all you need
    http://algostrategies.io/

    [edit: i would not use it on your phone]

    Everything runs in your browser so you dont even have to be on the internet (once the page is loaded).

    The idea is that you provide some of your data and through some magic it will find patterns that predict some movement for the next bar.
    NOTE: you will find some data there already

    It basically tries all sort of combinations of comparisons of last high/low/close values including some MA and highest high and lowest low.

    Such a combination is used as a condition which once fulfilled will trigger a trade.
    There can be many conditions, but obviously more may lead to overfitting.
    Also the algorithm tries to find strategies with less conditions (basically a strategy with more conditions needs to have a better results then a strategy with less conditions).

    A trade = 1 bar (so the profit or loss is the difference of open to close)

    The stats do not take fees into account

    The produced code is in MQL4, i am happy to implement code creation for more platforms if there is demand from you guys.

    I tried it for couple markets, TBH it is better on higher time frames. It may happen that it wont find anything (that may be fine if the market is very effective).

    If you choose a high worker count / parallelism your CPU will do overtime.

    perhaps that is all for now

    AMA and feel free to make suggestions or obviously report bugs.
    I have also a patreon account if this tool has value for you by any chance.
     
    Last edited: Aug 1, 2020
  2. cool. i did similar thing in 2006. i bought 20 dell precisions to calculate trillions upon trillions of combinations
     
    userque likes this.
  3. Colleague

    Colleague

    oh wow what an investment, did it pay off ?
     
  4. Sure. I found a strategy in use till today.
     
    userque and Colleague like this.
  5. Colleague

    Colleague

    -> to clarify the strategy picks, the fitness values is profit "factor * √# of trades * complexity penalisation" and strategies are picked based on that value and also based on similarity to already picked strategies (to have a diverse collection)
     
  6. Colleague

    Colleague

    someone asked privately:

    >Hey, I just wanted to know if you are planning to release the sourcecode to your website. Or just a general outline how you are generating and testing those strategies. Would be highly appreciated :)

    answer:

    hi, i wasnt really thinking about releasing the code.
    First its not very nice code (i am not that proud of it, even when i am proud of the results)
    Second its written in Scala and that is not a very popular language, the implementation itself is also not easy.

    To answer your question, for the most part i am making combinations of 2 prices. The price can be last High/Low/Open/Close/various MA/highest high/lowest low. so i have a combination of 2 prices.
    Such a combination is basically a condition so price 1 is higher or lower than price 2. The condition is not so completely plain, and i am counting the differences between the 2 prices so that i can find some value for which the condition is true in half of the time.
    like high_1 > high_2 + x // so that this is true in 50% of time its a bit more complicated but whatever.
    Now all such conditions will become strategies to evaluate. After that some (like 5) are taken into the next generation and will be extended with new conditions (so there will be strategies with more then 1 condition) or conditions get shifted a bit etc.
     
    ph1l and userque like this.
  7. userque

    userque

    Can you show backtest results for your best strategy discovered so far. (Or actual results.)
     
  8. ph1l

    ph1l


    This type of rule sounds like something Price Action Lab (https://www.priceactionlab.com/) generates as in
    http://systemtradersuccess.com/curve-fitting-and-optimization
    My experience with rules like these (created by genetic programming in my case) is they don't hold up too well in the future.
     
  9. Colleague

    Colleague

    sure lets do an example strategy

    So i searched for a strategy on VIX week data (which is part of the predefined data sets)
    I searched for a Long strategy with only 1 condition (so its super simple and not overfit)
    I used 100% of the data to find the strategies

    the VIX week dataset has 544 bars
    The best strategy (after 10 cycles):
    PF 1.8
    trades 233

    in app graph
    Screenshot 2020-08-05 at 12.52.13.png

    the code
    Code:
    int OnInit()
    {
      return(INIT_SUCCEEDED);
    }
    
    void OnDeinit(const int reason)
    {
    }
    
    double getHighLowDiff_1() {
      return iHigh(NULL, PERIOD_W1, 1) - iLow(NULL, PERIOD_W1, 1);
    }
    
    
    
    double getClose_1() {
      return iClose(NULL, PERIOD_W1, 1);
    }
    
    
    
    double getAvgPriceLow_50_2() {
      return iMA(NULL, PERIOD_W1, 50, 0, 0, PRICE_LOW, 2);
    }
    
    
    
    double getCondition_0() {
      // PriceDiffThenPrevPrice(Close,AvgPriceLow(50),-0.07975,false,1,0.455078125)
    
      double diff = getClose_1() - getAvgPriceLow_50_2();
      double hl = getHighLowDiff_1();
    
      if(hl == 0){
        return false;
      } else {
        double diffP = diff / hl;
    
        return diffP < -0.07975;
      }
    
    }
    
    
    bool isLong()
    {
       for(int i = 0; i < OrdersTotal(); i++)
       {
          if(OrderSelect(i, SELECT_BY_POS))
          {
             if(OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP)
             {
                return true;
             }
          }
       }
       return false;
    }
    
    
    void makeOrder()
    {
      
      double level = Ask;
    
    
       OrderSend(Symbol(), OP_BUY, 1, NormalizeDouble(level, Digits), 0,0,0);
    }
    
    
    void closeLong()
    {
       for(int i = 0; i < OrdersTotal(); i++)
       {
          if(OrderSelect(i,SELECT_BY_POS))
          {
             if(OrderType() == OP_BUY)
             {
                int ticket = OrderTicket();
                double usedAmount = OrderLots();
                OrderClose(ticket, usedAmount, Bid,1);
             }
          }
       }
    }
    
    
    void OnTick()
    {
    
      bool isTrade = isLong();
    
      bool shouldBeTrade = getCondition_0();
    
      if(shouldBeTrade && !isTrade){
        makeOrder();
      } else if(!shouldBeTrade && isTrade){
        closeLong();
      }
    }
    
    if nothing else one could read that the close of the last bar needs to be low and after that the strategy goes Long.
    Which fits my knowledge (that the vix likes to return to some average price)

    Now if you saw the graph in app its not very good but because its in the market almost half of the time many trades are merged (because you would have to otherwise reopen a trade right after closing one)

    so in MT4 the graph looks like this
    Screenshot 2020-08-05 at 12.58.37.png

    and 223 trades shrink to 46 (not only because of merging but also because MT4 maximum test trading period is Daily and so not all Week data is used (the daily data starts later))

    last few trades
    Screenshot 2020-08-05 at 13.01.50.png

    MT stats
    Screenshot 2020-08-05 at 13.02.20.png

    ....
    so i also tried to search for strategies with 2 conditions.
    it wasn't essentially better but similar results were achieved on much less trades (so technically you could use the free money on something else...)

    Anyway i like VIX, its an easy market for me.

    edit: one more thing, i do use strategies like this one yes, but this tool is new so i cant give real life results from it
     
    ph1l and userque like this.
  10. Colleague

    Colleague

    dunno i think i first read about this kind of rules long time ago from Larry Williams

    what kind of rules would you suggest more ?
    i am always open to improve my work (today i found and fixed a bug already :D )
     
    #10     Aug 5, 2020