> For the complete documentation index, see [llms.txt](https://boitoki.gitbook.io/barbwire/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://boitoki.gitbook.io/barbwire/knowledge/nano.md).

# 最適な期間の探求

最適な期間として1スイングのバーの数を使う。\
ピボットハイとピボットローから1スイングのバーの数を割り出す。

```
pvtLength       = input.int(16)
pvtHigh         = ta.pivothigh(pvtLength*2, pvtLength)
pvtLow          = ta.pivotlow (pvtLength*2, pvtLength)
var x1          = 0
var x2          = 0

if not na(pvtHigh)
    x1 := bar_index

if not na(pvtLow)
    x2 := bar_index

period = math.abs(x2 - x1)
```
