yuya_takahashi_
教育

zigzagストラテジーをつくる⑧|ストラテジーを作成する3

FX:USDJPY   米ドル/円
今日は、以下の機能を実装してみました。

①.損切りの損失を資金のN%とする取引量を算出
②.レバレッジを考慮した取引量を算出
③.②を上限として①の取引量でトレードする

まず、①の算出ですが、
このストラテジーは損切り幅が明確なので、
以下の計算式で算出することができます。

/////////////////
// 損切り幅を算出
range = abs( close - target01_sl )

//「1トレードに当てる資金 / 損切り幅」で取引量を算出
// 同時に、round( 取引量 /lot ) * lot で取引単位(1000通貨等)に四捨五入してる
amount = round( unit_value / range / lot ) * lot
/////////////////

次に②の算出です。

これは、どういうことをするかというと、
「あるレバレッジで取引できる最大の取引量を算出する」
ということです。

これは、以下の計算式で算出します。

/////////////////
max_amount = floor( ( balance - unit_value * 1.1 ) / ( close / reverge ) )
/////////////////

まず、「close / reverage」で1通貨あたりの証拠金を求めます。
(ドル円が100円でレバ25倍なら、1通貨の証拠金は4円)

あとは、現在の残高で何通貨取引できるかを算出すれば良いので、
「balance / 1通貨の証拠金」とすれば良いですね。

その他の細かな調整として、小数点以下を切り捨てたり(floor)、
そのトレードが損失だったとしても強制ロスカットにならないように
「balance - unit_value * 1.1」を算出したりしています。

5分足でのストラテジーを目指しているので、
このあたりはできるだけリアルにしていく必要があります。

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

/////////////////
//@version=4
strategy( title='ZigZag PA Strategy 勉強中', shorttitle='S', overlay=true, pyramiding=0, initial_capital=100000 )

dev_threshold = input( title="Deviation (%)", type=input.float, defval=0, minval=0, maxval=100 )
depth = input( title="Depth", type=input.integer, defval=6, minval=1, maxval=10 )



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

  if length == 0
    [bar_index, p]
  else
    isFound = true
    for i = 0 to length - 1
      if isHigh and src[i] > p
        isFound := false
      if not isHigh and src[i] < p
        isFound := false
    for i = length + 1 to 2 * length
      if isHigh and src[i] >= p
        isFound := false
      if not isHigh and src[i] <= p
        isFound := false
    
    if isFound and length * 2 <= bar_index
      [bar_index[length], p]
    else
      [int(na), float(na)]

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

// 変化率を算出する関数
calc_dev(base_price, price) =>
  100 * (price - base_price) / base_price

// 前回のpivotの情報を格納
var line lineLast = na   // lineのid (実際はidではなく識別している何か)
var float pLast = 0     // price
var bool isHighLast = true // High か Low か
var int  linesCount = 0
var bool isNewPivot = false

// pivotを確認する関数
pivotFound(dev, isHigh, price) =>
  if linesCount == 0
    [line(na), isHigh, true]
  else
    if abs(dev) >= dev_threshold
      [line(na), isHigh, true]
    else
      [line(na), isHighLast, false]

// 描画処理
if not na( pH ) and not na(pL) and pH == pL
  dev1 = calc_dev(pLast, pH )
  [id2, isHigh2, isNew2] = pivotFound(dev1, true, pH )
  if isNew2
    linesCount := linesCount + 1
    isHighLast := isHigh2
    isNewPivot := true
    pLast := pH
  dev2 = calc_dev(pLast, pL)
  [id1, isHigh1, isNew1] = pivotFound(dev2, false, pL)
  if isNew1
    linesCount := linesCount + 1
    isHighLast := isHigh1
    isNewPivot := true
    pLast := pL
else
  if not na( pH )
    dev1 = calc_dev(pLast, pH )
    [id, isHigh, isNew] = pivotFound(dev1, true, pH )
    if isNew
      linesCount := linesCount + 1
      isHighLast := isHigh
      isNewPivot := true
      pLast := pH
  else
    if not na(pL)
      dev2 = calc_dev(pLast, pL)
      [id, isHigh, isNew] = pivotFound(dev2, false, pL)
      if isNew
        linesCount := linesCount + 1
        isHighLast := isHigh
        isNewPivot := true
        pLast := pL

// 追加箇所
zigzag = pLast[1]!=pLast ? pLast : na
plot( zigzag ,color=color.red ,linewidth=3 ,title='zigzag' ,offset=-1*floor(depth / 2) )
bgcolor( isHighLast ? color.gray : color.white ,offset=-1*floor(depth / 2) )

// ジグザグが発生したときのジグザグの値を取得
float x = na
float a = na
float b = na
float c = na
float d = na

exist_zigzag = not na( zigzag ) and not isHighLast==isHighLast[1]
repaint = not na( zigzag ) and isHighLast==isHighLast[1]

x := exist_zigzag ? a[1] : x[1]
a := exist_zigzag ? b[1] : a[1]
b := exist_zigzag ? c[1] : b[1]
c := exist_zigzag ? d[1] : c[1]
d := exist_zigzag ? zigzag
 : not repaint ? d[1]
 :   isHighLast and pLast > pLast[1] ? zigzag
 : not isHighLast and pLast < pLast[1] ? zigzag
 : d[1]

showPatterns = input( true, title='Show Patterns' )
showFib0000 = input( title='Display Fibonacci 0.000:', type=input.bool, defval=true )
showFib0236 = input( title='Display Fibonacci 0.236:', type=input.bool, defval=true )
showFib0382 = input( title='Display Fibonacci 0.382:', type=input.bool, defval=true )
showFib0500 = input( title='Display Fibonacci 0.500:', type=input.bool, defval=true )
showFib0618 = input( title='Display Fibonacci 0.618:', type=input.bool, defval=true )
showFib0764 = input( title='Display Fibonacci 0.764:', type=input.bool, defval=true )
showFib1000 = input( title='Display Fibonacci 1.000:', type=input.bool, defval=true )

fib_range = abs(d-c)
fib_0000 = not showFib0000 ? na : d > c ? d - ( fib_range * 0.000 ) : d + ( fib_range * 0.000 )
fib_0236 = not showFib0236 ? na : d > c ? d - ( fib_range * 0.236 ) : d + ( fib_range * 0.236 )
fib_0382 = not showFib0382 ? na : d > c ? d - ( fib_range * 0.382 ) : d + ( fib_range * 0.382 )
fib_0500 = not showFib0500 ? na : d > c ? d - ( fib_range * 0.500 ) : d + ( fib_range * 0.500 )
fib_0618 = not showFib0618 ? na : d > c ? d - ( fib_range * 0.618 ) : d + ( fib_range * 0.618 )
fib_0764 = not showFib0764 ? na : d > c ? d - ( fib_range * 0.764 ) : d + ( fib_range * 0.764 )
fib_1000 = not showFib1000 ? na : d > c ? d - ( fib_range * 1.000 ) : d + ( fib_range * 1.000 )
plot( title='Fib 0.000', series=fib_0000 ,color=fib_0000 != fib_0000[1] ? na : color.black ,offset=-1*floor(depth / 2) )
plot( title='Fib 0.236', series=fib_0236 ,color=fib_0236 != fib_0236[1] ? na : color.red  ,offset=-1*floor(depth / 2) )
plot( title='Fib 0.382', series=fib_0382 ,color=fib_0382 != fib_0382[1] ? na : color.olive ,offset=-1*floor(depth / 2) )
plot( title='Fib 0.500', series=fib_0500 ,color=fib_0500 != fib_0500[1] ? na : color.lime ,offset=-1*floor(depth / 2) )
plot( title='Fib 0.618', series=fib_0618 ,color=fib_0618 != fib_0618[1] ? na : color.teal ,offset=-1*floor(depth / 2) )
plot( title='Fib 0.764', series=fib_0764 ,color=fib_0764 != fib_0764[1] ? na : color.blue ,offset=-1*floor(depth / 2) )
plot( title='Fib 1.000', series=fib_1000 ,color=fib_1000 != fib_1000[1] ? na : color.black ,offset=-1*floor(depth / 2) )

xab = ( abs( b - a ) / abs( x - a ) )
xad = ( abs( a - d ) / abs( x - a ) )
abc = ( abs( b - c ) / abs( a - b ) )
bcd = ( abs( c - d ) / abs( b - c ) )

// 5つの点の比率からパターンを判断する関数
isBat(_mode)=>
  _xab = xab >= 0.382 and xab <= 0.5
  _abc = abc >= 0.382 and abc <= 0.886
  _bcd = bcd >= 1.618 and bcd <= 2.618
  _xad = xad <= 0.618 and xad <= 1.000  // 0.886
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isAntiBat(_mode)=>
  _xab = xab >= 0.500 and xab <= 0.886  // 0.618
  _abc = abc >= 1.000 and abc <= 2.618  // 1.13 --> 2.618
  _bcd = bcd >= 1.618 and bcd <= 2.618  // 2.0 --> 2.618
  _xad = xad >= 0.886 and xad <= 1.000  // 1.13
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isAltBat(_mode)=>
  _xab = xab <= 0.382
  _abc = abc >= 0.382 and abc <= 0.886
  _bcd = bcd >= 2.0 and bcd <= 3.618
  _xad = xad <= 1.13
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isButterfly(_mode)=>
  _xab = xab <= 0.786
  _abc = abc >= 0.382 and abc <= 0.886
  _bcd = bcd >= 1.618 and bcd <= 2.618
  _xad = xad >= 1.27 and xad <= 1.618
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isAntiButterfly(_mode)=>
  _xab = xab >= 0.236 and xab <= 0.886  // 0.382 - 0.618
  _abc = abc >= 1.130 and abc <= 2.618  // 1.130 - 2.618
  _bcd = bcd >= 1.000 and bcd <= 1.382  // 1.27
  _xad = xad >= 0.500 and xad <= 0.886  // 0.618 - 0.786
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isABCD(_mode)=>
  _abc = abc >= 0.382 and abc <= 0.886
  _bcd = bcd >= 1.13 and bcd <= 2.618
  _abc and _bcd and (_mode == 1 ? d < c : d > c)

isGartley(_mode)=>
  _xab = xab >= 0.5 and xab <= 0.618 // 0.618
  _abc = abc >= 0.382 and abc <= 0.886
  _bcd = bcd >= 1.13 and bcd <= 2.618
  _xad = xad >= 0.75 and xad <= 0.875 // 0.786
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isAntiGartley(_mode)=>
  _xab = xab >= 0.500 and xab <= 0.886  // 0.618 -> 0.786
  _abc = abc >= 1.000 and abc <= 2.618  // 1.130 -> 2.618
  _bcd = bcd >= 1.500 and bcd <= 5.000  // 1.618
  _xad = xad >= 1.000 and xad <= 5.000  // 1.272
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isCrab(_mode)=>
  _xab = xab >= 0.500 and xab <= 0.875  // 0.886
  _abc = abc >= 0.382 and abc <= 0.886  
  _bcd = bcd >= 2.000 and bcd <= 5.000  // 3.618
  _xad = xad >= 1.382 and xad <= 5.000  // 1.618
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isAntiCrab(_mode)=>
  _xab = xab >= 0.250 and xab <= 0.500  // 0.276 -> 0.446
  _abc = abc >= 1.130 and abc <= 2.618  // 1.130 -> 2.618
  _bcd = bcd >= 1.618 and bcd <= 2.618  // 1.618 -> 2.618
  _xad = xad >= 0.500 and xad <= 0.750  // 0.618
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isShark(_mode)=>
  _xab = xab >= 0.500 and xab <= 0.875  // 0.5 --> 0.886
  _abc = abc >= 1.130 and abc <= 1.618  //
  _bcd = bcd >= 1.270 and bcd <= 2.240  //
  _xad = xad >= 0.886 and xad <= 1.130  // 0.886 --> 1.13
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isAntiShark(_mode)=>
  _xab = xab >= 0.382 and xab <= 0.875  // 0.446 --> 0.618
  _abc = abc >= 0.500 and abc <= 1.000  // 0.618 --> 0.886
  _bcd = bcd >= 1.250 and bcd <= 2.618  // 1.618 --> 2.618
  _xad = xad >= 0.500 and xad <= 1.250  // 1.130 --> 1.130
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

is5o(_mode)=>
  _xab = xab >= 1.13 and xab <= 1.618
  _abc = abc >= 1.618 and abc <= 2.24
  _bcd = bcd >= 0.5 and bcd <= 0.625 // 0.5
  _xad = xad >= 0.0 and xad <= 0.236 // negative?
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isWolf(_mode)=>
  _xab = xab >= 1.27 and xab <= 1.618
  _abc = abc >= 0 and abc <= 5
  _bcd = bcd >= 1.27 and bcd <= 1.618
  _xad = xad >= 0.0 and xad <= 5
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isHnS(_mode)=>
  _xab = xab >= 2.0 and xab <= 10
  _abc = abc >= 0.90 and abc <= 1.1
  _bcd = bcd >= 0.236 and bcd <= 0.88
  _xad = xad >= 0.90 and xad <= 1.1
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isConTria(_mode)=>
  _xab = xab >= 0.382 and xab <= 0.618
  _abc = abc >= 0.382 and abc <= 0.618
  _bcd = bcd >= 0.382 and bcd <= 0.618
  _xad = xad >= 0.236 and xad <= 0.764
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

isExpTria(_mode)=>
  _xab = xab >= 1.236 and xab <= 1.618
  _abc = abc >= 1.000 and abc <= 1.618
  _bcd = bcd >= 1.236 and bcd <= 2.000
  _xad = xad >= 2.000 and xad <= 2.236
  _xab and _abc and _bcd and _xad and (_mode == 1 ? d < c : d > c)

// 売りパターンが出現したところに印を表示
plotshape( not showPatterns ? na : isABCD(-1) and not isABCD(-1)[1], text="\nAB=CD", title='Bear ABCD', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0, offset=-2 )
plotshape( not showPatterns ? na : isBat(-1) and not isBat(-1)[1], text="Bat", title='Bear Bat', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0, offset=-2 )
plotshape( not showPatterns ? na : isAntiBat(-1) and not isAntiBat(-1)[1], text="Anti Bat", title='Bear Anti Bat', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0, offset=-2 )
plotshape( not showPatterns ? na : isAltBat(-1) and not isAltBat(-1)[1], text="Alt Bat", title='Bear Alt Bat', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isButterfly(-1) and not isButterfly(-1)[1], text="Butterfly", title='Bear Butterfly', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isAntiButterfly(-1) and not isAntiButterfly(-1)[1], text="Anti Butterfly", title='Bear Anti Butterfly', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isGartley(-1) and not isGartley(-1)[1], text="Gartley", title='Bear Gartley', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isAntiGartley(-1) and not isAntiGartley(-1)[1], text="Anti Gartley", title='Bear Anti Gartley', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isCrab(-1) and not isCrab(-1)[1], text="Crab", title='Bear Crab', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isAntiCrab(-1) and not isAntiCrab(-1)[1], text="Anti Crab", title='Bear Anti Crab', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isShark(-1) and not isShark(-1)[1], text="Shark", title='Bear Shark', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isAntiShark(-1) and not isAntiShark(-1)[1], text="Anti Shark", title='Bear Anti Shark', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : is5o(-1) and not is5o(-1)[1], text="5-O", title='Bear 5-O', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isWolf(-1) and not isWolf(-1)[1], text="Wolf Wave", title='Bear Wolf Wave', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isHnS(-1) and not isHnS(-1)[1], text="Head and Shoulders", title='Bear Head and Shoulders', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isConTria(-1) and not isConTria(-1)[1], text="Contracting Triangle", title='Bear Contracting triangle', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )
plotshape( not showPatterns ? na : isExpTria(-1) and not isExpTria(-1)[1], text="Expanding Triangle", title='Bear Expanding Triangle', style=shape.labeldown, color=color.maroon, textcolor=color.white, location=location.top, transp=0 )

// 買いパターンが出現したところに印を表示
plotshape( not showPatterns ? na : isABCD(1) and not isABCD(1)[1], text="AB=CD\n", title='Bull ABCD', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isBat(1) and not isBat(1)[1], text="Bat", title='Bull Bat', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isAntiBat(1) and not isAntiBat(1)[1], text="Anti Bat", title='Bull Anti Bat', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isAltBat(1) and not isAltBat(1)[1], text="Alt Bat", title='Bull Alt Bat', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isButterfly(1) and not isButterfly(1)[1], text="Butterfly", title='Bull Butterfly', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isAntiButterfly(1) and not isAntiButterfly(1)[1], text="Anti Butterfly", title='Bull Anti Butterfly', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isGartley(1) and not isGartley(1)[1], text="Gartley", title='Bull Gartley', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isAntiGartley(1) and not isAntiGartley(1)[1], text="Anti Gartley", title='Bull Anti Gartley', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isCrab(1) and not isCrab(1)[1], text="Crab", title='Bull Crab', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isAntiCrab(1) and not isAntiCrab(1)[1], text="Anti Crab", title='Bull Anti Crab', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isShark(1) and not isShark(1)[1], text="Shark", title='Bull Shark', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isAntiShark(1) and not isAntiShark(1)[1], text="Anti Shark", title='Bull Anti Shark', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : is5o(1) and not is5o(1)[1], text="5-O", title='Bull 5-O', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isWolf(1) and not isWolf(1)[1], text="Wolf Wave", title='Bull Wolf Wave', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isHnS(1) and not isHnS(1)[1], text="Head and Shoulders", title='Bull Head and Shoulders', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isConTria(1) and not isConTria(1)[1], text="Contracting Triangle", title='Bull Contracting Triangle', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )
plotshape( not showPatterns ? na : isExpTria(1) and not isExpTria(1)[1], text="Expanding Triangle", title='Bull Expanding Triangle', style=shape.labelup, color=color.green, textcolor=color.white, location=location.bottom, transp=0 )

//
// 売買のロジック
////

fromY = input( 1900 ,type=input.integer ,minval=1900 ,title="test start year" )
fromM = input( 1   ,type=input.integer ,minval=1 ,maxval=12 ,title="test start month" )
fromD = input( 1   ,type=input.integer ,minval=1 ,maxval=31 ,title="test start date" )
endY = input( 3000 ,type=input.integer ,minval=1900 ,title="test end year" )
endM = input( 1   ,type=input.integer ,minval=1 ,maxval=12 ,title="test end month" )
endD = input( 1   ,type=input.integer ,minval=1 ,maxval=31 ,title="test end date" )

isWork = timestamp( fromY ,fromM ,fromD ,00 ,00 ) <= time and time < timestamp( endY ,endM ,endD ,00 ,00 )

cash_bool = input( true ,title="amount management" )
Unit_pct = input( 0.1 ,title="percent of unit value" )
lot    = input( 1   ,title="lot" ,minval=1 )
reverge  = input( 50  ,title="Reverge" ,minval=1 )

atr = ema ( tr ,20 )[1]
balance = strategy.initial_capital + strategy.netprofit
unit_value = balance * Unit_pct
float max_amount = na
float amount = na

//「fib_rangeに対する指定された比率の幅」を返す関数
f_last_fib( _rate ) => d > c ? d - ( fib_range * _rate ) : d + ( fib_range * _rate )

target01_ew_rate = input( defval=0.236 ,title='Target Fib. Rate to use for Entry Window:', type=input.float )
target01_tp_rate = input( defval=0.5  ,title='Target Fib. Rate to use for TP:', type=input.float )
target01_sl_rate = input( defval=-0.618 ,title='Target Fib. Rate to use for SL:', type=input.float )
target01_ew = f_last_fib( target01_ew_rate )
target01_sl = f_last_fib( target01_sl_rate )

buy_patterns_00 = isABCD(1) or isBat(1) or isAltBat(1) or isButterfly(1) or isGartley(1) or isCrab(1) or isShark(1) or is5o(1) or isWolf(1) or isHnS(1) or isConTria(1) or isExpTria(1)
buy_patterns_01 = isAntiBat(1) or isAntiButterfly(1) or isAntiGartley(1) or isAntiCrab(1) or isAntiShark(1)

sel_patterns_00 = isABCD(-1) or isBat(-1) or isAltBat(-1) or isButterfly(-1) or isGartley(-1) or isCrab(-1) or isShark(-1) or is5o(-1) or isWolf(-1) or isHnS(-1) or isConTria(-1) or isExpTria(-1)
sel_patterns_01 = isAntiBat(-1) or isAntiButterfly(-1) or isAntiGartley(-1) or isAntiCrab(-1) or isAntiShark(-1)

range_rate = input( title='Rate to use for ATR filter', type=input.float, defval=1 )
range = abs( close - target01_sl )

if isWork and isNewPivot and range > atr * range_rate

  max_amount := floor( ( balance - unit_value * 1.1 ) / ( close / reverge ) )
  amount := cash_bool ? round( unit_value / range / lot ) * lot : na
  amount := amount > max_amount ? max_amount : amount

  if ( buy_patterns_00 or buy_patterns_01 ) and close <= target01_ew
    strategy.entry( 'L1_target01', long=strategy.long, qty=amount, comment='L1' )
    strategy.exit( "exit-L1" ,"L1_target01" ,stop=target01_sl ,limit=f_last_fib( target01_tp_rate ) ,comment="exit-L1" )
    isNewPivot := false
  
  if ( sel_patterns_00 or sel_patterns_01 ) and close >= target01_ew
    strategy.entry( 'S1_target01', long=strategy.short, qty=amount, comment='S1' )
    strategy.exit( "exit-S1" ,"S1_target01" ,stop=target01_sl ,limit=f_last_fib( target01_tp_rate ) ,comment="exit-S1" )
    isNewPivot := false
/////////////////
コメント: 次の投稿
小次郎講師公式インジケーターのお申込
http://bit.ly/2vdSV4Q

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

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

コメント

ホーム 株式スクリーナー FXスクリーナー 仮想通貨スクリーナー 経済指標カレンダー 使い方 チャート機能 価格 友達紹介 ハウスルール ヘルプセンター ウェブサイト&ブローカー向けソリューション ウィジェット チャートソリューション 軽量チャートライブラリ ブログ&ニュース ツイッター
プロフィール プロフィール設定 アカウントとお支払い 友達紹介 コイン マイサポートチケット ヘルプセンター 公開したアイデア フォロワー フォロー中 プライベートメッセージ チャット サインアウト