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

Custom Strategy Based on My existing TV indicator #451

Closed
idristarwala opened this issue Dec 10, 2021 · 4 comments
Closed

Custom Strategy Based on My existing TV indicator #451

idristarwala opened this issue Dec 10, 2021 · 4 comments
Labels
good first issue Good for newcomers info Informational

Comments

@idristarwala
Copy link

Hi,

First of all thanks for creating a great library, this is a game changer.

I have been predominantly using Trading View, I have build many indicators on TV and use them in my daily trading. You can consider them proprietary Algo which are combination of use of basic building blocks all of which are already present in pandas-ta lib.

So my indicator uses a combination of Previous Day High/Low values, Premarket High/low values, EMAs, candle colors , volume pressure, ADR/ATR , curve , pivot points etc.

In a combination, which then results in a buy/sell signal along with take profit and exit signals

I have also been able to create most of it in my Python code using this lib as individual columns in the DF.

What I don't understand is how to now transfer this price of logic into Strategy Class to take advantage of the watch function etc.

Is there an example where I can pass in a function which creates a result column in the DF ?

Regards,
Idris

@idristarwala
Copy link
Author

idristarwala commented Dec 10, 2021

For Example :-

#Strategy Definition
strategy = [
    {"kind":"sma"},
    {"kind":"bbands"},
    {"kind":"macd"},
    {"kind":"rsi"},
    {"kind":"supertrend"},
    {"kind":"mfi"}
]

When defining a strategy like this we can pass in multiple inbuilt indicators. I want to pass in my own function which has custom logic to generate the buy/sell signals.

#Strategy Definition
strategy = [
    {"custom_function": customFunction()}
]

something like this.

@twopirllc twopirllc added good first issue Good for newcomers info Informational labels Dec 11, 2021
@twopirllc
Copy link
Owner

Hello @idristarwala,

First of all thanks for creating a great library, this is a game changer.

Thank you. I appreciate it!

I have been predominantly using Trading View, I have build many indicators on TV and use them in my daily trading. You can consider them proprietary Algo which are combination of use of basic building blocks all of which are already present in pandas-ta lib

That's how I started out as well. I have ported a few indicators from TV into Pandas TA also.

I have also been able to create most of it in my Python code using this lib as individual columns in the DF.

Excellent!

What I don't understand is how to now transfer this price of logic into Strategy Class to take advantage of the watch function etc.

I assume you are referring to the example Watchlist Class as shown in the Pandas TA Strategy Examples Notebook.

In order to use your custom_function(), you will first need to create it and hook it up to the DataFrame Extension Class ta by following the pinned Issue #355 Creating a Custom Indicator: The Big 4 (in particular Step 2).

#Strategy Definition
strategy = [
    {"custom_function": customFunction()}
]

Then you should be able to load the strategy into the watchlist and run like so (Pandas TA Strategy Examples Notebook.
):

Screen Shot 2021-12-12 at 3 21 00 PM

Note: Since you are running one indicator, custom_function(), through df.ta.strategy(), make sure to pass cores=0 before it runs so that multiprocessing is disabled. Spinning up the multiprocessing pool for one indicator is time consuming despite how many indicators you have within your custom_function(). Also df.ta.strategy() does not look into indicators to determine whether to apply multiprocessing or not. However if you have a bunch of indicators in which multiprocessing is needed then you will need a different approach altogether.

Hope this helps! Let me know otherwise. Apologies for the delayed response.

Kind Regards,
KJ

@idristarwala
Copy link
Author

@twopirllc thanks for your detailed response. I will try this out on the weekend.

@twopirllc
Copy link
Owner

Hello @idristarwala,

I assume by no response that the solution provided was sufficient. Thus I will be closing this issue in a few days.

Kind Regards,
KJ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers info Informational
Projects
None yet
Development

No branches or pull requests

2 participants