# loop-type: date-only
//==============================
require "TIlib"
require "Utility"
require "TrendCheck"
// ======================================
// イチモクRSI
// ======================================
//
//[ランキング条件]
// 1) 株価の低い場合はランキングしない[150]万円以下
// 2) 売買代金の少ない場合はランキングしない(売買代金の[3]日間平均が[5]千万円以下の場合)
//
//[買いルール]
// 1) ローソク足が雲の上にあり、RSIが30%を下回って確定した時
//
//[手仕舞いルール]
// 1) 利食い:5%のプラス
// 2) 最大保有日数:4日
codes = CodeList
if ($code_num && $code_num != Length(codes))
Print("前回と異なる銘柄リストでは実行できません。")
Dummy
end
$code_num = Length(codes)
//グローバル変数を初期化
if (!$__INIT__)
$budgetIni = 10000000
$buyUnit = 1000000 // 1回の購入資金 (100万円)
$MaxHoldDay = 2 // 最大保有日数
$shortSelling = 0 // 空売り戦略 Yes(1)/No(0)
$Interest = 1 // 無制限(0) / 単利(1) / 複利(2)
$reverse = 0 // 購入順序 昇順(0) / 降順(1)
$udcount = 0 // 騰落レシオ利用数
Init()
// テクニカル指標初期化 --------------------------
$ICHI = [$code_num]
$RSI = [$code_num]
//------------------------------------------------
InitDone() // 騰落レシオ初期化
$__INIT__ = 1
end
def Main(i)
//==================================================
// 条件(買条件, 売条件共通部分)
//==================================================
//まだ上場していない銘柄は株価データがないためnullが返る
if (Index == null)
return
end
if ! ($order[(int)Code])
$order[(int)Code] = i
end
if ! ($ICHI[i] && $RSI[i])
//Tilibのオブジェクト生成
$ICHI[i] = Ichimoku_new(9, 26, 52)
$RSI[i] = RSI_new(14, 1) // Wilder RSI
//銘柄ごとのグローバル変数を初期化する
$hold[i] = 0
return
end
//指標の計算を1日進める
Ichimoku_next($ICHI[i])
RSI_next($RSI[i])
//==================================================
// 保有してない→購入
//==================================================
if (! $hold[i])
//==================================================
// 売買(買い)
//==================================================
// 1) 株価の低い場合はランキングしない[150]万円以下
// 2) 売買代金の少ない場合はランキングしない(売買代金の[3]日間平均が[5]千万円以下の場合)
if ! (Close && {-1}Close && {-2}Close)
return
end
if ! (SalesValue()/3 + {-1}SalesValue()/3 + {-2}SalesValue()/3 > 50000 && Close > 150)
return
end
senko1_1 = $ICHI[i][4]
senko2_1 = $ICHI[i][6]
senko1 = Ichimoku_senko1($ICHI[i])
senko2 = Ichimoku_senko2($ICHI[i])
rsi_1 = $RSI[i][0]
rsi = RSI_value($RSI[i])
if ! (kijun_1 && tenkan_1 && kijun && tenkan && senko1_1 && senko2_1 && senko1 && senko2 && rsi_1 && rsi)
return
end
// 1) ローソク足が一目均衡表の雲を上抜けた
check1 = (High >= senko1_1 || High >= senko2_1) && senko1 >= Low && senko2 >= Low
// 2) RSIが30%を下回った
check2 = rsi_1 >= 30 && 30 > rsi
if (check1 && check2)
PrintLog("購入予定")
$buyflag[i][0] = 1
// 好きなパラメータをもとにソート
$buyflag[i][1] = rsi
$buyCnt = $buyCnt + 1
end
//==================================================
// 保有している→売却
//==================================================
elsif ($hold[i])
if ($set[i] < 1)
$set[i] = 1
return
end
$set[i] = $set[i] + 1
//==================================================
// 売買(売り)
//==================================================
if (Close >= 1.05 * $buy[i])
PrintLog("利食い")
$sellflag[i] = 1
$set[i] = 0
elsif ($set[i] >= $MaxHoldDay)
$sellflag[i] = 1
$set[i] = 0
end
end
end
//====================
// 買い処理
//====================
def SortBuy(i)
if (PricedataExistCheck(Close))
return
end
$long = 0
$long = Num($buyUnit, Close)
codeset = $order[(int)Code]
Buying(codeset)
end
//====================
// 売り処理
//====================
def Sell_(i)
if ($sellflag[i])
Selling(i)
$sellflag[i] = 0
end
// 使用した$buyflag 配列を初期化
if ($buyflag[i][0])
$buyflag[i][0] = 0
$buyflag[i][1] = 0
end
end
//====================
// 銘柄コードを変えながらMain関数,BuySell関数を実行
//====================
Print("-------------------------------------------------")
Print("日付 = "+ Year + "/" + Month + "/" + Day)
SortInit() // ソート初期化
i = -1
while (i + 1 < $code_num)
i = i + 1
{codes[i]}Main(i)
end
i = -1
while i + 1 < $code_num
i = i + 1
{codes[i]}Sort(i)
end
i = -1
if ($buyCnt)
while i + 1 < $buyCnt
i = i + 1
{$sortList2[i]}SortBuy(i)
end
end
i = -1
while i + 1 < $code_num
i = i + 1
{codes[i]}Sell_(i)
end