yuya_takahashi_

zigzagストラテジーをつくる①|インジケーターを理解する1

Éducation
yuya_takahashi_ Mis à jour   
OANDA:USDJPY   Dollar Américain / Yen japonais
以前みつけた高勝率のzigzagストラテジーを再現する試みです。

まずは、zigzagインジケーターを作成します。

作成とは言っても、
すでにあるものを理解する作業。お勉強です。

モデルになるzigzagストラテジーは、
非常にシンプルなロジックのzigzagでした。
ただし、上の時間軸のzigzagを表示するというもの。

このアプローチでも良いのですが、
tradingViewやmt4で用いられているzigzagを
ちゃんと理解してすべてを検証できる状態をつくりたいと思います。

コツコツと地道にすすめていく予定です。
けっこう時間がかかると思いますが、気長にお付き合いください。

※ コピペする場合は以下の変更を行ってください
[](全角の角括弧)→(半角の角括弧)
(全角スペース)→(半角スペース)

=====
//@version=4
study("Zig Zag 勉強中", overlay=true)

// Depth = 深さ
depth = input(title="Depth", type=input.integer, defval=10, minval=1)

//**
//* depth -> length -> zero
//* lengthが最高値・最安値であるかを確認
//* trueならbar_indexと価格を返す
//*
pivots(src, length, isHigh) =>
 p = nz(src[length])

 if length == 0
  [bar_index, p]
 else
  isFound = true
  // length -> zeroの最高値・最安値を確認
  for i = 0 to length - 1
   if isHigh and src[i] > p
    isFound := false
   if not isHigh and src[i] < p
    isFound := false
  // depth -> lengthの最高値・最安値を確認
  for i = length + 1 to 2 * length
   if isHigh and src[i] >= p
    isFound := false
   if not isHigh and src[i] <= p
    isFound := false
  
  // lengthが最高値・最安値だった場合は値を返す
  if isFound and length * 2 <= bar_index
   [bar_index[length], p]
  // そうでない場合はnaを返す
  else
   [int(na), float(na)]

[iH, pH] = pivots(high, floor(depth / 2), true)
[iL, pL] = pivots(low, floor(depth / 2), false)

zigzag = pH>0 ? pH : pL>0 ? pL : na
plot( zigzag ,offset=-1*floor(depth / 2) ,color=color.red )
=====
Commentaire:
次の投稿

小次郎講師公式インジケーターのお申込
bit.ly/2vdSV4Q

小次郎講師のLINE@
bit.ly/2VZQFu3

小次郎講師のチャート情報局
bit.ly/2GvLAEp

Idées en relation

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.