Hi All,
need your help.
I am trying to code different codes in pythone. Can anyone help me code the below pine script code in python with one liner comment for my understanding
length = 14
source = close
mg = 0.0
mg := na(mg[1]) ? ema(source, length) : mg[1] + (source - mg[1]) / (length * pow(source/mg[1], 4))
I believe the pine documentation would be helpful to understand the structure of the code and identify which technical indicator is used. If you identify the indicator, it would be much easier to covert/find that particular indicator code in Python. Can refer to this documentation for the Python code for some of the technical indicators.
Thanks for the response.
This indicatotor is McGinley Dynamic. I couldn't find the solution to code it. If anyone helps to provide the solution that will be great
The formula gives McGinley Dynamic:
MDi = MDi-1 + (Pricei - MDi-1) / (N x (Price / MDi-1)4)
where,
MDi-1 is the exponential moving of the previous day's price
N is the number of period
There are three things to do in this:
- To calculate the exponential moving average in Python, use the pandas ewm() function, or this can be done using the Ta-Lib library. Can refer to this blog post to calculate the exponential moving average.
- To calculate the previous day's exponential moving average use shift() function.
- Finally, to calculate the fourth power of (Price / MDi-1), either use ** operator or pow() function.
Hope that helps!