【実装】X日Y日移動平均
http://ameblo.jp/traderssystem/entry-10104417214.html
http://ameblo.jp/traderssystem/entry-10104417647.html
-----------------------------------------------------------------
Input : short_period(3), long_period(30), KeepDay(12);
Value1 = ma(C, short_period);
Value2 = ma(C, long_period);
//短期移動平均が長期移動平均を3日連続で上回ったら買い
If (Value1[0] >= Value2[0] and Value1[1] >= Value2[1] and Value1[2] >= Value2[2]) then {
Buy("SW1401新規買", AtMarket);
}
//短期移動平均が長期移動平均を3日連続で下回ったら売り
If (Value1[0] <= Value2[0] and Value1[1] <= Value2[1] and Value1[2] <= Value2[2]) then {
Sell("SW1401新規売", AtMarket);
}
//N日間後に決済
If BarsSinceEntry(0) == KeepDay then {
if MarketPosition == 1 then {
ExitLong("SW1401買決済-期限", OnClose);
}
if MarketPosition == -1 then {
ExitShort("SW1401売決済-期限", OnClose);
}
}
-----------------------------------------------------------------
3日連続でというところを
Value1[0] >= Value2[0] and Value1[1] >= Value2[1] and Value1[2] >= Value2[2]
と実装していますが、工夫すればもっと柔軟なシステムになると思います。
是非、挑戦してみてください。
【実装】ジョーズ・クオーター・パウンダー
http://ameblo.jp/traderssystem/entry-10104985605.html
--------------------------------------------------------------------
Input : period(30), kakeme(3);
//3日前終値>当日始値 かつ
//2日前終値>当日始値 かつ
//2日前終値>3日前終値 のとき
If (Close[0] < Close[3] and
Close[0] < Close[2] and
Close[2] > Close[3]) Then {
//翌日2日前高値を逆指しで仕掛ける
Buy("SW2401新規買", AtStop, Close[2]);
}
//3日前終値<当日始値 かつ
//2日前終値<当日始値 かつ
//2日前終値<3日前終値 のとき
If (Close[0] > Close[3] and
Close[0] > Close[2] and
Close[2] < Close[3]) Then {
//翌日2日前高値を逆指しで仕掛ける
Sell("SW2401新規売", AtStop, Close[2]);
}
//買値±30日標準偏差の3倍で利確・損切り
If MarketPosition == 1 Then {
//MessageLog("%.0f %.2f", AvgEntryPrice, STD(C, period));
ExitLong("SW2401買決済_損切り", AtStop, AvgEntryPrice - (STD(C - C[1], period) * kakeme));
ExitLong("SW2401買決済_利確", AtLimit, AvgEntryPrice + (STD(C - C[1], period) * kakeme));
}
//買値±30日標準偏差の3倍で利確・損切り
If MarketPosition == -1 Then {
ExitShort("SW2401売決済_損切り", AtStop, AvgEntryPrice + (STD(C - C[1], period) * kakeme));
ExitShort("SW2401売決済_利確", AtLimit, AvgEntryPrice - (STD(C - C[1], period) * kakeme));
}
--------------------------------------------------------------------
標準偏差の算出にSTD()関数を利用しています。
--------------------------------------------------------------------
/* Description : Standard Deviation
*
* Provided By : YesStock Inc. (c) Copyright 2006
* E-Mail : webmaster@yesstock.com
*/
Input : Price(NumericSeries), Length(NumericSimple);
Var : SumSqrt(0), Avg(0), Counter(0);
If Length != 0 Then Begin
Avg = Ma(Price, Length);
SumSqrt = 0;
For Counter = 0 To Length - 1 Begin
SumSqrt = SumSqrt + (Price[Counter] - Avg) * (Price[Counter] - Avg);
End;
Std = SquareRoot(SumSqrt / Length);
End
Else
Std = 0;
--------------------------------------------------------------------
【実装】ジョーズ・ギャップ
http://ameblo.jp/traderssystem/entry-10104985811.html
-----------------------------------------
Input : KeepDay(3);
//本日安値>昨日高値のとき
//翌日の寄り付きで買い
If (Low[0] > High[1]) Then {
Buy("SW1601新規買", AtMarket);
}
//本日安値<昨日高値のとき
//翌日の寄り付きで売り
If (Low[0] > High[1]) Then {
Sell("SW1601新規売", AtMarket);
}
//N日間後に決済
If BarsSinceEntry(0) == KeepDay then {
if MarketPosition == 1 then {
ExitLong("SW1601買決済-期限", OnClose);
}
if MarketPosition == -1 then {
ExitShort("SW1601売決済-期限", OnClose);
}
}
-----------------------------------------
BarsSinceEntry()関数はマニュアルにありますが
ポジション新規以後、経過した足の数を返しています。
【実装】レンジが狭まった安値圏での逆張り
http://ameblo.jp/traderssystem/entry-10104416720.html
----------------------------------------------------------------------
Input : ma_period(5), short_range_period(10), long_range_period(25),
range_rate(0.2);
Var : cnt(0);
Value1 = 0;
Value3 = 0;
Value5 = 0;
For cnt = 1 To ma_period Begin
Value1 = Value1 + DayClose(ma_period);
End
Value2 = Value1 / ma_period;
For cnt = 1 To short_range_period Begin
Value3 = Value3 + (DayHigh(short_range_period) - DayLow(short_range_period));
End
Value4 = Value3 / short_range_period;
For cnt = 1 To long_range_period Begin
Value5 = Value5 + (DayHigh(long_range_period) - DayLow(long_range_period));
End
Value6 = Value5 / short_range_period;
//終値が前日の終値と5日間移動平均よりも安く、
//過去10日間の平均レンジが過去25日間の平均レンジよりも小さいとき
If DayClose(1) < DayClose(2) and
DayClose(1) < Value2 and
Value4 < Value5 Then {
//翌日の始値+前日レンジの20%の水準にストップ注文で買い
Buy("DT1301新規買", AtStop, DayOpen(0) + Value4 * range_rate);
}
If MarketPosition == 1 Then {
//仕掛け値-過去25日間の平均レンジで損きり
ExitLong("DT1301買決済_損切", AtStop, AvgEntryPrice - Value6);
//終値が前日終値と5日間移動平均よりも高いときは
If BarsSinceEntry >= 1 and
DayClose(1) > DayClose(2) and
DayClose(1) > Value2 Then {
//翌日始値-前日レンジの20%の水準で手仕舞い
ExitLong("DT1301買決済_手仕舞", AtStop, DayOpen(0) - Value4 * range_rate);
}
}
----------------------------------------------------------------------
Value1 - Value6までで
分足ベースで日足のシグナルを算出しています。
For文の中で指定した期間の値を合算して
For文終了後に期間で割っています。
【実装】ジョージ・テキサス・2ステップ
http://ameblo.jp/traderssystem/entry-10104985157.html
-------------------------------------------------
Input : RSI_Period(14), MA_Period(3);
Value1 = RSI(RSI_Period);
Value2 = ma(Value1, MA_Period);
//本日14日RSIが14日RSIの3日移動平均を上抜くとき
If CrossUp(Value1, Value2) then {
//翌日の寄り付きで買い
Buy("SW2501新規買", AtMarket);
}
//本日14日RSIが14日RSIの3日移動平均を下抜くとき
If CrossDown(Value1, Value2) then {
//翌日の寄り付きで売り
Sell("SW2501新規売", AtMarket);
}
-------------------------------------------------
これまでの記事を読んでこられた方は
アイデアから素直にソースコードに落とすことができると思います。
特に解説はありません。
【実装】9日間高安に基づく66%モメンタム手法
http://ameblo.jp/traderssystem/entry-10104415393.html
----------------------------------------------------
Input : period(9), kakeme(0.66);
Var : max_high(0), max_low(0), XH(0), XL(0), XX(0), Count(0);
max_high = 0;
max_low = 0;
//過去N日間の高値・安値を算出
For Count = 1 To period Begin
If DayHigh(period) > max_high Then {
max_high = DayHigh(period);
}
If DayLow(period) < max_low Then {
max_low = DayLow(period);
}
End
//過去9日間の最高値-終値=XH
//終値-過去9日間の最安値=XL
//より大きいほうをXX
XH = max_high - DayClose(1);
XL = DayClose(1) - max_low;
XX = Max(XH, XL);
//1.XH>XLのとき
//翌日の始値+XLの66%をストップ注文で買い
If XH > XL Then {
Buy("DT1101新規買", AtStop, DayOpen(0) + XL * kakeme);
}
//損きり注文は仕掛け値-XX×1.32
If MarketPosition == 1 Then {
ExitLong("DT1101買決済", AtStop, AvgEntryPrice - XX * kakeme * 2);
}
//2.XH<XLのとき
//翌日の始値-XHの66%をストップ注文で売り
If XH < XL Then {
Sell("DT1101新規売", AtStop, DayOpen(0) - XH * kakeme);
}
//損きり注文は仕掛け値+XX×1.32
If MarketPosition == 1 Then {
ExitShort("DT1101売決済", AtStop, AvgEntryPrice + XX * kakeme * 2);
}
----------------------------------------------------
下記のような方法で分足ベースで過去N日の高値・安値を算出しています。
・DayHigh(1)が変数max_highを上回ったらmax_highにDayHigh(1)をセット
・DayHigh(2)が変数max_highを上回ったらmax_highにDayHigh(2)をセット
以下、periodで指定した日数分繰り返す(DayLowについても同じ考え方)
後は難しくないと思います。
難しい実装
日足ベースの戦略を分足で動かすというのは
結構、実装の難易度が高いのかもしれません。
こういうアイデアの場合どうすればいいの?
というのがありましたら気軽にご連絡ください。
解決できるとは限りませんが、考えてみたいと思っています。
【実装】ワンナイト・スタンド
http://ameblo.jp/traderssystem/entry-10104984953.html
------------------------------------------------------------
Input : short_period(10), long_period(40), entry_period(4), exit_period(8);
//木曜 かつ
//当日終値の10日単純移動平均>40日単純移動平均のとき
// 翌日に過去4日高値で逆指し買い
If CurrentWeek(Date) == 4 and
Ma(Close, short_period) > Ma(Close, long_period) Then {
Buy("SW3801新規買", AtStop, Highest(High, entry_period));
}
If CurrentWeek(Date) == 4 and
Ma(Close, short_period) < Ma(Close, long_period) Then {
Sell("SW3801新規売", AtStop, Lowest(Low, entry_period));
}
//売りは過去8日安値で仕掛ける
If MarketPosition == 1 Then {
ExitLong("SW3801買決済_損切り", AtStop, Lowest(Low, exit_period));
}
//買いは過去8日安値で仕掛ける
If MarketPosition == 1 Then {
ExitShort("SW3801売決済_損切り", AtStop, Highest(High, exit_period));
}
//月曜寄り付きで手仕舞い
If CurrentWeek(Date) == 5 Then {
ExitLong("SW3801買決済_月曜", AtMarket);
ExitShort("SW3801売決済_月曜", AtMarket);
}
------------------------------------------------------------
トレコレさん 開発の
CurrentWeek()関数をフルに利用しています。
日足ベースで寄りで手仕舞う場合に
金曜日のクローズのタイミングでAtMarket注文を出していますが、
これだと金曜イブニングで処理されてしまうかもしれません。
(どなたか教えてください)
回避するには分足で動かすしかないと思います。
(実際に利用するにはシステムで動かさず予約注文しておくという方が無難かも知れません)
【実装】3日間の200%レンジブレイクアウト
http://ameblo.jp/traderssystem/entry-10104414153.html
------------------------------------------------------
Input : period(3), kakeme(2), s_period(4);
Var : Count(0);
Value1 = 0;
//翌日の始値±過去3日間の平均レンジの200%の水準を買い
For Count = 1 To period Begin
Value1 = DayHigh(period) - DayLow(period);
End
Value2 = Value1 / period * kakeme;
If sTime == 090000 Then {
Value3 = 0;
}
If MarketPosition == 0 and Value3 == 0 Then {
Buy("DT1201新規買_指値", AtLimit, DayOpen(0) - Value2);
Buy("DT1201新規買_逆指値", AtStop, DayOpen(0) + Value2);
}
If MarketPosition == 1 Then {
//利益目標は前日高値水準
ExitLong("DT1201買決済_指値", AtLimit, DayHigh(1));
//前日安値水準に損きり注文
ExitLong("DT1201買決済_逆指値", AtStop, DayLow(1));
//仕掛け日を含めた4日後に手仕舞い
If Time == 151000 Then {
Value3 = Value3 + 1;
If Value4 = s_period Then {
ExitLong("DT1201買決済_日付", OnClose);
Value3 = 0;
}
}
}
------------------------------------------------------
分足での動作を想定したシステムです。
アップしてから気づいたのですが、Value1, Valueで
過去N日間の平均レンジのXXX%という値を出そうとしていますが、
ロジックに誤りがあります。
せっかくなのでクイズです。
どうすれば正しい動作になるでしょうか
考えてみてください。
DayOpen(), DayHigh(), DayLow()関数を使って
当日、前日の日足ベースの価格を利用しています
//仕掛け日を含めた4日後に手仕舞い
ポジションを保有しているとき、151000時点でValue3に1加算
Value3の値がN日と等しいときは決済としています。
【実装】リバーサルデイ
http://ameblo.jp/traderssystem/entry-10104413400.html
------------------------------------------------------------------------------
Input : period(30), kakeme(3);
//前日の高値が前々日の高値よりも高く、終値が前日の終値よりも安いとき
If (Close[0] < Close[1] and High[1] > High[2]) Then {
//翌日の寄付きに成り行きで買う
Buy("SW2601新規買", AtMarket);
}
//前日の安値が前々日の安値よりも安く、終値が前日の終値よりも高いとき
If (Close[0] > Close[1] and Low[1] < Low[2]) Then {
//翌日の寄付きに成り行きで売る
Sell("SW2601新規売", AtMarket);
}
//買値±30日標準偏差の3倍で利確・損切り
If MarketPosition == 1 Then {
//MessageLog("%.0f %.2f", AvgEntryPrice, STD(C, period));
ExitLong("SW2601買決済_損切り", AtStop, AvgEntryPrice - (STD(C - C[1], period) * kakeme));
ExitLong("SW2601買決済_利確", AtLimit, AvgEntryPrice + (STD(C - C[1], period) * kakeme));
}
//買値±30日標準偏差の3倍で利確・損切り
If MarketPosition == -1 Then {
ExitShort("SW2601売決済_損切り", AtStop, AvgEntryPrice + (STD(C - C[1], period) * kakeme));
ExitShort("SW2601売決済_利確", AtLimit, AvgEntryPrice - (STD(C - C[1], period) * kakeme));
}
------------------------------------------------------------------------------
買値、売値はAvgEntryPriceで表現しています。
マニュアルでは
平均新規単価:決済していない新規シグナルの平均新規単価をリターンする関数
とあります、引数は必要ありませんが関数なので()を加えておいた方がいいかもしれません。
標準偏差を求める関数STD()が初めて出てきています。
------------------------------------------------------------------------------
/* Description : Standard Deviation
*
* Provided By : YesStock Inc. (c) Copyright 2006
* E-Mail : webmaster@yesstock.com
*/
Input : Price(NumericSeries), Length(NumericSimple);
Var : SumSqrt(0), Avg(0), Counter(0);
If Length != 0 Then Begin
Avg = Ma(Price, Length);
SumSqrt = 0;
For Counter = 0 To Length - 1 Begin
SumSqrt = SumSqrt + (Price[Counter] - Avg) * (Price[Counter] - Avg);
End;
Std = SquareRoot(SumSqrt / Length);
End
Else
Std = 0;
------------------------------------------------------------------------------
いずれ見ていこうと思います。