Gekko Forum
Adding Events to your strategy - Printable Version

+- Gekko Forum (
+-- Forum: Gekko (
+--- Forum: Guides (
+--- Thread: Adding Events to your strategy (/thread-58031.html)

Pages: 1 2 3

Adding Events to your strategy - Hallonstedt - 11-05-2019

There are a large number of Events with interesting data that are emitted by the Gekko plugins. Some would be quite useful in strategies but they are not available for the simple reason that strategies are not plugins and therefore cannot directly pick up the triggered events.

My quest was initially to be able to read live portfolio data as I have two strategies running in parallell and I need to know if I am exposed or not. I also want the strategy to react correctly to manual changes in the portfolio. I have since added more events that have proven quite useful.

Before using this guide, please be aware that it requires changes to two core Gekko plugins, meaning that if you update Gekko your changes are lost and the strategy will not work. It may also mean you break something else if you are not careful.

That being said, it is quite easy to do. Let's add the PortfolioChange event (~ is your Gekko root folder);
Edit ~/plugins/tradingAdvisor/tradingAdvisor.js and add:
Actor.prototype.processPortfolioChange = function(portfolio) {  // This must be the handler name. The parameter name can be made up (portfolio). Just be consistent.
  this.strategy.processPortfolioChange(portfolio);  // This will be executed in baseTradingMethod.js

Edit ~/plugins/tradingAdvisor/baseTradingMethod.js and add:
Base.prototype.processPortfolioChange = function(portfolio) {
  this.onPortfolioChange(portfolio);  // onPortfolioChange will be accessible in the strategy

In your strategy, onPortfolioChange will trigger when the portfolio has changed so you can read the asset and currency variables. This is independent of your candle size so this can trigger at any moment. Add, for example;
strat.onPortfolioChange = function (portfolio) {'Portfolio has changed; Asset=', portfolio.asset.toFixed(3), 'and Currency=', portfolio.currency.toFixed(0) );

That's it! 

Follow the same logic for any other Events. This adds Balance updates;
Edit ~/plugins/tradingAdvisor/tradingAdvisor.js and add:
Actor.prototype.portfolioValueChange = function(balance) {

Edit ~/plugins/tradingAdvisor/baseTradingMethod.js and add:
Base.prototype.portfolioValueChange = function(balance) {

In your strategy, add:
strat.onBalanceChange = function (balance) {'Balance has changed; it is now', balance.balance.toFixed(1) );

RE: Adding Events to your strategy - nicolesmith - 06-03-2020

You have to characterize what achievement intends to you. They ought to have explicit numeric results. , you may would like to play moviestarplanet download pc on your pc.  Start you social game experience today.

RE: Adding Events to your strategy - DenisSchinner - 11-24-2020

Yes i use to watch the program initially it was started but later on i have missed the episodes due to busy with my dragon resume review works. But i feel so embarrassed that being human why people behave in such weird ways doing weird things. But they has listed best things.

RE: Adding Events to your strategy - Xavier32 - 08-03-2021

It turns out that even the hottest port has a few places where you can get off the beaten path. Here are some recommendations that will make you feel like you're in the know face mask

RE: Adding Events to your strategy - Xavier32 - 08-06-2021

Your post has those facts which are not accessible from anywhere else. It’s my humble request to u please keep writing such remarkable articles 토토사이트

RE: Adding Events to your strategy - Xavier32 - 08-07-2021

A debt of gratitude is in order for posting this information. I simply need to tell you that I simply look at your site and I discover it exceptionally fascinating and educational. I can hardly wait to peruse bunches of your posts. Iron Railings Toronto

RE: Adding Events to your strategy - cryptocurrency0 - 08-16-2021

Appreciate it intended for placing a really good document! I stumbled upon your blog perfect for the desires. Its full of superb in addition to very helpful threads. Sustain the favorable do the job!

RE: Adding Events to your strategy - cryptocurrency0 - 08-20-2021

A very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. I was exactly searching for. Thanks for such post and please keep it up. Great work

RE: Adding Events to your strategy - lucifar - 08-31-2021

I want to say thanks for beautiful blog sharing with us. Your blog really great resource to update my knowledge. voirfilms

RE: Adding Events to your strategy - lucifar - 08-31-2021

For a long time me & my friend were searching for informative blogs, but now I am on the right place guys, you have made a room in my heart! Art