Quickly see all trades, income graphs, buy / sell graphs and much more
Download Candle Data, Write and Run Trading Strategies with Ease
import { BTH } from "../infra/interfaces"
import { indicatorSMA } from "../indicators/moving-averages"
export async function sma(bth: BTH) {
// Get low and high SMA from input
const lowSMAInput = bth.params.lowSMA
const highSMAInput = bth.params.highSMA
// Get Candles
const lowSMACandles = await bth.getCandles('close', 0, lowSMAInput)
const highSMACandles = await bth.getCandles('close', 0, highSMAInput)
// Get SMA's
const lowSMA = await indicatorSMA(lowSMACandles, lowSMAInput, 1)
const highSMA = await indicatorSMA(highSMACandles, highSMAInput, 1)
// Perform Buy / Sell when low crosses high
if (lowSMA > highSMA) {
await bth.buy()
} else {
await bth.sell()
}
}
To run with multi value or multi symbol, you do not need to change your code only your run params!!!
Download any data from whatever timeframe interval you desire in a matter of seconds with ease. Any downloaded data can easily be exported to a csv.
Your candle data is not crypto related? No problem just import your data from a csv and your on your way to running that killer strategy on your desired historical candle data set.
Easily download crypto candle data from binance
Import any candle data to the app to then run strategies on
Access the candle data, add more candle data or delete the data.
Easily export any downloaded candle data to a csv
How to run a strategy in the BacktestJS application.
How to run a strategy in the BacktestJS application with more options.
How to run a strategy in the BacktestJS application with multi values.
How to run a strategy in the BacktestJS application with multiple symbols.
How to code a simple sma trading strategy.
How to code a simple sma trading strategy with paramaters.
Code a more advanced sma trading strategy including shorting / stop losses.
Code an advanced sma trading strategy with more advanced buy / sells.
What trading results are given and how to view them.
What multi value trading results are given and how to view them.
What multi symbol trading results are given and how to view them.
How to save / delete trading results.
Create the basic skeleton structure that every strategy needs.
How to retrieve candle data in your strategy.
How and where to call indicators / make your own indicators.
How to perform buy / sells within your strategy.
How to access the order book data object in your strategy.
BacktestJS is completely free, not freemium, no signups, no credit cards and no ads. Not only is the application free but its open source as well so users can contribute to the application!
Glad you asked! We currently accept donations in Bitcoin, Ethereum and Paypal. Wanna donate some other way? Feel free to contact us.
Bitcoin:
Ethereum:
Paypal
Great question! There are a lot of moving parts keeping this project alive. One great way is to contribute to the code of the BacktestJS application itself or adding indicators / strategies. Feel free to put in a PR (follow the guidelines) via github.
I dont code but want to help? Thats even better. Main areas where we can use help is marketing (would love help here 🙂 ), website development and graphic design. If you have a different expertise that you think can help, feel free to contact us!
Remember we are an open source project, all work is done from the bottom of your heart 🙂 and of course all work will be credited to the maker.
Contact us for a quote as we do offer paid services to code trading strategies. Your coded strategy will be kept private to you and not published to the application.
A second option is to reach out to the community forum. If we or someone else find it interesting it might get coded!
Head over to the community we would love to hear about it!
Now this is a great question 🙂 . In general its always a better practice to code in TS over JS in my honest opinion. With that said you can always convert the project to JS with one simple command (learn more here) and choose to write your strategies in JS instead. Basically TS is a wrapper to JS, in the end of the day we code in JS which is why it’s called BacktestJS.
Update: the above was a cover up don’t tell anyone 🙂 i just like the name BacktestJS more than BacktestTS.
My name is Andrew and i made this monstrosity of an application, website, documentation and youtube videos.
The why is a bit harder to explain. A friend once asked me to write a backtest of a strategy he had. I didn’t know what a strategy was, not even what a candle was. But like a good, curious friend i figured out this stock world, how to get candle data and then wrote some rudimentary tests. I found that i really liked this and had ideas of strategies. As time went on i realized i had around 100 strategies with most of them having the same basic infra and indicators rewritten over and over and tons of different candle data in spreadsheets throughout my computer. This was a huge mess to say the least.
So I decided to make an infra that can get and save candle data to a db and provide a super smooth infra to code ANY strategy no matter how complex. I then realized many people could benefit from this so i can either keep it to myself or i can put in a lot more work 🙂 and make it open source. I then spent a lot of time making sure the app has good error validation, ease of use, automation and of course i needed a pretty website, docs, examples and youtube videos to go along with it!!
But wait pinescript exists why rewrite the wheel? Well although i did learn pinescript before writing this i was not thrilled to learn yet another language at first and i figured it would be easy to code this infra in JS and of course would run much faster. Eventually while i did succumb to pinescript at first, I quickly learned that it wasn’t powerful enough for the very intricate things i wanted and went back to JS and wrote this app.
While i personally don’t recommend the approach it can easily be done. Run the command “npm run makejs” or “npm build” and then the typescript will be converted to javascript in a new folder called “dist”. To code a strategy you must go inside “/dist/strategies” and you can code your strategy inside here with javascript instead of “/src/strategies” which is the place to code strategies using typescript.
This is most likely due to asking for more candles than are available.
Lets say you have 2 years of data on a daily timeframe and your strategy requires 60 candles worth of data for the indicator to work. When you call the getCandle() function on the first day, it realizes that you dont have 60 candles worth of data in the past and instead returns an array of 60 0’s and blocks the buy() / sell() functions. This happens for 2 months worth of candles (60 candles) until you have enough data and the getCandles() function returns candles correctly and buy / sell is no longer blocked.
The indicators are coming from a plugin called tulind. If tulind is returning incorrect data please reach out to the tulind project. From experience i have seen that some indicators need more candle data. For example if the indicator needs 60 closes try to give it 120 closes instead. Keep in mind a trading view indicator and tulind indicator might use different math to get their value.