FC2ブログ

# 平均足 コマ足 Heiken Ashi
# 引数 始値 高値 安値 終値 (\@Open, \@High, \@Low, \@Close)
# 戻り値 hash {'open'} {'high'} {'low'} {'close'} (%heiken)
sub HEIKIN{
my ($Open, $High, $Low, $Close) = @_;
my %heiken = ();
my $count = @$Close - 2;

# 配列数の確認
if(($count < 0) || (@$Close != @$Open) || (@$Close != @$High) || (@$Close != @$Low)){
return 0;
}

# 計算
$heiken{'open'}->[$count] = ($$Open[$count + 1] + $$High[$count + 1] + $$Low[$count + 1] + $$Close[$count + 1]) / 4;
$heiken{'high'} = $High;
$heiken{'low'} = $Low;
$heiken{'close'}->[$count] = ($$Open[$count] + $$High[$count] + $$Low[$count] + $$Close[$count]) / 4;
for(my $i = $count - 1; $i >= 0; $i--){
# 平均足 Heiken Ashi
$heiken{'open'}->[$i] = ($heiken{'open'}->[$i + 1] + $heiken{'close'}->[$i + 1]) / 2;
$heiken{'close'}->[$i] = ($$Open[$i] + $$High[$i] + $$Low[$i] + $$Close[$i]) / 4;
}

return %heiken;
}

修正平均足

# 修正平均足 修正コマ足 Heiken Ashi
# 引数 期間 始値 高値 安値 終値 ($Period, \@Open, \@High, \@Low, \@Close)
# 戻り値 hash {'open'} {'high'} {'low'} {'close'} (%heiken)
sub HEIKIN{
my ($Period, $Open, $High, $Low, $Close) = @_;
my %heiken = ();
my $MeanOpen = 0;
my $MeanHigh = 0;
my $MeanLow = 0;
my $MeanClose = 0;
my $DenPeriod_4 = $Period * 4;
my $count = @$Close - ($Period + 1);

# 期間と配列数の確認
if(($Period <= 0) || ($count < 0) || (@$Close != @$Open) || (@$Close != @$High) || (@$Close != @$Low)){
return 0;
}

# 計算
for(my $i = $count; $i >= 0; $i--){
if($i == $count){
for(my $j = 0; $j < $Period; $j++){
$MeanOpen += $$Open[$i + $j + 1];
$MeanHigh += $$High[$i + $j + 1];
$MeanLow += $$Low[$i + $j + 1];
$MeanClose += $$Close[$i + $j + 1];
}

# 平均足 Heiken Ashi
$heiken{'open'}->[$i] = ($MeanOpen + $MeanHigh + $MeanLow + $MeanClose) / $DenPeriod_4;
$MeanOpen = $MeanOpen + $$Open[$i] - $$Open[$i + $Period];
$MeanHigh = $MeanHigh + $$High[$i] - $$High[$i + $Period];
$MeanLow = $MeanLow + $$Low[$i] - $$Low[$i + $Period];
$MeanClose = $MeanClose + $$Close[$i] - $$Close[$i + $Period];
$heiken{'high'}->[$i] = $MeanHigh / $Period;
$heiken{'low'}->[$i] = $MeanLow / $Period;
$heiken{'close'}->[$i] = ($MeanOpen + $MeanHigh + $MeanLow + $MeanClose) / $DenPeriod_4;
}else {
$MeanOpen = $MeanOpen + $$Open[$i] - $$Open[$i + $Period];
$MeanHigh = $MeanHigh + $$High[$i] - $$High[$i + $Period];
$MeanLow = $MeanLow + $$Low[$i] - $$Low[$i + $Period];
$MeanClose = $MeanClose + $$Close[$i] - $$Close[$i + $Period];

# 平均足 Heiken Ashi
$heiken{'open'}->[$i] = ($heiken{'open'}->[$i + 1] + $heiken{'close'}->[$i + 1]) / 2;
$heiken{'high'}->[$i] = $MeanHigh / $Period;
$heiken{'low'}->[$i] = $MeanLow / $Period;
$heiken{'close'}->[$i] = ($MeanOpen + $MeanHigh + $MeanLow + $MeanClose) / $DenPeriod_4;
}

}

return %heiken;
}


参考URL
平均足の見方

メモ
平均足のClose = 当日(Open + High + Low + Close) / 4
当日 平均足のOpen = 前日(Open + High + Low + Close) / 4
2日目以降 平均足のOpen = (前日の平均足のOpen + 前日の平均足のClose) / 2
オンライン コンパイラ/インタプリタ
テクニカル分析
プロフィール

Author:雨宮
Firefoxを使用しているので気づかなかったけど、IE6でソースコードを上手くコピーできない

5/3
携帯用ならIE6でもソースコードをコピーできる
携帯用

検索フォーム


あわせて読みたいブログパーツ
一寸先は闇 RSS