Porting a Moving Average Crossover Strategy into JavaScript
Summary
This tutorial shows how to transfer a simple MyLanguage trend strategy into JavaScript using a reusable event loop and order-management framework. The example computes two moving averages from market bars, compares their recent completed values, and treats an upward crossover as a long entry and a downward crossover as a short entry. Opposite crossover signals close the existing position. The surrounding framework tracks position states, checks current holdings, places limit orders around the price tick, and cancels unfilled orders.
The author compares the JavaScript implementation with the original MyLanguage backtest and reports that their results are nearly the same. This supports the porting example, but does not establish robustness or live-trading performance. The tutorial’s sample uses a daily bar setup and fixed position size, and it does not discuss transaction costs, slippage, or risk controls. Its broader lesson is that moving strategy logic into a general-purpose language can make custom data handling, charting, and interaction easier, while requiring the trader to implement execution and state management carefully.
Key ideas
- A crossover strategy can be ported by separating indicator calculations, signal rules, and execution logic.
- The example enters long or short positions when the faster moving average crosses the slower one.
- Opposite crossover signals close existing positions in the sample state machine.
- The reusable execution loop checks positions and cancels orders that remain unfilled.
- Similar backtest results do not establish performance after costs or in live markets.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.