yuya_takahashi_

Pine講座㉖ バックテスト|2本のSMAで途転

Formación
yuya_takahashi_ Actualizado   
FX:USDJPY   Dólar estadounidense/Yen japonés
まずは、TradingViewに最初から入っているストラテジーの解説をしていきます。

今回は、MovingAvg2Line Cross

2本の移動平均線の
ゴールデンクロス(GC)と
デッドクロス(DC)で
途転売買する手法です。

コードの中に、直接解説を記入していきます!

=====
//Pineスクリプトのバージョンを宣言
//@version=4

//ストラテジーの宣言
strategy("MovingAvg2Line Cross", overlay=true)

//SMAの計算値を設定
//ポップアップで変更もできるように(input関数)
fastLength = input(9)
slowLength = input(18)

//計算のもとになる価格を指定
price = close

//SMAの計算
mafast = sma(price, fastLength)
maslow = sma(price, slowLength)

//**
//* 以下で条件分岐して売買
//*

//短期が長期を上抜けた場合
if (crossover(mafast, maslow))
//買いエントリー
strategy.entry("MA2CrossLE", strategy.long, comment="MA2CrossLE")

//短期が長期を下抜けた場合
if (crossunder(mafast, maslow))
//売りエントリー
strategy.entry("MA2CrossSE", strategy.short, comment="MA2CrossSE")
=====

crossover( {a} ,{b} )
{a} が {b} を上抜けたときに True を返します

crossunder( {a} ,{b} )
{a} が {b} を下抜けたときに True を返します

strategy.entry( )
エントリーする関数。
strategy.long、strategy.short で「買い」「売り」を指定できる。
すでにポジションがあるときに、逆方向のエントリーをすると「途転」となる。(買いと売りが同数になるわけではないことに注意)
Comentarios:
次の講座

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

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

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

Ideas relacionadas

Exención de responsabilidad

La información y las publicaciones que ofrecemos, no implican ni constituyen un asesoramiento financiero, ni de inversión, trading o cualquier otro tipo de consejo o recomendación emitida o respaldada por TradingView. Puede obtener información adicional en las Condiciones de uso.