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


오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?