TradingView
Seungdori_
Nov 26, 2022 3:42 AM

Grid Strategy Back Tester (Long/Short/Neutral) 

Bitcoin / TetherUS PERPETUAL CONTRACTBinance

描述

Preface
I'd like to send a thank you to @xxattaxx-DisDev.
The 'Line' Code, which was the most difficult to plan the Grid Indicator, was solved through the 'Grid Bot Simulator' script of @xxattaxx-DisDev.


A brief description of the indicators
These indicators are designed for backtesting of grid trading that can be opened on various exchanges.

Grid trading is a method of selling at particular intervals as prices rise and fall for gird interval price range.
This indicator is actually designed to see what the Long / Short / Neutral grid has achieved and how much it has achieved over a given period of time.


How to use

1. Lower Limit and Upper Limit are required when putting indicators on the chart.
After that, choose the 'Time' when to open the grid.
Also, select Long / Short / Neutral direction if necessary.

2. Statistics Table



Matched Grid shows how many grid pairs were engaged during the backtesting period.
The Daily Average Matching Profit is calculated based on the number of these closed grids.

Total Matching Profit is calculated as Matching Grid * Per Matching Profit.

Position Profit/Loss shows the benefits and losses from your current position.

Total Profit/Loss is sum of Total Matching Profit and Position Profit/Loss.

The Expanded APY shows the benefits of running the strategy on these terms for a year.

Max Loss of Upper is the maximum loss assumed to be directly at the top of the grid range.
BEP days (Upper) show how many days of maintenance relative to Average Matching Profit can result in greater profit than maximum loss if the grid continues to move within range.
(In the case of Long Strategy, it appears to be 'Min Profit', which shows minimal benefit if it reaches the top.)

Max Loss of Lower and BEP days (Lower) shows the opposite.
(In the case of Short Strategy, it is also referred to as 'Min Profit', which shows minimal benefit if it reaches the bottom.)

3. Grid Info



Total Grid Number, Upper Limit, and Lower Limit show the values you set in INPUT.

Grid Open Price shows the price for the period you decide to open.

Starting Position shows the number of positions that were initially held in the case of a Long / Short Strategy.
(0 for Neutral Strategy)

Per Grid qty shows how many positions are allocated to one grid
Grid Interval shows the spacing of each grid.
Per Matched Profit shows how much profit is generated when a single grid is matched.

Caution

Backtesting results for these indicators may vary depending on the time frame.
Therefore, I recommend that you use it only to compare Profit/Loss over time.

*In addition, there is a problem that all lines in the grid are not implemented, but it is independent of the backtest results.





--------------------------------------

서문

지표를 기획함에 있어서 가장 어려웠던 line 코드를 @xxattaxx-DisDev의 'Grid Bot Simulator' 스크립트를 통해 해결할 수 있었습니다.

이에 감사의 말씀을 드립니다.

해당 지표에 대한 간단한 설명
해당 지표는 다양한 거래소에서 오픈할 수 있는 그리드 매매에 대한 백테스팅을 위해 만들어졌습니다.
그리드매매는, 특정 가격 구간에 대해 가격이 오르고 내림에 따라 일정 간격에 맞춰 매매를 하는 방식입니다.
이 지표는 실질적으로 롱/숏/중립 그리드가 어떠한 성과를, 특정 기간동안 얼마나 냈는지를 확인하고자 만들어졌습니다.

사용방법

1. 인풋

지표를 차트위에 넣을 때, Lower Limit과 Upper Limit이 필요합니다.
그 후 그리드를 언제부터 오픈할 것인지를 선택하세요.
또, 필요하다면 Long / Short / Neutral의 방향을 선택하세요.

2. 그리드 통계

Matched Grid는, 백테스팅 기간동안 체결된 그리드 쌍이 몇개인지를 보여줍니다.
이 체결된 그리드의 갯수를 바탕으로 Daily Average Matched Profit이 계산됩니다.

Total Matched Profit은, Matched Grid * Per Matched Profit으로 계산됩니다.

Position Profit/Loss는, 현재 갖고 있는 포지션으로 인한 이익과 손실을 보여줍니다.

Total Matched Profit과 Position Profit/Loss를 합친 금액이 Total Profit/Loss가 됩니다.

Expcted APY는, 이러한 조건으로 전략을 1년동안 운영했을 때의 이익을 보여줍니다.

Max Loss of Upper는, 그리드 범위의 최상단에 바로 도달했을 경우를 가정한 최대 손실입니다.
BEP days(Upper)는, 그리드가 범위 내에서 계속 움직일 경우, Average Matched Profit을 기준으로 며칠동안 유지되어야 최대손실보다 더 큰 이익이 발생할 수 있는지를 보여줍니다.
(Long Strategy의 경우, ‘Min Profit’이라고 나타나는데, 최상단에 도달했을 경우 최소한의 이익을 보여줍니다)

Max Loss of Lower는 그 반대의 경우를 보여줍니다.
(Short Strategy의 경우, 역시 ‘Min Profit’이라고 나타나는데, 최하단에 도착했을 경우 최소한의 이익을 보여줍니다)

3. 그리드 정보
그리드 갯수, Upper Limt, Lower Limt은 자신이 설정한 값을 보여줍니다.

Grid Open Price는, 자신이 오픈하기로 정했던 기간의 가격을 보여줍니다.

Starting Position은, 롱/숏 그리드의 경우에 처음에 들고 시작했던 포지션의 갯수를 보여줍니다.
Neutral Strategy의 경우 0입니다.

Per Grid qty는, 하나의 그리드에 얼마만큼의 포지션이 배분되었는지를 보여주며
Grid Interval은 각 그리드의 간격을 보여줍니다.
또, Per Matched Profit은 하나의 그리드가 체결될 때 얼마만큼의 이익이 발생하는 지를 보여줍니다.


[주의]

이러한 지표에 대한 역테스트 결과는 시간 프레임에 따라 달라질 수 있습니다.
따라서 시간 경과에 따른 손익을 비교할 때만 사용하는 것이 좋습니다.
*추가로, 그리드의 라인이 모두 구현되지 않는 문제가 있지만, 백테스팅 결과와는 무관합니다.

版本注释

Thanks to @xxattaxx-DisDev

Line problem solved.

And I got put on 'DrawDown' on table.

When Max Draw Down is bigger than your Initial Capital, the 'Max Draw Down' will show red text color.

版本注释

Improved the calculation formula to make the backtest results more accurate.

版本注释

Upgraded to show when able to liquidation on background color.
评论
xxattaxx-DisDev
Wow. Nice work!
To add more lines:

indicator("Grid Strategy Back Tester", shorttitle = 'Grid Strategy Backtester', overlay=true, max_lines_count=500)
Seungdori_
@xxattaxx-DisDev, Thank you so much, sir! Thanks to you, I solved the problem. :)
Anonymous293848
안녕하세요 승도리님~~
오리군단 입니다 승도리님봇이 이거였군요.. 최대 그리드 숫자가 40개인가요?..
실력이 대단하신거같아요 저같이 알못은 뭐가뭔지 모르겠네요 ...ㅎㅎㅎ
실제 거래소 적용방법이나 이런걸 어떻게해야될지 참.. ㅠ
Seungdori_
@Anonymous293848, 안녕하세요!
아니에요 봇은 이거 아니고 따로 제가 전략 만든 거에요 ㅎㅎ
이건 거래소 적용용이 아니라, 그냥 트레이딩뷰에서 백테스팅 용으로 사용하는거에요! ㅎㅎ
Anonymous293848
@Seungdori_, 아 그렇군요..
개발하신 전략 이건 그리드가 최대 몇개까지인가요?
차트에 적용해보니 50개까지 되는거같기도하고..
Seungdori_
@Anonymous293848, 199개까지 되도록 해놨습니다~!
선은 표시 안되어도, 오른쪽 테이블에 떠있는 계산은 제대로 될거에요!
Anonymous293848
@Seungdori_, 아네알겠습니다 유용하게 쓰겟습니다.
저는 봇을 따로 개발하신줄알았어요ㅋㅋㅋㅋ
In_Finito_
This is great! Thank you for sharing it.
I have a script that calculates ideal ranges for any symbol based on standard deviations, been wanting to turn it into a grid bot and this helps a lot
Seungdori_
@In_Finito_, Thank you!
Recently, I've been working on a bot that trades grids according to current trends. Personally, I think I've developed a script that is quite satisfactory. If we could use your script in conjunction with mine, I'm confident we could create a truly effective grid bot.

Would you like to exchange ideas on this?
更多