0bps

Strategy vault / Tools & templates

Price Fluctuation Alarm

The program monitors the price fluctuation within a specified period. If it exceeds the specified range, it will send an SMS notification to the designated mobile users. Using the SMSBao interface, it can be sent to…

Author
Zero
Complexity
Intermediate · 92 lines
Parameters
6

The program monitors the price fluctuation within a specified period. If it exceeds the specified range, it will send an SMS notification to the designated mobile users. Using the SMSBao interface, it can be sent to multiple phone numbers, separated by commas. Please select the candlestick cycle for the cycle. If the candlestick cycle is 1 minute, the data within one minute will be monitored.

Parameters

NameDefaultWhat it controls
MaxRatio1.5Volatility (percentage))
LoopInterval5Collection interval (seconds)
EnableSMStrueEnable SMS notifications
SMSUsertestSMSBao username
SMSPasstestSMS Bao passwordMD5
PhoneNum111Notification phone number

Source JavaScript

function _N(v) {
    return Math.floor(parseFloat(v.toFixed(10))*1000)/1000;
}

var LastMsg = "";
function SMSSend(msg) {
    if (msg == LastMsg) {
        return;
    }
    Log('SMS:', msg);
    LastMsg = msg;
    var ret = false;
    var phones = PhoneNum.split(',');
    for (var i = 0; i < phones.length; i++) {
        ret = HttpQuery("http://www.smsbao.com/sms?u=" + encodeURIComponent(SMSUser) + "&p=" + SMSPass.toUpperCase() + "&m=" + phones[i] + "&c=" + encodeURIComponent(msg)) == "0";
        if (ret) {
            Log("SMS Notification", phones[i], "Success");
        } else {
            Log("SMS Notification", phones[i], "Failed");
        }
    }
    return ret;
}

function formatDate(t) {
    var year = t.getFullYear();
    var month = t.getMonth() + 1;
    var day = t.getDate();
    var hour = t.getHours();
    var minute = t.getMinutes();
    var second = t.getSeconds();

    if (month < 10) {
        month = '0' + month;
    }
    if (day < 10) {
        day = '0' + day;
    }
    if (hour < 10) {
        hour = '0' + hour;
    }
    if (minute < 10) {
        minute = '0' + minute;
    }
    if (second < 10) {
        second = '0' + second;
    }

    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
}

function main() {
    if (exchanges.length > 1) {
        throw "Only supports one exchange";
    }
    LoopInterval = Math.max(1, LoopInterval);
    Log('Floating percentage will be displayed as profit, Exceed' + MaxRatio + '% Alarm later');
    if (EnableSMS && !SMSSend('Alert strategy started successfully')) {
        throw "SMS interface test failed";
    }
    var preRatio = 0;
    var preKRatio = 0;
    while (true) {
        var records = exchange.GetRecords();
        if (records && records.length > 0) {
            var r = records[records.length-1];
            var n = _N(((r.High - r.Low) * 100) / r.High);
            
            if (records.length > 1) {
                var p = records[records.length-2];
                var pn = _N(((p.High - p.Low) * 100) / p.High);
                if (pn != preKRatio) {
                    preKRatio = pn;
                    if (pn != preRatio) {
                        LogProfit(pn, 'Time:', formatDate(new Date(p.Time)), 'High:', p.High.toFixed(4), 'Low:', p.Low.toFixed(4));
                        if (EnableSMS && n >= MaxRatio) {
                            SMSSend('Current floating ratio: ' + n + '%');
                        }
                    }
                }
            }
            if (n != preRatio) {
                LogProfit(n, 'Time:', formatDate(new Date(r.Time)), 'High:', r.High.toFixed(4), 'Low:', r.Low.toFixed(4));
                preRatio = n;
                if (EnableSMS && n >= MaxRatio) {
                    SMSSend('Current floating ratio: ' + n + '%');
                }
            }
        }
        Sleep(LoopInterval * 1000);
    }
}

Published by Zero on the FMZ strategy square · last modified 2014-10-11. 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/Price-Fluctuation-Alarm.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