yvponce

Slippage Calculator

Hello everyone,


This is the first script I publish, also my English is not the best my apologies.

This simple study script is an attempt to estimate the slippage during a trade. By no means it is a precise calculation, it is just an approach that can be improved.

You are welcome to take this simple script and use it and change it at your convenience just ask your acknowledge.
My approach considers the total fluctuation the price gets as a consequence for the total volume on that specific bar.
The volume on each bar is given in BTC, thus you get that by using the formula.

vol = volume * vwap

The total variation in price is considered as twice the size of the bar plus the gap between to consecutive bars. that is the
total fluctuation of price on each bar = (2 * (high - low) + abs(open - close)) which is not totally true since inside each bar price can fluctuate a lot more.
The script considers you are trading your total equity (eq_BTC ) each time. The fraction of your equity of the volume bar is eq_BTC / vol
Then eq_BTC / vol is the portion or the total fluctuation in price that is due to your entry or exit from the market.

(2 * (high - low) + abs(open - close)) * eq_BTC / vol
is the average change in price due you enter o exit a position.

** the 2 factor accounts for the two directions in the market buying and selling. There is more behind this formula I can explain you in more detail if you like.

I haven't seen anywhere a formula like this one, so it is intended to be a first attempt to get a better approach.

Finally the output of the scripts is how many ticks the price might change due to your trade on each bar

round(slippage/syminfo.mintick)

The script is focused in crypto but it can be used as well on forex markets.

Take care,

@yvponce


Script open-source

Dans le véritable esprit de TradingView, l'auteur de ce script l'a publié en open-source, afin que les traders puissent le comprendre et le vérifier. Bravo à l'auteur! Vous pouvez l'utiliser gratuitement, mais la réutilisation de ce code dans une publication est régie par le règlement. Vous pouvez le mettre en favori pour l'utiliser sur un graphique.

Clause de non-responsabilité

Les informations et les publications ne sont pas destinées à être, et ne constituent pas, des conseils ou des recommandations en matière de finance, d'investissement, de trading ou d'autres types de conseils fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.

Vous voulez utiliser ce script sur un graphique ?