Comments (4)
if you're stuck at some line - best share what you have so far, so we can determine where the most likely error is ?
from technical.
Thanks for responding, appreciate it. I have gotten this far. Basically i have verified that deviation dev
is correct and matching trading view values. Where I am stuck is these 3 lines from the pine version
a=0.,a := src > nz(a[1],src) + dev ? src : src < nz(a[1],src) - dev ? src : nz(a[1],src)
upper = valuewhen(change(a),a + dev,0)
lower = valuewhen(change(a),a - dev,0)
Below is my python version (non optimized). I am using pandas ts for stddev
, mom
calculation which is equivalent of change
import pandas_ta as ta
## dfInd is the input dataframe that contain ohlcv data
length = 100
fast = 50
slow = 200
src = dfInd['Close'] # control src : Close, hl2, hlc3, etc
slowChange = ta.mom(src,length=length).abs()
fastChangeSum = ta.mom(src,length=1).abs().rolling(length).sum()
er = slowChange/fastChangeSum
dev = er*ta.stdev(src*2,fast) + (1-er)*ta.stdev(src*2,slow) # verified and correct
## ------------- Code below this line is where i am struggling !!
a = pd.DataFrame(0., index=dfInd.index, columns=['a'])
a=a['a']
# len(src.values)
# len(src.shift().fillna(0).values)
# # a['a'] = src.shift().fillna(0).values
value = np.where(a.shift(1).notnull(), a, src)
tsc = np.where (src > value + dev , value, src)
# tsc = np.where (src > value + dev , src, (np.where (src < value - dev , src , value)))
dfInd['TSC'] = tsc
dfInd['TSCdev'] = dev
# ----------- not reached to upper and lower bands calculations yet
# chang_a = ta.mom(dfInd['TSC'],1)
# dfInd['TSC_U'] = dfInd['TSC'] + dev
# dfInd['TSC_L'] = dfInd['TSC'] - dev
Appreciate if you can take a look at it.
from technical.
a[1]
is referencing the prior row.
as this happens as part of the assignment to a - this means that you cannot really vectorize this indicator - but you'll have to loop - as the result of each row depends on the result from the calculation of the prior row.
You can find an example for this for example here:
technical/technical/indicators/indicators.py
Lines 1002 to 1007 in 7accaf5
Obviously, this will have a quite severe performance penalty - as you'll loop through a dataframe with potentially 1000nds rows.
from technical.
I understand what you are referring. Thanks for the quick response.
I will try out just looping through as you suggested here and see what results i get.
from technical.
Related Issues (20)
- Resampled dataframes are shifted 1 candle. HOT 4
- resample_to_interval date shifted HOT 1
- Help with Trend Trader Strategy HOT 1
- ichimoku different value proposal HOT 1
- How to import external data to populate entry/exit trend conditions HOT 14
- Multiple timeframe merge HOT 10
- Laguerre RSI wrong computation HOT 3
- ```crossed``` function throws error with numpy integers
- utils bug HOT 4
- How to plot segtrends or gentrends using freqtrade plot-dataframe ? HOT 1
- Phase Change Index HOT 18
- I try to convert Predictive Ranges [LuxAlgo] to the py, whats the problem? HOT 7
- Involvement of Heikenashi candles could be helpful in trend prediction HOT 1
- Help needed with: AttributeError: 'SSL' object has no attribute 'copy' HOT 3
- warning util.py
- 16 tests failed HOT 4
- Pandas warning when setting fillna(0) on RMI calc HOT 2
- Issues with PMAX indicator HOT 1
- A few Pinescript lines HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from technical.