FC2ブログ

# Instantaneous Trend Line
# 引数 値 ($Price)
# 戻り値 hash {'trendline'} {'smooth'} (%itrend)
sub ITREND{
my ($Price) = @_;
my %itrend = ();
my $count = @$Price - 7;

my @Value1 = (0, 0, 0, 0, 0, 0, 0);
my $Value2 = 0;
my $Value3 = 0;
my $Value4 = 0;
my @Value5 = (0, 0);
my @Value11 = (0, 0);
my @InPhase = (0, 0);
my @Quadrature = (0, 0);
my @Phase = (0, 0);
my @DeltaPhase = (0) x 41;
my @InstPeriod = (0, 0);
my $Period = 0;
my $Trendline = 0;

# 配列数の確認
if($count < 0){
return 0;
}

# 計算
$Value11[0] = $$Price[$count + 1];
for(my $i = $count; $i >= 0; $i--){
# 配列の要素を1つ後ろに動かす
for(my $j = 6; $j >= 1; $j--){
$Value1[$j] = $Value1[$j - 1];
}
for(my $j = 40; $j >= 1; $j--){
$DeltaPhase[$j] = $DeltaPhase[$j - 1];
}
$Value5[1] = $Value5[0];
$Value11[1] = $Value11[0];
$InPhase[1] = $InPhase[0];
$Quadrature[1] = $Quadrature[0];
$Phase[1] = $Phase[0];
$InstPeriod[1] = $InstPeriod[0];

$Value1[0] = $$Price[$i] - $$Price[$i + 6];
$Value2 = $Value1[3];
$Value3 = (0.75 * ($Value1[0] - $Value1[6])) + (0.25 * ($Value1[2] - $Value1[4]));
$InPhase[0] = (0.33 * $Value2) + (0.67 * $InPhase[1]);
$Quadrature[0] = (0.2 * $Value3) + (0.8 * $Quadrature[1]);

if(abs($InPhase[0] +$InPhase[1]) > 0){
$Phase[0] = atan(abs(($Quadrature[0] + $Quadrature[1]) / ($InPhase[0] + $InPhase[1])));
}

$Phase[0] = 180 - $Phase[0] if(($InPhase[0] < 0) && ($Quadrature[0] > 0));
$Phase[0] = 180 + $Phase[0] if(($InPhase[0] < 0) && ($Quadrature[0] < 0));
$Phase[0] = 360 - $Phase[0] if(($InPhase[0] > 0) && ($Quadrature[0] < 0));

$DeltaPhase[0] = $Phase[1] - $Phase[0];
$DeltaPhase[0] = 360 + $Phase[1] - $Phase[0] if(($Phase[1] < 90) && ($Phase[0] > 270));
$DeltaPhase[0] = 1 if($DeltaPhase[0] < 1);
$DeltaPhase[0] = 60 if($DeltaPhase[0] > 60);

$InstPeriod[0] = 0;
$Value4 = 0;
for(my $j = 0; $j <= 40; $j++){
$Value4 += $DeltaPhase[$j];

if(($Value4 > 360) && ($InstPeriod[0] == 0)){
$InstPeriod[0] = $j;
last;
}
}

$InstPeriod[0] = $InstPeriod[1] if($InstPeriod[0] == 0);
$Value5[0] = (0.25 * $InstPeriod[0]) + (0.75 * $Value5[1]);

$Period = int($Value5[0] + 1);
$Trendline = 0;
for(my $j = 0; $j <= $Period + 1; $j++){
$Trendline += $$Price[$i + $j];
}
$Trendline = $Trendline / ($Period + 2) if($Period > 0);

$Value11[0] = (0.33 * ($$Price[$i] + (0.5 * ($$Price[$i] - $$Price[$i + 3])))) + (0.67 * $Value11[1]);

# Instantaneous Trend Line
$itrend{'trendline'}->[$i] = $Trendline;
$itrend{'smooth'}->[$i] = $Value11[0];
}

return %itrend;
}


AllAverages mq4のInstantaneous Trend Line

# Instantaneous Trend Line
# 引数 期間 値 ($Period, $Price)
# 戻り値 InstantaneousTrendLine (@itrend)
sub ITREND{
my ($Period, $Price) = @_;
my @itrend = ();
my $alpha = 2 / ($Period + 1);
my $count = @$Price - 5;

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

# 計算
$itrend[$count + 1] = ($$Price[$count + 1] + 2*$$Price[$count + 2]+ $$Price[$count + 3]) / 4;
$itrend[$count + 2] = ($$Price[$count + 2] + 2*$$Price[$count + 3]+ $$Price[$count + 4]) / 4;
for(my $i = $count; $i >= 0; $i--){
my $tmp1 = (($alpha - ($alpha * $alpha / 4)) * $$Price[$i]) + (0.5 * $alpha * $alpha * $$Price[$i + 1]) - (($alpha - (0.75 * $alpha * $alpha)) * $$Price[$i + 2]);
my $tmp2 = (2 * (1 - $alpha) * $itrend[$i + 1]) - ((1 - $alpha) * (1 - $alpha) * $itrend[$i + 2]);

# Instantaneous Trend Line
$itrend[$i] = $tmp1 + $tmp2;
}

return @itrend;
}
オンライン コンパイラ/インタプリタ
テクニカル分析
プロフィール

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

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

検索フォーム


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