Ccxt: code for calculating EMA Exponential Moving Average on any Poloniex market

Created on 29 Nov 2017  Â·  3Comments  Â·  Source: ccxt/ccxt

hi Igor and community,
it's not an issue, but i publish here because not under oop coding
here is my little contribution on ccxt
for poloniex a python 3.5 function that compute the last value of ema for any pair

you need to call: calculema(300,14,'BTC','AMP')
for a periodic of 300 seconds and on 14 hours historical data of AMP/BTC market

import requests
import json
import time
import urllib.request
import pandas as pd
import numpy as np

def ExpMovingAverage(values, window):
    weights = np.exp(np.linspace(-1., 0., window))
    weights /= weights.sum()
    a =  np.convolve(values, weights, mode='full')[:len(values)]
    a[:window] = a[window]
    return a


def calcalema(period1,hrsnumbers,basesur,cur):
    # period1 300, 900, 1800, 7200, 14400, and 86400
    rightnow=time.time()
    url ='https://poloniex.com/public?command=returnChartData&currencyPair='+basesur+'_'+cur +'&start=' + str(int(rightnow - hrsnumbers*60*60)) + '&end=9999999999&period='+ str(period1)

    rrie = requests.get(url)
    r2rie=rrie.json()

    lescloses=list()
    for i in r2rie:
        for key,val in i.items():

            lescloses.append(i['close'])


    return  ExpMovingAverage(lescloses, period1)

Most helpful comment

i think -1.0 in linspace must be 1.0 in positive to add more weight to recent data not old data

All 3 comments

Thank you!

I'm sure Python coders will find this contribution useful for learning and for practical purposes as well!

I can't really integrate this code into ccxt, because statistical calculations are beyond the scope of the library for now, that is why we have numpy (used in the above example) and other cool standalone libs for that which can be combined with ccxt to cover most of the needs. I'll leave this issue open for a while.

yes i know that, Igor, it was just to give you insurance that's if i can
give a hand it would be with an infinite pleasure
that was for EMA indicator, most traders use it

for now, i'm studying a lilltle bit OOP aproach to increase my level
good bye

On Wed, Nov 29, 2017 at 7:43 PM, Igor Kroitor notifications@github.com
wrote:

Thank you!

I'm sure Python coders will find this contribution useful for learning and
for practical purposes as well!

I can't really integrate this code into ccxt, because statistical
calculations are beyond the scope of the library for now, that is why we
have numpy (used in the above example) and other cool standalone libs for
that which can be combined with ccxt to cover most of the needs. I'll leave
this issue open for a while.

—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/ccxt/ccxt/issues/713#issuecomment-347956131, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AeW22e2Txe13fsQHK95XSXFnPImLmgy0ks5s7aW2gaJpZM4QvbR5
.

i think -1.0 in linspace must be 1.0 in positive to add more weight to recent data not old data

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaardiolor picture gaardiolor  Â·  3Comments

jjhesk picture jjhesk  Â·  3Comments

Fcl69 picture Fcl69  Â·  3Comments

werewere picture werewere  Â·  3Comments

nashse picture nashse  Â·  3Comments