Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trama #333

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Trama #333

wants to merge 12 commits into from

Conversation

bkamuz
Copy link

@bkamuz bkamuz commented Apr 25, 2023

Name : Tradingview "Trend Regularity Adaptive Moving Average"

I've using this indicator for strategy to determine flat market.

It works perfectly, but it seems to me that we can improve it by avoiding this loop operation. But alas, no matter how I tried to use for example numpy vector operations - no success. Maybe someone will have some thoughts on this? Thank you.q

@xmatthias
Copy link
Member

It works perfectly, but it seems to me that we can improve it by avoiding this loop operation. But alas, no matter how I tried to use for example numpy vector operations - no success. Maybe someone will have some thoughts on this? Thank you.

The moment you have point at time i depend on i-1, your only option is usually to loop, as the prior point directly influences the current datapoint.

Potentially, pandas' rolling() feature can help with this, and would probably be a safer option to support different usecases, as this will effectively have an indefinite lookback, as it's an expanding window starting with the very first candle.
Now the influence of the very first candle will decrease significantly over time - but in theory, you can still see a (very small, potentially disappearing due to float representation) difference 200 or 2000 candles into the dataframe by simply modifying the very first candle

@xmatthias
Copy link
Member

Please run black locally - it'll auto-fix the errors CI is pointing out ;)

@xmatthias
Copy link
Member

xmatthias commented May 26, 2023

Hi, sorry this took a while, finally had some time to look at this

Comparing the values to tradingview, it doesn't seem to fully align.
For example right before the long, red candle, this indicator is touching the green candle - but the tradingview one isn't.

are you sure the algorithm is corresponding to the tradingview variant?

image

image

technical/indicators/indicators.py Show resolved Hide resolved
Comment on lines 1290 to 1292
hh = ta.MAX(dataframe[field], length)
ll = ta.MIN(dataframe[field], length)
hhll = np.where(np.diff(hh) > 0, 1, 0) + np.where(np.diff(ll) < 0, 1, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct, actually.

The original pinescript is making the diff first, and then does the max on top of that.

hh = max(sign(change(highest(length))),0)
ll = max(sign(change(lowest(length))*-1),0)

so maybe something around this (incomplete, untested - and switched to pandas, as to me, that transports the intend better )

    change = df[field].diff()
    hh = np.maximum(np.sign(change.rolling(length).max()), 0)
    ll = np.maximum(np.sign(change.rolling(length).min()) * -1, 0)
     # ...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkamuz the latest changes don't really go into this topic ... what's your opinion on this ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants