# CumulitiveDeltaWithEma

**URL:** <https://community.tradovate.com/t/cumulitivedeltawithema/7177>\
**Category:** Custom Indicators\
**Created:** [April 26, 2023, 5:00pm UTC](https://community.tradovate.com/t/cumulitivedeltawithema/7177 "2023-04-26T17:00:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex\_Mandich](https://avatars.discourse-cdn.com/v4/letter/a/ccd318/32.png) [@Alex\_Mandich](https://community.tradovate.com/u/Alex_Mandich)\
**Post date:** [April 26, 2023, 5:00pm UTC](https://community.tradovate.com/t/cumulitivedeltawithema/7177/1 "2023-04-26T17:00:45Z")

</div>

hi ppl trying to make a custom indicator, but like most having issues i cant get in on my indictor tab for some reason. any pointer or videos will be appericated.

i just took the existing Cvd on tradovate and had chat gpt to add 4 ema’s

here is the code if any one want to help

const predef = require(“./tools/predef”);  
const meta = require(“./tools/meta”);

class cumulativeDeltaHistogram {  
init() {  
this.delta;  
this.last = 0;  
this.sessionLast = 0;  
this.line;  
this.cumulativeDelta;  
this.ema10;  
this.ema20;  
this.ema50;  
this.ema200;  
}

```
map(d, index, history) {
    // Delta
    let delta = d.offerVolume() - d.bidVolume();
   
    if (this.props.resetSession){
       
        // Session cumulative delta
        let sessionCumulativeDelta = this.sessionLast + delta;
        this.sessionLast = sessionCumulativeDelta;
       
        const timestamp = d.timestamp();
        const currentTime = timestamp.getHours()*60 + timestamp.getMinutes();

        const sessionStartTime = this.props.sessionStartHour * 60 + this.props.sessionStartMinute;
       
        if (history.prior()) {
            const priorTimestamp = history.prior().timestamp();
            const priorTime = priorTimestamp.getHours()*60 + priorTimestamp.getMinutes();
            if (priorTime < sessionStartTime && currentTime >= sessionStartTime) {
                sessionCumulativeDelta = delta;
                this.sessionLast = sessionCumulativeDelta;
            }
        }
        this.cumulativeDelta = sessionCumulativeDelta;
       
    }else{
       
        // Cumulative Delta
        let fullCumulativeDelta = this.last + delta;
        this.last = fullCumulativeDelta;
       
        this.cumulativeDelta = fullCumulativeDelta;
       
    }
   
    const deltaColor = { color: this.cumulativeDelta > 0 ? "green" : "red" };
   
    // Show lines if true
    if (this.props.showLine) {
        this.line = this.cumulativeDelta;
    }
   
    // EMA calculations
    const alpha10 = 2 / (10 + 1);
    const alpha20 = 2 / (20 + 1);
    const alpha50 = 2 / (50 + 1);
    const alpha200 = 2 / (200 + 1);

    if (index === 0) {
        this.ema10 = this.cumulativeDelta;
        this.ema20 = this.cumulativeDelta;
        this.ema50 = this.cumulativeDelta;
        this.ema200 = this.cumulativeDelta;
    } else {
        this.ema10 = alpha10 * this.cumulativeDelta + (1 - alpha10) * this.ema10;
        this.ema20 = alpha20 * this.cumulativeDelta + (1 - alpha20) * this.ema20;
        this.ema50 = alpha50 * this.cumulativeDelta + (1 - alpha50) * this.ema50;
        this.ema200 = alpha200 * this.cumulativeDelta + (1 - alpha200) * this.ema200;
    }

    return {
        line: this.line,
        value: this.cumulativeDelta,
        ema10: this.ema10,
        ema20: this.ema20,
        ema50: this.ema50,
        ema200: this.ema200,
        style: { value: deltaColor }
    };
}

```

}

module.exports = {  
name: “cumulativeDeltaHistogram”,  
description: “Cumulative Delta Histogram”,  
calculator: cumulativeDeltaHistogram,  
params: {  
resetSession: predef.paramSpecs.bool(true),  
sessionStartHour: predef.paramSpecs.percent(18, 1, 0, 23),  
sessionStartMinute: predef.paramSpecs.percent(0, 1, 0, 59),  
showLine: predef.paramSpecs.bool(true),  
},  
inputType: meta.InputType.BARS,  
areaChoice: meta.AreaChoice.NEW,  
tags: [predef.tags.Volumes],  
plots: {  
value: {title: ‘Cum Δ’},  
line: {title: ‘Line’, displayOnly: true},  
ema10: {title: ‘EMA 10’, color: ‘green’},  
ema20: {title: ‘EMA 20’, color: ‘blue’},  
ema50: {title: ‘EMA 50’, color: ‘orange’},  
ema200: {title: ‘EMA 200’, color: ‘red’},  
},  
plotter: [  
predef.plotters.histogram,  
predef.plotters.singleline(“line”),  
predef.plotters.ma(“ema10”),  
predef.plotters.ma(“ema20”),  
predef.plotters.ma(“ema50”),  
predef.plotters.ma(“ema200”)  
],  
schemeStyles: {  
dark: {  
line: {color: “ACE5EE”, lineStyle: 1}  
}  
}  
};

thanks for your time.

---

<div class="post-metadata">

**Author:** ![khaled007622](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@khaled007622](https://community.tradovate.com/u/khaled007622)\
**Post date:** [April 26, 2023, 8:39pm UTC](https://community.tradovate.com/t/cumulitivedeltawithema/7177/2 "2023-04-26T20:39:27Z")

</div>

Hi there, based off @TikiDave “Tiki Cum Delta Line”, you can find below an adaptation with the 4 EMAs. You can switch the reset at the begining of each session in the options. In my experience and I don’t know why, the JavaScript language used by ChatGPT is not the same than the one understood by Tradovate platform.  
///------------------  
const predef = require(“./tools/predef”);  
const meta = require(“./tools/meta”);  
const EMA = require(“./tools/EMA”);

function number(defValue, step, min) {  
return {  
type: meta.ParamType.NUMBER,  
def: defValue,  
restrictions: {  
step: step || 1,  
min: min \> 0 ? min : 0  
}  
};  
}

class tikiCumulativeDeltaLine4 {  
init() {  
this.last = 0;  
this.tradeDate = 0;

```
    // EMAS
    this.ema1 = EMA(this.props.period1);
    this.ema2 = EMA(this.props.period2);
    this.ema3 = EMA(this.props.period3);
    this.ema4 = EMA(this.props.period4);
                            
}

map(d, i, history) {
    const bidVolume = d.bidVolume();
    const askVolume = d.offerVolume();
    const delta = askVolume - bidVolume;
    
    const open = this.last;
    const close = open + delta;
    const range = Math.abs(open) > Math.abs(close) ? open : close;
    const prevd = i > 0 ? history.prior() : d;

    const type = this.props.type;
    const tradeDate = d.tradeDate();
    
    this.last = close;
    if (type === 'chart') {
        if (tradeDate !== this.tradeDate) {
            this.last = 0;
            this.tradeDate = tradeDate;
        }
    } else if (type === 'session') {
        const timestamp = d.timestamp();
        const hour = timestamp.getHours();
        const minute = timestamp.getMinutes();
        const startHour = this.props.startHour;
        const startMinute = this.props.startMinute;
        
        if (history.prior()) {
            const priorTimestamp = history.prior().timestamp();
            const priorHour = priorTimestamp.getHours();
            const priorMinute = priorTimestamp.getMinutes();
            
            // Hacky way to help tick charts work.
            const startTime = +('' + startHour + (startMinute < 10 ? '0' : '') + startMinute)
            const priorTime = +('' + priorHour + (priorMinute < 10 ? '0' : '') + priorMinute)
            const time = +('' + hour + (minute < 10 ? '0' : '') + minute)
            
            if (priorTime < startTime && time >= startTime) {
                this.last = 0;
                this.tradeDate = tradeDate;
            }
        }
    }
    
    const EMA10 = this.ema1(this.last);
    const EMA20 = this.ema2(this.last);
    const EMA50 = this.ema3(this.last);
    const EMA200 = this.ema4(this.last);
    
    
    return {
        delta: this.last,
        zero: 0,
        EMA10:EMA10,
        EMA20:EMA20,
        EMA50:EMA50,
        EMA200:EMA200,
    };

    // return {
    // open, 
    // close, 
    // delta: this.last, 
    // value: range
    // };
}

```

}

module.exports = {  
name: “tikiCumulativeDeltaLine4”,  
description: “Tiki CVD & EMAs”,  
calculator: tikiCumulativeDeltaLine4,  
params: {  
period1: predef.paramSpecs.period(10),  
period2: predef.paramSpecs.period(20),  
period3: predef.paramSpecs.period(50),  
period4: predef.paramSpecs.period(200),

```
    type: predef.paramSpecs.enum({
        chart: 'Chart',
        session: 'Session'
    }, 'Chart'),
    startHour: number(9, 1, 0),
    startMinute: number(30, 1, 0)
},
plots: {
delta: { title: 'Delta' },
zero: { title: 'Zero' },
EMA10: { title: "EMA 10" },
EMA20: { title: "EMA 20" },
EMA50: { title: "EMA 50" },
EMA200: { title: "EMA 200" },
},
inputType: meta.InputType.BARS,
areaChoice: meta.AreaChoice.NEW,
// plotter: predef.plotters.histogram,
tags: ['00 Indicators'],
schemeStyles: {
    dark: {
        delta: predef.styles.plot({ 
            color: "red"
        }),
        zero: predef.styles.plot({ 
            color: "yellow"
        }),
        EMA10: {color: "cyan", lineStyle: 1 },
        EMA20: {color: "blue", lineStyle: 2 },
        EMA50: {color: "orange", lineStyle: 3 },
        EMA200: {color: "forestgreen", lineStyle: 4 },
    }
}

```

};

---

<div class="post-metadata">

**Author:** ![khaled007622](https://avatars.discourse-cdn.com/v4/letter/k/e480ec/32.png) [@khaled007622](https://community.tradovate.com/u/khaled007622)\
**Post date:** [April 26, 2023, 8:42pm UTC](https://community.tradovate.com/t/cumulitivedeltawithema/7177/3 "2023-04-26T20:42:58Z")

</div>

It’s not perfect, because the EMAs don’t seem to reset each day like the CVD.

---

<div class="post-metadata">

**Author:** ![Fred\_Naef](https://avatars.discourse-cdn.com/v4/letter/f/dc4da7/32.png) [@Fred\_Naef](https://community.tradovate.com/u/Fred_Naef)\
**Post date:** [May 20, 2023, 6:35pm UTC](https://community.tradovate.com/t/cumulitivedeltawithema/7177/4 "2023-05-20T18:35:14Z")

</div>

Hi Khaled:  
Follow up , you noted:

> It’s not perfect, because the EMAs don’t seem to reset each day like the CVD."  
> So I can assume it is not functional, so as to render it basically useless?  
> I do not want misconstructed information and would rather have nothing than to look at something  
> that is not accurate!. Most humbly I already have introduced many elements that seem to be hurting rather than assisting my trade decisions.

---

<div class="post-metadata">

**Author:** ![Reymou\_306](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Reymou\_306](https://community.tradovate.com/u/Reymou_306)\
**Post date:** [January 14, 2024, 10:01am UTC](https://community.tradovate.com/t/cumulitivedeltawithema/7177/5 "2024-01-14T10:01:36Z")

</div>

Hi @khaled007622 , wondering if you can help me with something.  
I was trying to write a code which can highlight low volume prints.  
Like if you have ES1 with 100,200,800 contracts and suddenly 0/5 appears, whould you know how to highlight volume between 1-25 for example?

I was trying to figure it out from “VPOC of each bar” indicator, without success.

Thanks

MK
