自動売買BOTの改良 その3
今回はスキャルピングをやってみましょう。
損益があらかじめ決めた値幅以上になったら利益確定するというものです。
コードに以下のような部分があると思います。
collateral = bitflyer.private_get_getcollateral()
balance = float(collateral["collateral"])
lot = math.floor(balance * 2 * 0.99 / midprice * 100) / 100
lmt = balance * 2.0 / 100
lct = -(balance * 10.0 / 100)
これは証拠金からロット数やロスカット幅、リミット幅などを計算している部分です。
lmt = balance * 2.0 / 100 という部分があります。
今回はここの2.0を1.0にしてみましょう。
1%利益が乗ったら利益確定することにします。
lmt = balance * 1.0 / 100
以上のようにします。
次は未実現損益pnlがリミット幅lmtを越えた時に決済注文を出す部分を作ります。
コードに以下の部分があると思います。
if(pnl < lct and posi == "BUY"):
try:
order = bitflyer.create_order(symbol = 'BTC/JPY',type='market',side='sell',amount=lot0,params = { "product_code" : "FX_BTC_JPY"})
posi = ""
b0 += 1
pprint( order )
time.sleep(2)
except Exception as e:
time.sleep(2)
if(pnl < lct and posi == "SELL"):
try:
order = bitflyer.create_order(symbol = 'BTC/JPY',type='market',side='buy',amount=lot0,params = { "product_code" : "FX_BTC_JPY"})
posi = ""
b0 += 1
pprint( order )
time.sleep(2)
except Exception as e:
time.sleep(2)
この部分をこのすぐ前の行のあたりにコピペします。
そして貼り付けたほうの条件式の pnl < lct を pnl > lmt に書き換えます。
if(pnl > lmt and posi == "BUY"):
try:
order = bitflyer.create_order(symbol = 'BTC/JPY',type='market',side='sell',amount=lot0,params = { "product_code" : "FX_BTC_JPY"})
posi = ""
b0 += 1
pprint( order )
time.sleep(2)
except Exception as e:
time.sleep(2)
if(pnl > lmt and posi == "SELL"):
try:
order = bitflyer.create_order(symbol = 'BTC/JPY',type='market',side='buy',amount=lot0,params = { "product_code" : "FX_BTC_JPY"})
posi = ""
b0 += 1
pprint( order )
time.sleep(2)
except Exception as e:
time.sleep(2)
if(pnl < lct and posi == "BUY"):
try:
order = bitflyer.create_order(symbol = 'BTC/JPY',type='market',side='sell',amount=lot0,params = { "product_code" : "FX_BTC_JPY"})
posi = ""
b0 += 1
pprint( order )
time.sleep(2)
except Exception as e:
time.sleep(2)
if(pnl < lct and posi == "SELL"):
try:
order = bitflyer.create_order(symbol = 'BTC/JPY',type='market',side='buy',amount=lot0,params = { "product_code" : "FX_BTC_JPY"})
posi = ""
b0 += 1
pprint( order )
time.sleep(2)
except Exception as e:
time.sleep(2)
と、このようになります。
こうするとMACDのゴールデンクロス、デッドクロスでポジションを持ったときに1%で利益確定します。
ただし、トレンドに乗り続けて大儲けすることは出来なくなってしまいますね。
今回はスキャルピングがしたい方向けの方法のひとつを紹介いたしました。
今回は以上です。
この記事が気に入ったらサポートをしてみませんか?