gsoros / GTrader

a trading strategy trainer, back-tester and bot
GNU General Public License v3.0
83 stars 38 forks source link

Discussion (was: Can't run bots) #10

Open Lazur opened 6 years ago

Lazur commented 6 years ago

Hi. Firstly, thanks. Very interesting project, for educate myself also. I meet some problem. I create strategy and bot. But I can't run any bot, get the error from mysql and a lot of notice messages about undefined constants, mostly about indicators, as I understand. Is this possible on this step test the strategy? Could you please tell little bit, how it should work? Part of output.

Notice: Use of undefined constant TRADER_MA_TYPE_KAMA - assumed 'TRADER_MA_TYPE_KAMA' in /Applications/MAMP/htdocs/symfony_steps/GTrader-env/GTrader/config/GTrader/Indicators/Trader.php on line 11
PHP Notice:  Use of undefined constant TRADER_MA_TYPE_MAMA - assumed 'TRADER_MA_TYPE_MAMA' in /Applications/MAMP/htdocs/GTrader-env/GTrader/config/GTrader/Indicators/Trader.php on line 12

Notice: Use of undefined constant TRADER_MA_TYPE_MAMA - assumed 'TRADER_MA_TYPE_MAMA' in /Applications/MAMP/htdocs/GTrader-env/GTrader/config/GTrader/Indicators/Trader.php on line 12
PHP Notice:  Use of undefined constant TRADER_MA_TYPE_T3 - assumed 'TRADER_MA_TYPE_T3' in /Applications/MAMP/htdocs/GTrader-env/GTrader/config/GTrader/Indicators/Trader.php on line 13

Notice: Use of undefined constant TRADER_MA_TYPE_T3 - assumed 'TRADER_MA_TYPE_T3' in /Applications/MAMP/htdocs/GTrader-env/GTrader/config/GTrader/Indicators/Trader.php on line 13

[Illuminate\Database\QueryException]                                                           
  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `bots` where `status` = active)                                                       

  [PDOException]                             
  SQLSTATE[HY000] [2002] Connection refused  
Lazur commented 6 years ago

So, I understand my mistake and adjust database in .env. After execute docker exec -it gtrader_php_1 bash and inside of container

root@809c749d8270:/gtrader# php artisan bots:run 

  [ErrorException]                            
  array_merge(): Argument #1 is not an array  

This is still my mistake or error in code?

gsoros commented 6 years ago

Hi Kiril, thanks for trying out the software.

I have added a check for the case where the strategy does not emit any signals. Can you please try again?

Inside the container: git pull && su -c "php artisan bots:run" gtrader

Note that if you have any active bots they are automatically run by cron every minute, so be careful if you have entered your real exchange api key/secret and you have any balance on the exchange.

Please test your strategy carefully before activating it. You can check the strategy's performance by adding the "Balance" and "Signals" indicators on the Chart tab.

Good luck and let me know how it goes.

Lazur commented 6 years ago

Hi. Thanks for quick response. I did update, but still get error root@f6ac683d451b:/gtrader# su -c "php artisan bots:run" gtrader [ErrorException] array_merge(): Argument #1 is not an array

so be careful if you have entered your real exchange api key/secret and you have any balance on the exchange.

Yes sure, I'm not intend to use it with real account, before understand everything.

Please test your strategy carefully before activating it. You can check the strategy's performance by adding the "Balance" and "Signals" indicators on the Chart tab.

What does means "Signals" indicators? Balance is the result of applying strategy, like simulation without opening real orders? This is very close to what I want to do. I found your project, cos I'm looking in this direction. I want to create strategy and trading simulator for checking strategies and how it works. Is this possible to get you contact and ask few technical and conceptual questions? Thanks for inspiration 👍

Lazur commented 6 years ago

Yes. Now it works and I just need to adjust correct API. Thanks. Wrong API interface

gsoros commented 6 years ago

I think I found the bug that prevented bots from running. Feel free to reopen if still no go.

gsoros commented 6 years ago

Ok, one more thing, the bots will not not actually execute any orders unless APP_ENV=production in .env.

gsoros commented 6 years ago

Hi Kiril,

What does means "Signals" indicators?

Basically the logic is: the strategy emits a signal (either short or long) which you can display on the chart using the Signals indicator. Also the output of this indicator can be used by e.g. the Balance indicator. It is also possible to create more complicated chains using the custom settings on Signals.

Balance is the result of applying strategy, like simulation without opening real orders?

Yes.

This is very close to what I want to do. I found your project, cos I'm looking in this direction. I want to create strategy and trading simulator for checking strategies and how it works. Is this possible to get you contact and ask few technical and conceptual questions?

I'm not an expert, this is just a hobby project but I'll be happy to share what I found out :)

On Tue, Jul 25, 2017 at 8:07 AM, Kiril notifications@github.com wrote:

Yes. Now it works and I just need to adjust correct API. Thanks. Wrong API interface

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/gsoros/GTrader/issues/10#issuecomment-317639028, or mute the thread https://github.com/notifications/unsubscribe-auth/ALedWYu0eZZ8TML5pCx_fF6mf4tSFZlMks5sRYYTgaJpZM4OgwbV .

Lazur commented 6 years ago

Basically the logic is: the strategy emits a signal (either short or long) which you can display on the chart using the Signals indicator.

How I can recognize the type of signal? And this is about buy or sell? http://prntscr.com/fzyas2 This is looks like strategy is't good and balance was lost? http://prntscr.com/fzybrf

Do you have positive experiments, where strategy with some adjustments may predict the price and get some potential profit?

You did this SPA with just jQuery and bootstrap (and Laravel in back, for sure :) )? Thank you for answers :)

gsoros commented 6 years ago

How I can recognize the type of signal? And this is about buy or sell? http://prntscr.com/fzyas2

Yes, the green thingy means open long position (= buy), red thingy means open short position (= sell). I'm planning to add support for neutral position and take profit / stop loss in the future.

This is looks like strategy is't good and balance was lost? http://prntscr.com/fzybrf

At the last candle balance is around 197 so your initial balance of 100 has been doubled.

*** Correction I just noticed your initial cap was 204 so it's indeed a net loss.


Do you have positive experiments, where strategy with some adjustments may predict the price and get some potential profit?

I have had mixed results, some nice profits and some painful losses. Hard to distinguish luck from a good strategy. Given the nearly constant rise of Bitcoin price over longer time frames it has been difficult to beat the "buy and hold" strategy.

You did this SPA with just jQuery and bootstrap (and Laravel in back, for sure :) )?

SPA?

Thank you for answers :)

Thank you for your interest!

Lazur commented 6 years ago

SPA I mean - single page application.

Lazur commented 6 years ago

Did you think about to clear data in inputs into neural network, I mean remove extremums as first step? This is the first step in usual data mining process. Maybe it will helps to reduce false triggering of strategy.

gsoros commented 6 years ago

You can use for example EMA(Open, 5), EMA(Close, 5)... as your inputs, this will smooth out any extreme values but also introduce delay. Is this what you mean?

Lazur commented 6 years ago

Ah yes, this is very close is what I mean. Like this way how you implement the system.

gsoros commented 6 years ago

I'm glad somebody appreciates it. Make sure you share your reliable winning strategy with me when you find it :)

Lazur commented 6 years ago

Is this looks like successful strategy? screenshot-30-15-07

I don't know if "Balance" indicator is implemented correctly. I try to understand logic, but I can't handle app architecture in general.

Lazur commented 6 years ago

When I continue learning network more, result changed, but still not bad. screenshot 30 20-27-23

gsoros commented 6 years ago

Hi!

Is this looks like successful strategy?

That depends :) Has the network seen the data, i.e. was it trained on this range? It made some good trades but completely missed out on the big wave from 1900 to 2900.

The "mode=dynamic" setting can be deceptive because it invests less and less as the balance decreases and it will never actually lose all the balance. I have added a description on this field.

I don't know if "Balance" indicator is implemented correctly.

Well, it does not consider the liquidation price on leveraged trades, this one is in the todo.

I try to understand logic, but I can't handle app architecture in general.

I agree, the code is difficult to follow. The project started as a simple one-file script and as I added features it became quite complex at places. Maybe time for a complete rewrite?

Lazur commented 6 years ago

Very big thanks for comments in code. It should helps me. Maybe time for a complete rewrite? I want. But yes, not so much free time. Firstly I'm intend to call in mind theory of neural networks and learn PHP extensions (FANN and Trader, I did't know about it before and was intend to write even EMA by self). I like the way how strategy is works and generate signals(base on visual results). But still did't understand how the signals is generated, based on which data? How do you think, is this possible after training network create a new dataset, based on "expert" vision, where the signals should be placed and "correct" network.

That depends :) Has the network seen the data, i.e. was it trained on this range? Yes, it was trained on this range, here the little bit present data. screenshot at 31 12-55-13 Looks like balance works not correct when I try to scale chart. Try to check.

gsoros commented 6 years ago

I like the way how strategy is works and generate signals(base on visual results). But still did't understand how the signals is generated, based on which data?

It works something like this: Prediction(Strategy) -> Signals -> Balance

So the Strategy has some inputs and one output. The Prediction indicator takes a sample (which is an array of candles with the necessary indicators) and runs the associated Strategy on it. It outputs a single value which is the output of the net. Then it takes the next sample etc.

The Signals indicator takes the Prediction value and compares it to the open price, if Prediction is higher than 100.5% of open, it emits a long (buy) signal. Inverse for short (sell).

This is the default setup, you can customize many aspects of this flow.

How do you think, is this possible after training network create a new dataset, based on "expert" vision, where the signals should be placed and "correct" network.

Hmm, not sure, I think that's called supervised or reinforcement learning, haven't looked into that. You could extend the UI with a system to manually add signals and train the strategy on that data. The question is whether it could improve the performance...

Yes, it was trained on this range, here the little bit present data

Well, I think it's better to judge a strategy by how it performs on data it has not seen before. It is quite easy to train a network on a range and have a beautiful steadily climbing diagonal balance on that range but that does not tell much about how it would work with live data.

Looks like balance works not correct when I try to scale chart. Try to check.

Where do you see an error?

Lazur commented 6 years ago

Hi. As a small conclusion after long time investigation a get understanding and want to share with you what only RNN and LSTM especially networks may be useful for predict time series data, because this type remembers the previous state. Prediction of the price itself is a holy grail. I'm start to think in a direction of prediction(with LSTM and may be decisions tree) the right decision when to in and out of market, based on expert choice (select&generate successful decisions) and train network on this basis. Do not have a time and just share the idea.