FC2ブログ

# 新値足 Shin Ne Ashi
# 引数 N本足 値 ($N, \@Price)
# 戻り値 hash {'shinne'} {'high'} {'low'} {'ashi'} {'count'} (%shinne)
sub SHINNE{
my ($N, $Price) = @_;
my %shinne = ();
my %Temp = ();
my @Reverse = ();
my $TempHigh = 0;
my $TempLow = 0;
my $N_1 = $N + 1;
my $Up = 1;
my $Down = 1;
my $Check = 0;
my $Number = 0;
my $Ashi = 0;
my $count = @$Price - 1;

# N本足と配列数の確認
if(($N <= 0) || ($count < 0)){
return 0;
}

# 計算
$TempHigh = $$Price[$count];
$TempLow = $$Price[$count];
@Reverse = ($$Price[$count]) x $N_1;
for(my $i = $count - 1; $i >= 0; $i--){
if($Up == 1){
if(($Reverse[$N] > $$Price[$i]) || ($TempLow > $$Price[$i])){
# 下降トレンドへ
my $tmp = $Reverse[1];
@Reverse = ($TempHigh) x $N_1;
# 一本目
$Reverse[1] = $tmp;
$Reverse[0] = $$Price[$i];
$TempLow = $$Price[$i];
$Ashi = 1;
# Flag
$Up = 0;
$Down = 1;
$Check = 1;
}else {
# 高値更新
if($TempHigh < $$Price[$i]){
# 配列を後ろ一つずらす
for(my $j = $N; $j > 0; $j--){
$Reverse[$j] = $Reverse[$j - 1]
}
$Reverse[0] = $$Price[$i];
$TempHigh = $$Price[$i];
# 足
$Ashi++;
# Flag
$Check = 1;
}
}
}else {
if($Down == 1){
if(($Reverse[$N] < $$Price[$i]) || ($TempHigh < $$Price[$i])){
# 上昇トレンドへ
my $tmp = $Reverse[1];
@Reverse = ($TempLow) x $N_1;
# 一本目
$Reverse[1] = $tmp;
$Reverse[0] = $$Price[$i];
$TempHigh = $$Price[$i];
$Ashi = -1;
# Flag
$Up = 1;
$Down = 0;
$Check = 1;
}else {
# 安値更新
if($TempLow > $$Price[$i]){
# 配列を後ろ一つずらす
for(my $j = $N; $j > 0; $j--){
$Reverse[$j] = $Reverse[$j - 1]
}
$Reverse[0] = $$Price[$i];
$TempLow = $$Price[$i];
# 足
$Ashi--;
# Flag
$Check = 1;
}
}
}
}

if($Check == 1){
if($Up == 1){
$Temp{'shinne'}->[$Number] = $Reverse[0];
$Temp{'high'}->[$Number] = $TempHigh;
$Temp{'low'}->[$Number] = $Reverse[1];
$Temp{'ashi'}->[$Number] = $Ashi;
}else {
if($Down == 1){
$Temp{'shinne'}->[$Number] = $Reverse[0];
$Temp{'high'}->[$Number] = $Reverse[1];
$Temp{'low'}->[$Number] = $TempLow;
$Temp{'ashi'}->[$Number] = $Ashi;
}
}
$Number++;
# Flag
$Check = 0;
}
}

# 先頭を最新にする
$shinne{'count'} = $Number - 1;
for(my $i = 0; $i < $Number; $i++){
# 新値足 Shin Ne Ashi
$shinne{'shinne'}->[$i] = $Temp{'shinne'}->[$Number - ($i + 1)];
$shinne{'high'}->[$i] = $Temp{'high'}->[$Number - ($i + 1)];
$shinne{'low'}->[$i] = $Temp{'low'}->[$Number - ($i + 1)];
$shinne{'ashi'}->[$i] = $Temp{'ashi'}->[$Number - ($i + 1)];
}

return %shinne;
}

時系列

# 新値足 Shin Ne Ashi
# 引数 N本足 値 ($N, \@Price)
# 戻り値 hash {'shinne'} {'high'} {'low'} {'ashi'} {'count'} (%shinne)
sub SHINNE{
my ($N, $Price) = @_;
my %shinne = ();
my %Temp = ();
my @Reverse = ();
my $TempHigh = 0;
my $TempLow = 0;
my $N_1 = $N + 1;
my $Up = 1;
my $Down = 1;
my $Ashi = 0;
my $count = @$Price - 1;

# N本足と配列数の確認
if(($N <= 0) || ($count < 0)){
return 0;
}

# 計算
$TempHigh = $$Price[$count];
$TempLow = $$Price[$count];
@Reverse = ($$Price[$count]) x $N_1;
for(my $i = $count - 1; $i >= 0; $i--){
if($Up == 1){
if(($Reverse[$N] > $$Price[$i]) || ($TempLow > $$Price[$i])){
# 下降トレンドへ
my $tmp = $Reverse[1];
@Reverse = ($TempHigh) x $N_1;
# 一本目
$Reverse[1] = $tmp;
$Reverse[0] = $$Price[$i];
$TempLow = $$Price[$i];
$Ashi = 1;
# Flag
$Up = 0;
$Down = 1;
}else {
# 高値更新
if($TempHigh < $$Price[$i]){
# 配列を後ろ一つずらす
for(my $j = $N; $j > 0; $j--){
$Reverse[$j] = $Reverse[$j - 1]
}
$Reverse[0] = $$Price[$i];
$TempHigh = $$Price[$i];
# 足
$Ashi++;
}
}
}else {
if($Down == 1){
if(($Reverse[$N] < $$Price[$i]) || ($TempHigh < $$Price[$i])){
# 上昇トレンドへ
my $tmp = $Reverse[1];
@Reverse = ($TempLow) x $N_1;
# 一本目
$Reverse[1] = $tmp;
$Reverse[0] = $$Price[$i];
$TempHigh = $$Price[$i];
$Ashi = -1;
# Flag
$Up = 1;
$Down = 0;
}else {
# 安値更新
if($TempLow > $$Price[$i]){
# 配列を後ろ一つずらす
for(my $j = $N; $j > 0; $j--){
$Reverse[$j] = $Reverse[$j - 1]
}
$Reverse[0] = $$Price[$i];
$TempLow = $$Price[$i];
# 足
$Ashi--;
}
}
}
}

# 新値足 Shin Ne Ashi
if($Up == 1){
$shinne{'shinne'}->[$i] = $Reverse[0];
$shinne{'high'}->[$i] = $TempHigh;
$shinne{'low'}->[$i] = $Reverse[1];
$shinne{'ashi'}->[$i] = $Ashi;
}else {
if($Down == 1){
$shinne{'shinne'}->[$i] = $Reverse[0];
$shinne{'high'}->[$i] = $Reverse[1];
$shinne{'low'}->[$i] = $TempLow;
$shinne{'ashi'}->[$i] = $Ashi;
}
}
}

$shinne{'count'} = $count - 1;

return %shinne;
}


参考URL
新値三本足-いま聞きたいQ&A
第20回 : 新値足
オンライン コンパイラ/インタプリタ
テクニカル分析
プロフィール

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

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

検索フォーム


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