سادہ کثیر اقسام کے اجناس کے فیوچر کی حرکت پذیر اوسط لائن کی حکمت عملی

مصنف:نیکی, تخلیق: 2018-08-31 11:36:35, تازہ کاری: 2019-12-03 17:33:28

سادہ کثیر اقسام کے اجناس کے فیوچر کی حرکت پذیر اوسط لائن کی حکمت عملیwww.fmz.com

کموڈٹی فیوچر لائبریری $.CTA فنکشن کے اسٹریٹجک فریم ورک کو نافذ کرتی ہے۔ اس حکمت عملی کے فریم ورک کے ساتھ ، ایک ہی وقت میں مستحکم اور حقیقی مارکیٹ کی حکمت عملی کی ایک کثیر قسم کی حکمت عملی صرف چند درجن لائنوں میں حاصل کی جاسکتی ہے۔

function main() {
    // using commodity futures library of the CTA strategy framework
    $.CTA(Symbols, function(st) {
        var r = st.records
        var mp = st.position.amount
        var symbol = st.symbol
        /*
        r is the K line, mp is the current variety position, positive number refers to long positions, negative number refers to short position, 0 means no position, 
        symbol refers to variety name       
        The return value is n: 
            n = 0 : Refers to close all position (regardless of the current holdings position)
            n > 0 : If there are currently holding long positions, adding n long positions, if the current position is short position, then close n short positions, 
                    if n is greater than the current holding position, then open long positions      
            n < 0 : If the current position is short position, adding n short positions. If the current position is long positions, then close n long positions.
                    If -n is greater than the current holding position, then open short position.   
            No return value means doing nothing
        */
        if (r.length < SlowPeriod) {
            return
        }
        var cross = _Cross(TA.EMA(r, FastPeriod), TA.EMA(r, SlowPeriod));
        if (mp <= 0 && cross > ConfirmPeriod) {
            Log(symbol, "up cross cycle", cross, "Current holding position", mp);
            return Lots * (mp < 0 ? 2 : 1)
        } else if (mp >= 0 && cross < -ConfirmPeriod) {
            Log(symbol, "down cross cycle", cross, "Current holding position", mp);
            return -Lots * (mp > 0 ? 2 : 1)
        }
    });
}

مزید

لوئسبہت اچھا

چھوٹا سا خواباچھا! ^=^