Hello Tickblaze, I am a machine learning engineer and am interested in algo trading. I wanted to ask if all libraries are able to be imported in Python. I have a couple of machine learning strategies I want to backtest, so is that functionality there? Also, I saw you guys had mentioned the implementation for Rithmic and futures trading support so when would be an estimated timeline for that? Thank you
Tickblaze uses the Python for .NET open source project which integrates Python with C#. The project supports Python packages which can be referenced from your scripts. That being said your code and any access to the packages need to fit into our existing script architecture. I suggest you simply download the platform and test out whatever you're looking to do.
Hello @Tickblaze. I am trying to code a strategy in your platform and would really appreciate an advise. Here is a simplified logic of the strategy: 1) every day search for stocks which gapped up more than 70%. That is, where today's open is at least 50% higher than yesterday's close 2) If the condition is met - short sell the ticker and cover the position at 14:30 3) If the condition is not met - forget about the ticker until tomorrow I have coded the strategy, but my current problem is that the OnBarUpdate function seems to be evaluated every minute even if the "gap up" condition was not met, which leads to quite long backtesting time. Is there a way to code the "forget about the ticker till tomorrow if it hasn't gapped up" logic in the platform? I am currently experimenting with the DataSeriesSwitch function, but hasn't found a solution yet.
Hi @Pochitito If you export and share your strategy's code (MENU > Desktops > Export Resource), I will take a look at it this weekend (no promises though). It is difficult to help when we can't see the code and the settings of your strategy. Can you share Data Series settings? Just to check..
I don't know about the details of their architecture but you have 2 choices right out of the gate: 1) build a custom callback (if not already provided) on daily data, only. Then invoke the day open callback to evaluate potential trade entries and invoke day close to close open positions and run performance attribution. 2) check on each 1minute callback whether it is the first callback or last callback of the day to run your entry and exit, else ignore. Re 1) that's obviously only for back testing. Running in production you definitely want to run additional risk checks at a minimum each single minute throughout the session.
I would be the most grateful. Please find the exported strategy (simplifed version) attached. With regards to the Data Series settings, that's what has worked for me so far
Pochitito, ok, got the code for you. First off, your Data Series need to be set to 1 minute bars and invoked On Bar Closed, like this: I ran the backtest on DJI stocks from 2015, but didn't get many trades, so I tried Gamestop and that was better so here's GME backtest from 2015-2023 just so that you can compare results: And here's the strategy code. It is kinda slow to backtest on 1min bars, but you get other advantages and flexibility, like you can add stoploss with high precision, you can do some risk management checks each minute and generally the code is more live-execution ready. Don't forget to add Position Sizing script (Fixed Equity etc.) tickblaze_strategy_gapupreverse.zip P.S. It is a C# version, I prefer it to Python, but the strategy is very simple and should be easy to read / port.
Hi @petrz Thank you very much! Your version runs way faster and it taught me many things I didn't know about Tickblaze. By the way, with regards to the two data series setups: 1) Daily bars consisting of minutes where the strategy is invoked on every update 2) Minute bars consisting of minutes where the strategy is invoked on bar close My assumption was that there shouldn't be much difference (assuming that the code is adjusted for every option) between them as the "OnBarUpdate" function will be executed every minute anyway. Do I miss something?
My quant friend, that innocent sentence "there shouldn't be much difference" makes all the difference in the world You know what they say ... The devil is in the details. Let me explain. You are right in the big picture, but the crucial difference lies in the Script Functions - the result is different when they are called on a 1min bar (with On Bar Close) or the Daily bar built from 1 min (with On Bar Update). Specifically: 1) The function TotalDataCount() < 390 on a Daily bar will now skip 1.5 years worth of data 2) The function SessionIsFirstBar() will return true on every minute update you evaluate it, because there really is only 1 bar for the session, updated every minute. 3) the function DataIsMissing() now evaluates Daily bars, not small data gaps in the 1 minute data (this actually makes a difference of 1 trade on GME) 4) The function BrokerMarketOnClose() handles closing the position differently on a Daily bar built from minute bars with On Bar Update (it will close the position on next bar update), so you have to write a different exit block. Not to mention one important thing - when you invoke the strategy with On Bar Update settings in LIVE mode, it will be updated on each new incoming TICK, no matter what source bars its built from. So On Bar Update setting in LIVE mode does not match the behavior in the BACKTEST mode (unlike On Bar Close setting, which behaves the same in both BACKTEST/LIVE mode). Practically speaking, in order to make the script work with Daily bars built from 1 minute bars with On Bar Update settings, you would have to make several important changes to my script - like this ... se my version 2 of the script. tickblaze_strategy_gapupreverse_v2.zip This version will work with both Data Series settings. But it might produce different results because of how the functions handle bars. For example, the version running on 1 minutes bars with On Bar Close will leave out a trade opportunity GME on 02/25/2021, but the version running on Daily bars with On Bar Update will make the trade. Why the discrepancy? Because the 1 minute On Bar Close version is checking for intraday missing data using the function DataIsMissing(0) and DataIsMissing(1), and when GME started gapping like crazy in 2021, it had a lot of intraday data gaps like this...
Pochitito, alternatively, you could backtest on Daily data (Bar Type = Day, Bar Source = Day, Invoke = On Bar Close), which would be the fastest way to backtest a large universe of stocks, but also the most unrealistic. There's also a catch with Daily bars and On Bar Close - we can't cheat the backtester and look into the future to check the developing bar Open, so what do we do? We look back 1 day into the past and calculate the trades ourselves. We will use the in-built Output Window to basically calculate and create rows of trades, which you will then copy and paste into a new TXT/CSV file and import it into an Excel. Like this: And with 3 clicks in Excel, you got the equity curve, voila: Ok, here is the code for version 3: tickblaze_strategy_gapupreverse_v3.zip This Daily version is probably better and much faster for some early exploration of your strategy, but is very unrealistic when it comes to execution. It is naive to think that you will get the precise opening price when executing a position, especially when these stocks GAP UP so far. For LIVE production version, if you get to this stage, I would use the 1 minute or TICK version of the strategy. Hell, probably even look into premarket data (if there is any liquidity) and send MOO orders early. P.S. If you want to calculate the cummulative equity of multiple symbols, you will have to adjust the code and probably use multi-symbol strategy. Or just remove it and do it in Excel.