FXCM Forex Trading

Forecast oscillator

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

Forecast oscillator

Postby Nikolay.Gekht » Sun Apr 18, 2010 2:50 pm

The forecast oscillator is developed by by Tushar Chande and is an extension of the Time Frame Forecast method.

The formula is:
Forecast Oscillator = Price - Previous Time Series Forecast / Price * 100

Interpretation:
The positive value of the indicator forecasts higher prices. The negative value forecasts the lower prices. Chande also recommends to user 3-day smoothing line as a trigger. When the oscillator falls below or crosses above the trigger line it shows a change of the trend.

forecast.png


Download:
forecast.lua
(1.66 KiB) Downloaded 902 times


Code: Select all
-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
    indicator:name("Forecast Oscillator");
    indicator:description("");
    indicator:requiredSource(core.Tick);
    indicator:type(core.Oscillator);

    indicator.parameters:addInteger("N", "N", "Number of periods", 20, 2, 300);
    indicator.parameters:addColor("FO_color", "Color", "Color of Forecast line", core.rgb(255, 0, 0));
end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- Parameters block
local N;

local first;
local source = nil;

-- Streams block
local FO = nil;

-- Routine
function Prepare()
    N = instance.parameters.N;
    source = instance.source;
    first = source:first() + N + 1;
    local name = profile:id() .. "(" .. source:name() .. ", " .. N .. ")";
    instance:name(name);
    FO = instance:addStream("F", core.Line, name, "F", instance.parameters.FO_color, first);
end

-- Indicator calculation routine
function Update(period)
    if period >= first then
        local sx, sy, sxy, sx2, i, t, a, b, tsf;
        t = N;
        sx = 0;
        sy = 0;
        sxy = 0;
        sx2 = 0;
        for i = period - N, period - 1, 1 do
            sy = sy + source[i];
            sx = sx + t;
            sx2 = sx2 + t * t;
            sxy = sxy + source[i] * t;
            t = t - 1;
        end
        b = (N * sxy - sx * sy) / (N * sx2 - sx * sx);
        a = (sy - b * sx) / N;
        tsf = a + b;
        FO[period] = (source[period] - tsf) / source[period] * 100;

    else
        FO[period] = nil;
    end
end
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1230
Joined: Wed Dec 16, 2009 6:39 pm
Location: Morrisville, NC

Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot], Exabot [Bot], Google [Bot] and 4 guests