0bps

Strategy vault / Tools & templates

Example of Using Drawing Library to Draw Candlestick and Moving Average Charts

JavaScript strategy by 发明者量化-小小梦.

Author
发明者量化-小小梦
Complexity
Starter · 35 lines
Parameters
1

The original spec has no written description. Read the source below.

Parameters

NameDefaultWhat it controls
MaCyc10Moving average parameters

Source JavaScript

var PreBarTime = 0
function PlotMA_Kline(records, param, isFirst){
    var ma = TA.MA(records, param)
    $.PlotRecords(records, "K")
    if(isFirst){
        for(var i = records.length - 1; i >= 0; i--){
            if(ma[i] !== null){
                $.PlotLine("ma", ma[i], records[i].Time)
            }
        }
        PreBarTime = records[records.length - 1].Time
    } else {
        if(PreBarTime !== records[records.length - 1].Time){
            $.PlotLine("ma", ma[ma.length - 2], records[records.length - 2].Time)
            PreBarTime = records[records.length - 1].Time
        }
        $.PlotLine("ma", ma[ma.length - 1], records[records.length - 1].Time)
    }


}

function main(){
    var maCyc = MaCyc
    var isFirst = true

    while(1){
        var records = exchange.GetRecords()
        if(records && records.length > maCyc){
            PlotMA_Kline(records, maCyc, isFirst)
            isFirst = false
        }
        Sleep(1000)
    }
}

Published by 发明者量化-小小梦 on the FMZ strategy square · last modified 2018-11-12. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a tested, production-ready module from strategies/Example-of-Using-Drawing-Library-to-Draw-Candlestick-and-Moving-Average-Charts.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open