Porting a Dual Moving Average Strategy from My Language to JavaScript
Summary
This document shows how to translate a My-language trading strategy into JavaScript when the original language makes custom data handling difficult. Its reusable framework separates market-data processing, signal generation, and order execution, with a state variable tracking whether the system is idle, entering, or holding a position. The example ports a dual moving average crossover: it calculates 5-period and 15-period averages, compares the two most recent completed bars, and opens or closes long and short positions when their relationship crosses.
The author compares backtests of the JavaScript and My-language versions and reports broadly similar results. The example is presented as a way to gain flexibility for custom bar construction, data processing, and charting. The document does not provide numerical performance details or a rigorous comparison of execution assumptions, and its order-management code is specific to the cited futures platform and contract setup.
Key ideas
- A reusable strategy framework can separate data processing, signal conditions, and order execution.
- The example uses 5-period and 15-period moving average crossovers to generate long and short signals.
- Comparing completed bars helps identify confirmed crossovers rather than relying on the current unfinished bar.
- The two language implementations are reported to have broadly similar backtest results.
- Porting enables custom data handling, including nonstandard bar construction and charting.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.