TradingView
amd01s
30 ינו׳ 2020 07:28

sma dipsparity and sdv 

FX Bitcoin / YenbitFlyer

תיאור

FXBTCJPY 1min contrarian script (2020/1/30)
1分足の逆張りです.

If you want to use other timescale, need to change disparity rate and sdv.
To display disparity(sma) and standard deviation, and to draw a hline(pine function) a certain valu. And lets think. I thought disparity rate 1~1.3 or -1~-1.3 are able to use constrarian trade (and sdv>600).

In bottom, disparity index is auxiliary. It is different from the multiple in the script to make the value easier to understand.

Sorry if the expiration date of the script has expired.

הערות שחרור

disparity's multiple, length and sdv are changed.(is it Curve fitting ?)

הערות שחרור

input_length and timeframe changed.

הערות שחרור

・add comment
・sdv value changed
・made code easier to read

in addition, sorry to make a mistake title "dipsparity"→"disparity :(
תגובות
Chana35
すみません、このスクリプトで自動売買はされてますか?もし、されているようでしたら、ご使用されているプラットフォームをお教え頂けると助かります。
amd01s
@Chana35, いえ、まだですね。tradingviewでのバックテストでは今月1月のデータしかないので、約定履歴かcryptowatch使って1分足データを作成して2018年のバックテストもしてからbot作る予定です
amd01s
@Chana35, バックテストは2019年、ですね。すいません。(完全に現在2019年気分で2018年と書いてしまいました)
Chana35
@amd01s, ご多忙の中、ご返信ありがとうございました。「botを作成」とのことですが、TVからのAlertをもとに売買ではなく、別途Python等で作成されるという感じですかね。。。
amd01s
@Chana35, そうですね、アラート機能使ってトレードするのはtradingviewの有料会員でないとまともなトレードは不可?(すいません曖昧な記憶です)なのと、指値や特殊注文で自分はトレードしたいのでPythonに移植しようと考えてます。
こちらのscriptsのコードは公開していますので、改変例えば損切りコード書き加えたりなどしてtvのアラートで売買してみてはいかかでしょうか?
簡単に調べたところ、noteでは「たんさん」や「はむとれ」という方がtvのアラートを使った売買を紹介されていますので実践するのも良さそうですね。
Chana35
@amd01s, ご返信、ありがとうございます。

「たんさん」は使用していませんが、「はむとれ」は使用しています。「はむとれ」だと、アラートが出てから実際の売買までのラグが3秒から20秒程あり、長時間足のストラテジーだと、誤差なんですが、流石に1分足で、スキャルピング的に短時間で売買をするのは現実的ではないという感じです。恐らく「たんさん」の手法でも同じかと推測します。

せっかく偏差が数値化されているので、それに基づいた指値で売買する(Python等)のがやっぱりいいと思います。

もともとの質問の意図は、もし、TVからのアラートを基に既に自動売買をされているとしたら、上記の遅延を解決されておられると勝手に思い、お使いのプラットフォームをお教えいただければと思い、質問させていただいた次第です。

ご丁寧にいろいろとお教え頂き、ありがとうございました。
Chana35
@amd01s, 何で勝つのかわかりませんが、ごちゃごちゃいじってたら、1分足で成績がいいのができましたので、ご参考までにお送りしておきます。恐らく、期間限定で、たまたまこの2週間ほどがこのストラテジーに合っているだけで、汎用的に長期間で検証すると、アカンやつだと思います。自分のTradingViewのアカウントだと、1分足だと、せいぜい2週間分くらいしかバックテストできないもんで。

//@version=4
strategy("VolumeROC_MA_1min", overlay=false)

len = input(32)
vroc = roc(volume,len)
vrocma = sma(vroc, len)

plot(0,color=color.gray)
plot(vrocma,color=color.gray)

// direction -------------------------------------------------------------------
dirtime=input(41,"direction picker # bars")
dir=if close/close[dirtime] > 1
1
else
-1

// ️⚠️⚠️Logic -----------------------------------------------------------------

isLongEntry = crossover (vrocma, 0) and dir == -1
isShortEntry = crossover (vrocma, 0) and dir == 1

// Back Test Fnction -----------------------------------------------------------
TestP = input(true,title=" ░░░ Separator░░░ Test Period Parameter ")
startP = timestamp(input(2019, "Start Year"), input(1, "Start Month"), input(1, "Start Day"), 0, 0)
end = timestamp(input(9999, "End Year"), input(1, "End Month"), input(1, "End Day"), 0, 0)
_testPeriod() =>
iff(time >= startP and time <= end, true, false)

// Position Function
avgg = strategy.position_avg_price
poss = strategy.position_size

if _testPeriod()
if isLongEntry
strategy.entry("L", strategy.long, comment="Long")
if isShortEntry
strategy.entry("S", strategy.short, comment="Short")

// Plot Long and Short Position
input_isShowLongShort = input(true, title="[DISP] Long / Short")
bgcolor(input_isShowLongShort ? #000000cc : na, title="Dark Background")
bgcolor(input_isShowLongShort and poss<0 ? color.new(#DF00FF, 80) : input_isShowLongShort and poss>0 ? color.new(#0892D0, 80) : na, editable=false)

// Plot Wining or Losing
input_isShowWinOrLose = input(true, title="[DSIP] Winning / Losing")
isProfitShapePlus = false
isProfitShapeMinus = false
//if _bLongEntry or _bShortClose or _bShortEntry or _bLongClose ----------------
if avgg > 0 or poss==0
if strategy.openprofit > 0 and input_isShowWinOrLose
isProfitShapePlus := true
isProfitShapePlus
if strategy.openprofit < 0 and input_isShowWinOrLose
isProfitShapeMinus := true
isProfitShapeMinus

plotshape(isProfitShapePlus, style=shape.circle, color=color.aqua, transp=80, location=location.top, size=size.tiny, title="Win")
plotshape(isProfitShapeMinus, style=shape.xcross, color=color.red, transp=80, location=location.top, size=size.tiny, title="Lose")
amd01s
@Chana35, すごい緻密なコードですね汗 roc関数というの知りませんでしたので知見を得られました...
//direction--にかかれているdir=if close/close > 1のどちらかのcloseは[1]などを後ろに付けていくつか前の終値を参照しそうな感じですか?

アラートを使った売買は1分足では多少のスリッピングはありそうですが時間軸が長くなると気にならなさそうでPythonに移植するより楽に売買できそうですね.年度末なので少し多忙なのですがその方法も少し検討してみようと思います・・・(感謝です).
Chana35
@amd01s

dir=if close/close > 1 => dir=if close/close[dirtime] > 1

何故か[dirtime] が、抜けてました。普通に全部コピペしただけなんですけど。。。

dirtime = 1 だと、その時のバーが陽線であれば、Logic の中では、dir==1 を設定しますので、一般的には、

Long = dir == 1、short = dir == -1 で記述します。

恐らく、[] が無かったゆえのご質問かと思いますが、基本的にはご質問の答えはYesです。

上記のstrategyの場合、たまたま逆にしたら、成績が良かったという感じで。。。本来イメージして作ったロジックとは逆になっているので、そのため、「何で勝つのかわかりません」という表記になっておりますw
Chana35
@Chana35,

square brackets がコメント欄では表示できないみたいです。

全角のsquare bracketsで上記と同じ内容のコメントで再度挑戦しておきます。

誤謬 : dir=if close/close > 1
正解 : dir=if close/close[dirtime] > 1

何故か[dirtime]が、抜けてました。普通に全部コピペしただけなんですけど。。。

dirtime = 1 だと、その時のバーが陽線であれば、Logic の中では、dir==1 を設定しますので、一般的には、

Long = dir == 1、short = dir == -1 で記述します。

恐らく、[] が無かったゆえのご質問かと思いますが、基本的にはご質問の答えはYesです。

上記のstrategyの場合、たまたま逆にしたら、成績が良かったという感じで。。。本来イメージして作ったロジックとは逆になっているので、そのため、「何で勝つのかわかりません」という表記になっておりますw

もし、全角でもダメな場合を見越して、文章で記述すると、

「close」 と 「>1」 の間に、square brackets で囲まれた dirtime が入ります。
עוד