Documente Academic
Documente Profesional
Documente Cultură
// Version 1.5
Express Forecast_Oscillator
Vars
series line, line_signal, price, senti(50);
series tsf, res1, Ema1;
numeric sumX, sumX2, sumXY, sumY, a, b, r;
numeric i, sumX0, sumX20, sumXY0, sumY0, LinReg1, LinRegSlope1;
Calculation
if IsFirstBar() then
begin
CalculateAtEveryTick(false);
SetYscaleFormat(GetPriceFormat());
for i = 0 to FinalBarIndex()
begin
if $Price = 3 then price[-i] = l[-i];
else
if $Price = 2 then price[-i] = h[-i];
else
if $Price = 1 then price[-i] = c[-i];
else
if $Price = 0 then price[-i] = o[-i];
end
end
//======================================
// Function LinReg
//======================================
if $period < CurrentBarIndex() then
begin
sumx = 0;
sumy = 0;
sumx2 = 0;
sumxy = 0;
for i = 0 to $period - 1
begin
r = i - 1;
sumx = sumx + r ;
sumy = sumy + price[i];
sumx2 = sumx2 + r * r;
sumxy = sumxy + r * price[i];
end
b = (($period * sumXY) - (sumX * sumY)) / (($period * sumX2) - (sumX * sumX));
a = (sumY - (b * sumX)) /$period;
LinReg1 = a - b;
end
//======================================
// Function LinRegSlope
//======================================
if $period < CurrentBarIndex() then
begin
sumx0 = 0;
sumy0 = 0;
sumx20 = 0;
sumxy0 = 0;
for i = 0 to $period - 1
begin
r = i - 1;
sumx0 = sumx0 + r ;
sumy0 = sumy0 + price[i];
sumx20 = sumx20 + r * r;
sumxy0 = sumxy0 + r * price[i];
end
LinRegSlope1 = (($period * sumXY0) - (sumX0 * sumY0)) / (($period * sumX20) -
(sumX0 * sumX0)) * -1;
end
line = void;
line_signal = void;
//------------------------------------------------------------
if ($period + $signal_period ) < CurrentBarIndex() then
begin
tsf = LinReg1 + LinRegSlope1;
res1 = 100 * (price - tsf[ 1]) / price;
if IsFinalBar() then
begin
line[i] = void;
line_signal[i] = void;
ExpMovingAverage( res1, Ema1, $signal_period);
for i = CurrentBarIndex() downto 0
begin
if i < (CurrentBarIndex() - ($period + $signal_period + $period +
$signal_period)) then
begin
line[i] = res1[i] ;
line_signal[i] = Ema1[i];
end
SetYscaleFormat("%.3f");
interpretation
begin
sentiment = senti;
end