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


Mã nguồn mở

Với tinh thần TradingView, tác giả của tập lệnh này đã xuất bản nó dưới dạng mã nguồn mở, vì vậy các nhà giao dịch có thể hiểu và xác minh nó. Chúc mừng tác giả! Bạn có thể sử dụng mã này miễn phí, nhưng việc sử dụng lại mã này trong một ấn phẩm chịu sự điều chỉnh của Nội quy nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?