Harigami
ログイン
Harigamiは、ログイン不要のコード共有サービスです。コードの投稿後に発行されるURLでコードを共有できます。
PythonやRubyなど一部の言語は、投稿後にオンラインで実行することもできます。
誰でも無料で使えて、広告もありません。コードレビューやスニペットの代わりに使ってみてください。


詳細設定
+
anonymous タイトルなし
JavaScript
function addValueToState(state, options, value) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    // Add to source
    Vue.set(source, value[options.primary], value);

    // build index
    addIndexToState(state, options, value[options.primary]);
}

function addIndexToState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        buildIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}

function removeIndexMulti(v, id, bucket, keys, i = 0) {
    const key = v[keys[i]];
    console.log(bucket);
    if(keys.length-1 == i) {
        bucket[key] = bucket[key].filter(x => x != id);
    }
    else {
        removeIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function removeValueFromState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    // remove for each index
    removeIndexFromState(state, options, id);

    // remove from source
    Vue.delete(source, id);
}

function removeIndexFromState(state, options, id) {
    if(!state[options.sourceName]) return;

    const source = state[options.sourceName];

    if(!source[id]) return;

    const v = source[id];

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        removeIndexMulti(v, v[options.primary], rootBucket, keys);
    }
}
  • 0
  • 0
anonymous タイトルなし
JavaScript
const shiftOptions: EntityOptions = {
    sourceName: 'shifts',
    primary: 'id',
    prefix: 'shift',
    indexes: {
        'idx1': { keys: [ 'branch_id', 'yearmonth', 'day' ] }
    }
}


function buildIndexMulti(v, id, bucket, keys, i = 0) {
    if(keys.length == i) {
        Vue.set(bucket, bucket.length, id);
    }
    else {
        const key = v[keys[i]]
        if(!bucket[key]) Vue.set(bucket, key, keys.length - i >= 2 ? {} : []);
        buildIndexMulti(v, id, bucket[key], keys, i+1);
    }
}

function addArrayToState(state, options, array) {
    if(!state[options.sourceName]) Vue.set(state, options.sourceName, {});

    const source = state[options.sourceName];
    const primary = options.primary;

    // build source
    for(const v of array) {
        // build source
        Vue.set(source, v[options.primary], v);
    }

    for(const name in options.indexes) {
        const index = options.indexes[name];
        const realName = options.prefix + '_' + name;
        if(!state[realName]) Vue.set(state, realName, {});
        const rootBucket = state[realName];
        const keys = index.keys;
        for(const v of array) {
            buildIndexMulti(v, v[primary], rootBucket, keys);
        }
    }
}
  • 0
  • 0
anonymous タイトルなし
JavaScript
const MyEventEmitter = function() {
    this.callbackPool = {};
}

MyEventEmitter.prototype.on = function(type, callback) {
    this.callbackPool[type] = callback;
}

MyEventEmitter.prototype.emit = function(type, arg) {
    const sliced = [];
    for(let i = 1; i < arguments.length; i++) sliced.push(arguments[i]);
    if(this.callbackPool) this.callbackPool[type].apply(undefined, sliced);
}
  • 0
  • 0
anonymous タイトルなし
Python
//@version=3
study(title="MTF Bollinger Bands", shorttitle="MTF 2 BB", overlay=true)

onoffA = input(true, "BB1 ON/OFF")
resA = input(title='BB1時間足 (BB1 Time Frame)', type=resolution, defval="60")
sigmaA = input(1,title='BB1偏差 (BB1 Sigma)', step=1, minval=1, maxval=3)
onoffB = input(true, "BB2 ON/OFF")
resB = input(title='BB2時間足 (BB1 Time Frame)', type=resolution, defval="60")
sigmaB = input(2,title='BB2偏差 (BB2 Sigma)', step=1, minval=1, maxval=3)

devA = security(tickerid, resA, stdev(close,20))
basisA = security(tickerid, resA, sma(close,20))
devB = security(tickerid, resB, stdev(close,20))
basisB = security(tickerid, resB, sma(close,20))

upper_1 = onoffA ? (basisA + devA * sigmaA) : na
lower_1 = onoffA ? (basisA - devA * sigmaA) : na
upper_2 = onoffB ? (basisB + devB * sigmaB) : na
lower_2 = onoffB ? (basisB - devB * sigmaB) : na

plot(basisA, color=red,title='BB1 Basis')
plot(basisB, color=orange,title='BB2 Basis')
u1 = plot(upper_1, color=blue,title='BB1 Upper')
l1 = plot(lower_1, color=blue,title='BB1 Lower')
u2 = plot(upper_2, color=green,title='BB2 Upper')
l2 = plot(lower_2, color=green,title='BB2 Lower')
fill(u1,l1, color=yellow, transp=90,title='BB1')
fill(u2,l2, color=yellow, transp=90,title='BB2')
  • 0
  • 0
anonymous タイトルなし
Python
//
// @author Jadbrother modified by gero
//
//@version=2
study(title = "RCI3lines", shorttitle = "RCI3lines")

itvs = input(9, "short interval")
itvm = input(27, "middle interval")
itvl = input(108, "long interval")
src = input(close, "source")
upperband=input(title="High line[%]",defval=80,type=integer)
lowerband=input(title="Low line[%]",defval=-80,type=integer)

ord(seq, idx, itv) =>
    p = seq[idx]
    o = 1
    s = 0
    for i = 0 to itv - 1
        if p < seq[i]
            o := o + 1
        else
            if p == seq[i]
                s := s+1
                o+(s-1)/2.0
    o

d(itv) =>
    sum = 0.0
    for i = 0 to itv - 1
        sum := sum + pow((i + 1) - ord(src, i, itv), 2)
    sum

rci(itv) => (1.0 - 6.0 * d(itv) / (itv * (itv * itv - 1.0))) * 100.0

hline(upperband,color=gray,linestyle=dashed)
hline(lowerband,color=gray,linestyle=dashed)
plot(rci(itvs), title = "RCI short", color = red)
plot(rci(itvm), title = "RCI middle", color = green)
plot(rci(itvl), title = "RCI long", color = blue)
  • 0
  • 0
anonymous タイトルなし
Python
//
// @author Jadbrother modified by gero
//
//@version=2
study(title = "RCI3lines", shorttitle = "RCI3lines")

itvs = input(9, "short interval")
itvm = input(36, "middle interval")
itvl = input(52, "long interval")
src = input(close, "source")
upperband=input(title="High line[%]",defval=80,type=integer)
lowerband=input(title="Low line[%]",defval=-80,type=integer)

ord(seq, idx, itv) =>
    p = seq[idx]
    o = 1
    s = 0
    for i = 0 to itv - 1
        if p < seq[i]
            o := o + 1
        else
            if p == seq[i]
                s := s+1
                o+(s-1)/2.0
    o

d(itv) =>
    sum = 0.0
    for i = 0 to itv - 1
        sum := sum + pow((i + 1) - ord(src, i, itv), 2)
    sum

rci(itv) => (1.0 - 6.0 * d(itv) / (itv * (itv * itv - 1.0))) * 100.0

hline(upperband,color=gray,linestyle=dashed)
hline(lowerband,color=gray,linestyle=dashed)
plot(rci(itvs), title = "RCI short", color = red)
plot(rci(itvm), title = "RCI middle", color = blue)
plot(rci(itvl), title = "RCI long", color = green)
  • 0
  • 0
anonymous タイトルなし
Python
//@version=3
study("MTF 8 SMA/EMA", overlay=true)

// SMA or EMA
SEswitch = input(title="on:EMA off:SMA", type=bool, defval=true)

//Get EMA Values
maA = input(title='MA1 期間', type=integer, minval=1, step=1, defval=10)
maB = input(title='MA2 期間', type=integer, minval=1, step=1, defval=75)
maC = input(title='MA3 期間', type=integer, minval=1, step=1, defval=10)
maD = input(title='MA4 期間', type=integer, minval=1, step=1, defval=75)
maE = input(title='MA5 期間', type=integer, minval=1, step=1, defval=10)
maF = input(title='MA6 期間', type=integer, minval=1, step=1, defval=75)
maG = input(title='MA7 期間', type=integer, minval=1, step=1, defval=10)
maH = input(title='MA8 期間', type=integer, minval=1, step=1, defval=75)


//Set resolutions
resA = input(title='MA1 時間足', type=resolution, defval="5")
resB = input(title='MA2 時間足', type=resolution, defval="5")
resC = input(title='MA3 時間足', type=resolution, defval="15")
resD = input(title='MA4 時間足', type=resolution, defval="15")
resE = input(title='MA5 時間足', type=resolution, defval="60")
resF = input(title='MA6 時間足', type=resolution, defval="60")
resG = input(title='MA7 時間足', type=resolution, defval="240")
resH = input(title='MA8 時間足', type=resolution, defval="240")


//Set switches
emaAswitch = input(title="MA1 On/Off", type=bool, defval=true)
emaBswitch = input(title="MA2 On/Off", type=bool, defval=true)
emaCswitch = input(title="MA3 On/Off", type=bool, defval=true)
emaDswitch = input(title="MA4 On/Off", type=bool, defval=true)
emaEswitch = input(title="MA5 On/Off", type=bool, defval=true)
emaFswitch = input(title="MA6 On/Off", type=bool, defval=true)
emaGswitch = input(title="MA7 On/Off", type=bool, defval=true)
emaHswitch = input(title="MA8 On/Off", type=bool, defval=true)

//get data
dataA = security(tickerid, resA, SEswitch ? ema(close, maA) : sma(close, maA))
dataB = security(tickerid, resB, SEswitch ? ema(close, maB) : sma(close, maB))
dataC = security(tickerid, resC, SEswitch ? ema(close, maC) : sma(close, maC))
dataD = security(tickerid, resD, SEswitch ? ema(close, maD) : sma(close, maD))
dataE = security(tickerid, resE, SEswitch ? ema(close, maE) : sma(close, maE))
dataF = security(tickerid, resF, SEswitch ? ema(close, maF) : sma(close, maF))
dataG = security(tickerid, resG, SEswitch ? ema(close, maG) : sma(close, maG))
dataH = security(tickerid, resH, SEswitch ? ema(close, maH) : sma(close, maH))

//Plotting
plot(emaAswitch ? dataA : na, color=blue, linewidth=3)
plot(emaBswitch ? dataB : na, color=lime, linewidth=3)
plot(emaCswitch ? dataC : na, color=yellow, linewidth=3)
plot(emaDswitch ? dataD : na, color=orange, linewidth=3)
plot(emaEswitch ? dataE : na, color=red, linewidth=3)
plot(emaFswitch ? dataF : na, color=fuchsia, linewidth=3)
plot(emaGswitch ? dataG : na, color=maroon, linewidth=3)
plot(emaHswitch ? dataH : na, color=white, linewidth=4)
  • 0
  • 0
LC23 タイトルなし
Python
//@version=3
study('GMMA', overlay=true)
//MA
emaOrSma = input(title="EMA or SMA?", defval="EMA", options=["EMA", "SMA"])
maPeriodFast_1 = input(title="MA Period Fast 1", type=integer, defval=3, minval=1, maxval=10000)
maPeriodFast_2 = input(title="MA Period Fast 2", type=integer, defval=5, minval=1, maxval=10000)
maPeriodFast_3 = input(title="MA Period Fast 3", type=integer, defval=8, minval=1, maxval=10000)
maPeriodFast_4 = input(title="MA Period Fast 4", type=integer, defval=10, minval=1, maxval=10000)
maPeriodFast_5 = input(title="MA Period Fast 5", type=integer, defval=12, minval=1, maxval=10000)
maPeriodFast_6 = input(title="MA Period Fast 6", type=integer, defval=15, minval=1, maxval=10000)
maPeriodSlow_1 = input(title="MA Period Slow 1", type=integer, defval=30, minval=1, maxval=10000)
maPeriodSlow_2 = input(title="MA Period Slow 2", type=integer, defval=35, minval=1, maxval=10000)
maPeriodSlow_3 = input(title="MA Period Slow 3", type=integer, defval=40, minval=1, maxval=10000)
maPeriodSlow_4 = input(title="MA Period Slow 4", type=integer, defval=45, minval=1, maxval=10000)
maPeriodSlow_5 = input(title="MA Period Slow 5", type=integer, defval=50, minval=1, maxval=10000)
maPeriodSlow_6 = input(title="MA Period Slow 6", type=integer, defval=60, minval=1, maxval=10000)

fast_1 = emaOrSma == "EMA" ? ema(close, maPeriodFast_1) : sma(close, maPeriodFast_1)
fast_2 = emaOrSma == "EMA" ? ema(close, maPeriodFast_2) : sma(close, maPeriodFast_2)
fast_3 = emaOrSma == "EMA" ? ema(close, maPeriodFast_3) : sma(close, maPeriodFast_3)
fast_4 = emaOrSma == "EMA" ? ema(close, maPeriodFast_4) : sma(close, maPeriodFast_4)
fast_5 = emaOrSma == "EMA" ? ema(close, maPeriodFast_5) : sma(close, maPeriodFast_5)
fast_6 = emaOrSma == "EMA" ? ema(close, maPeriodFast_6) : sma(close, maPeriodFast_6)
slow_1 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_1) : sma(close, maPeriodSlow_1)
slow_2 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_2) : sma(close, maPeriodSlow_2)
slow_3 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_3) : sma(close, maPeriodSlow_3)
slow_4 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_4) : sma(close, maPeriodSlow_4)
slow_5 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_5) : sma(close, maPeriodSlow_5)
slow_6 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_6) : sma(close, maPeriodSlow_6)

//color
plot(fast_1, color=yellow)
plot(fast_2, color=orange)
plot(fast_3, color=red)
plot(fast_4, color=maroon)
plot(fast_5, color=fuchsia)
plot(fast_6, color=purple)
plot(slow_1, color=navy)
plot(slow_2, color=blue)
plot(slow_3, color=aqua)
plot(slow_4, color=teal)
plot(slow_5, color=lime)
plot(slow_6, color=green)
  • 0
  • 1
anonymous タイトルなし
Python
Profit +10% after 2 days 
The minimum amount for donation is 0.0025 BTC. 
Maximum donation amount is 10 BTC. 
 
Ref bonus 3 levels: 5%,3%,1% paying next day after donation 
https://quickchain.cc/
  • 0
  • 1
anonymous vuex-persisted-state filter example
JavaScript
    filter(mutation) {
        const t = mutation.type;
        const except_table = { 
            initChanging: 1,
            storeChanging: 1,
            deleteLoadingDialog: 1,
            deleteLoadingNodeDialog: 1,
            "route/ROUTE_CHANGED": 1
        };
        if(except_table[t]) {
            return false;
        }
        return true;
    },
  • 0
  • 1