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

IMPROVEMENT: New ApMode -> 3 EWMA System #115

Closed
Camille92 opened this issue May 31, 2017 · 19 comments
Closed

IMPROVEMENT: New ApMode -> 3 EWMA System #115

Camille92 opened this issue May 31, 2017 · 19 comments

Comments

@Camille92
Copy link

Camille92 commented May 31, 2017

Hello Carles and everyone,

I keep going with my "one improvement a week" idea, but this one is easy to implement and will, hopefully, give big rewards.

The concept is to ameliorate today's ewma basic by adding to it more ewma.
Originally this is a scalping strategy that I adapted for Tribeca. It should be faster to react to the market while still keeping into account longer ewma.
Read more here https://www.forexstrategiesresources.com/scalping-forex-strategies/2-scalp-with-emapredictive/ and here http://www.profitf.com/forex-strategies/3-ema-scalping-system-1-min/

1) Necessary and configurable parts:

Recommanded default values:
ewmaLong : 200, ewmaMedium: 100, ewmaShort: 50, sensibility: 0.5%

The sensibility represents the % you have between 2 ewma to activate a target position of nothing or everything. It is currently configured at 0.2% for Tribeca.
I recommend using 0.5% because we're going to add percentages.

2) Calculation:

Here is the original formula of EWMA basic:
let newTargetPosition = ((this.newShort * 100/ this.newLong) - 100) * 5;
in https://github.com/ctubio/tribeca/blob/master/src/server/position-management.ts

If 3EWMA mode is activated, here is what the calculation should look like:

let newTrend = ((this.SMA3 * 100/ this.newLong) - 100);
let newEwmacrossing = ((this.newShort * 100/ this.newMedium) - 100);
let newTargetPosition = ((this.trend + this.ewmacrossing)/2) * (1/sensibility);

3) Explanation

What we do here is to determine a trend, so if the market is above or under the ewmaLong and we add to it a shorter term crossover.

If the trend is up new Trend will be positive and add positive value to the TP calculation.
If it's negative, it will give a negative value to TP calculation.
Same for ewma crossing.

In practice, it means that -> if we have both a positive crossing and the market above the trend line, TBP position will be high.

If both are negative -> TP will close to 0

If one is negative and the other one positive, TP will be around neutral and its sign will depend on the strength of the movement.

4) Comparison with EWMA Basic:

3 ewma: (50,100, 200)
capture d ecran 2017-05-31 a 17 56 47
ewma classic: (100, 200)
capture d ecran 2017-05-31 a 17 56 13

Please tell me what you think and if you have any questions!

Ps: We can link that to #114 with the idea of making ewmaShort, Long, sensibility and time interval customizable !

@ctubio
Copy link
Owner

ctubio commented May 31, 2017

so this is to replace the current EWMABasic (long and short) with 3 (long, medium, short?)

or you wanna keep current EWMABasic functionality available to be selected too?

@Camille92
Copy link
Author

I think keeping the Ewma basic can't hurt! And it follows the logic of the "more option the better".

I wanted to do it, but I don't know where is the length of an ewma defined in Tribeca.

Ps: Thank you for the "genius improvement" I'm very flattered!

@ctubio
Copy link
Owner

ctubio commented May 31, 2017

coOl ok lets keep all options 💃

i believe thats what caused all my confusion with ewma value, cos at the end is pretty simple concept xD

the issue is that currently tribeca calculcates the ewma values using the accumulated calculated value, not the sequence of recorded values.

Using https://github.com/ctubio/tribeca/blob/master/src/server/main.ts#L76 at https://github.com/ctubio/tribeca/blob/master/src/server/statistics.ts#L44 where newValue is the current fair value, alpha is a variable representing both ewmaLong and ewmaShort defined at the top of main.ts (first link), and previous is the last ewma value calculated,

So, every 10 minutes - lets say, tribeca takes the fair value, the last ewma, and the magic factor ewmaLong or ewmaShort from main.ts to calculate the next current ewma value. no need for a sequence.

Then, if we want to modify this as you said, or we start using a sequecnce of recorded periods with customizable length, or otherwise we need to work with this magic factor value, that is not easy to understand at the first glance for the normal (like me) user. (is neat for computing resources, but is not easy to make use of it from the human point of view)

how feels in your body? xD

@Camille92
Copy link
Author

Hum I see,

I'm not 100% sure how to adjust this vector.
Is 4*0.095 then the ewma 50?

Otherwise, I bumped into that googling https://github.com/fredrick/gauss#vectorema would that be easier and efficient?

@ctubio
Copy link
Owner

ctubio commented May 31, 2017

yea lets grab that function xD seems more robust for sure; then lets continue trying to customize it using the new ewma function xD awesome plan'¡

@Camille92
Copy link
Author

Yeahh! So cool and it offers a lot of stats tools to play with them after! :)

@Camille92
Copy link
Author

Ps: For the sake of easy comparison with ewma classic in the definition of sensibility. I think it's better to use the average of 2.
It doesn't change anything but we're still able to use the 0.2% setting like before :)

So:
let newTargetPosition = ((this.trend + this.ewmacrossing)/2) * (1/sensibility)

ctubio added a commit that referenced this issue Jun 3, 2017
To support commits at ctubio/tribeca,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>
@ctubio
Copy link
Owner

ctubio commented Jun 3, 2017

ok so now we have medium ewma, but i dont think sensibility should be a customizable value (cos i dont see it as an option in any other charts out there where you can confiugure some ewmas [not because i have an idea xD])

do you really think sensibility should be customizable?

@Camille92
Copy link
Author

Hey yes, I still think so haha.

It can be seen as a trigger in case of false breakout, it can be particularly interesting if someone chooses to use smaller ewma :).

You can find an example here https://gekko.wizb.it/docs/strategies/example_strategies.html

it's what's usually referred to as the "threshold" :)

@Camille92
Copy link
Author

A general argument in favor of customization is that any trading strategy, as good as it can be if it is used by a lot of people will not work at all.

So by having different settings we assure that the probability for two Tribeca' users to have the same strategy is greatly reduced. In the end, this makes Tribeca stronger for having extra people to use it without killing everyone's profit :)

@ctubio
Copy link
Owner

ctubio commented Jun 4, 2017

ok so, 1 sensibility or 2 customizable sensibilities?

cos we have ewma protection but also ewma position rebalancing :S

ty for your time''

@Camille92
Copy link
Author

Only one for the ewma position rebalancing because this one acts as a "buffer" to TBP. It allows having values between 0 and full BTC for your tbp.

The other one is just a protection, using the ewma as a minimum value. If we want this one to be more reactive we just change the length of the ewma :)

@ctubio
Copy link
Owner

ctubio commented Jun 4, 2017

ah yea i understand now xD

@ctubio
Copy link
Owner

ctubio commented Jun 4, 2017

ok so last quesiton i hope:
what means SMA3 in:

let newTrend = ((this.SMA3 * 100/ this.newLong) - 100);
let newEwmacrossing = ((this.newShort * 100/ this.newMedium) - 100);
let newTargetPosition = ((this.newTrend + this.newEwmacrossing)/2) * (1/sensibility);

SMA3 is the result of calculate the ewma of the fair value using 3 periods? so the alpha variable for SMA3 should be: 2 / (3 + 1), no?

theen.. is not ewma3 same as sma3? xD

@Camille92
Copy link
Author

Hey no problem for the questions,

SMA is the simple moving average of the price it means:
SMA(3) = (FV(-2) + FV (-1) + FV (latest)) /3

But after looking at a chart they look very very very similar so EWMA 3 or 5 or SMA 3 or 5 should all do the job perfeclty. (Look at the chart below).

What we need here is just a very very short average that reflects the current price BUT are not subject to a 1mn explosion of the price. :)

capture d ecran 2017-06-04 a 21 02 15

@ctubio
Copy link
Owner

ctubio commented Jun 4, 2017

ok finally something easy :D many thanks'¡

@ctubio ctubio closed this as completed in 430fa87 Jun 4, 2017
@ctubio
Copy link
Owner

ctubio commented Jun 4, 2017

hope you dont miss nothing'¡ as far as i could test is niiiiice

@ctubio
Copy link
Owner

ctubio commented Jun 4, 2017

ah yea we miss EwmaBasic now xD will recover tomorrow

ctubio added a commit that referenced this issue Jun 4, 2017
To support commits at ctubio/tribeca,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>

To support commits at ctubio/tribeca,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>
@Camille92
Copy link
Author

Yess it looks good!

I need a few days to see if it's giving good results as expected but so far so good!

ctubio added a commit that referenced this issue Aug 1, 2017
Free Software Free Society

To support commits by ctubio,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>
ctubio added a commit that referenced this issue Aug 2, 2017
Free Software Free Society

To support commits by ctubio,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>
ctubio added a commit that referenced this issue Aug 2, 2017
Free Software Free Society

To support commits by ctubio,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>
ctubio pushed a commit that referenced this issue Aug 2, 2017
ctubio added a commit that referenced this issue Aug 2, 2017
Free Software Free Society

To support commits by ctubio,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>
ctubio pushed a commit that referenced this issue Aug 2, 2017
ctubio added a commit that referenced this issue Aug 2, 2017
Free Software Free Society

To support commits by ctubio,
you can buy-me-a-drink with a small git tip at:
  1GitTipgxvKB3zjCLXRcSgDhC9pivkpc7u

I promise to drink chocolate milk in the development of the next commit.

To request new features or in case this commit breaks something for you,
please create a new github issue with all possible details,
but never share your API Keys!

Signed-off-by: Carles Tubio <ctubio@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants