Go Back   DailyFX Forex Forum | FX Forum > FXCM Products and Services > FXProgrammers > Discussion / Support Forum > General Discussion

Reply
 
Thread Tools Rate Thread
  #1 (permalink)  
Old 01-13-2009, 11:22 PM
Junior Member
 
Join Date: Dec 2008
Posts: 2
andreasmanske is on a distinguished road
Stochastic Indicator Formula

While trying to emulate the stochastic indicator values in my application I cant seem to figure out how trading station computes the Fast Stochastic D value from what is suppose to be a 5 period moving average of the K value but it doesn't quite add up. Does anyone know what kind of moving average they are using to compute the D value of the Fast Stochastic ( linear weighted, exponential, smoothed, simple ) ?
Reply With Quote
  #2 (permalink)  
Old 01-14-2009, 02:47 PM
Member
 
Join Date: Oct 2008
Posts: 593
Nikolay.Gekht is on a distinguished road
It is looks like the bug is in the fast stochastic calculation. Thank you for the information.
Reply With Quote
  #3 (permalink)  
Old 01-14-2009, 03:34 PM
Member
 
Join Date: Oct 2008
Posts: 593
Nikolay.Gekht is on a distinguished road
You can use the following correct implementation of the Stochastic fast until bug is fixed.

Code:
-- Indicator profile initialization routine
function Init()
    indicator:name("Stochastic Fast (Modified)");
    indicator:description("Stochastic Oscillator is a momentum indicator that shows the location of the current close relative to the high/low range over a set number of periods. Closing levels that are consistently near the top of the range indicate accumulation (buying pressure) and those near the bottom of the range indicate distribution (selling pressure).");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Oscillator);

    indicator.parameters:addInteger("K", "%K", "", 14, 2, 1000);
    indicator.parameters:addInteger("D", "%D", "", 3, 2, 1000);
    indicator.parameters:addColor("clrFirst", "%K color", "", core.rgb(0, 255, 0));
    indicator.parameters:addColor("clrSecond", "%D color", "", core.rgb(255, 0, 0));
end

-- Indicator instance initialization routine
local k;
local d;

local source = nil;

-- Streams block
local iK = nil;
local K = nil;
local D = nil;

-- Routine
function Prepare()
    k = instance.parameters.K;
    d = instance.parameters.D;
    source = instance.source;

    local name = profile:id() .. "(" .. source:name() .. ", " .. k .. ", " .. d .. ")";
    instance:name(name);
    K = instance:addStream("K", core.Line, name .. ".K", "K", instance.parameters.clrFirst, source:first() + k);
    D = instance:addStream("D", core.Line, name .. ".D", "D", instance.parameters.clrSecond, source:first() + k + d);
end

-- Indicator calculation routine
function Update(period)
    if period >= K:first() then
        local kRange = core.rangeTo(period, k);
        local ll = core.min(source.low, kRange);
        local hh = core.max(source.high, kRange);
        K[period] = 100 * ((source.close[period] - ll) / (hh - ll));
    end
    if period >= D:first() then
        local dRange = core.rangeTo(period, d);
        D[period] = core.avg(K, dRange);
    end
end
Instruction:
- Copy the code above and save it as a text file SFKM.lua
- Choose Charts->Chart->Manage Custom Indicator menu item
- Press Load
- Point to the file saved on the first step
- Now you have SFKM indicator in the list of indicators.

This implementation 100% meets all popular descriptions of this indicator.
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Disclaimer: Trading foreign exchange on margin carries a high level of risk, and may not be suitable for all investors. The high degree of leverage can work against you as well as for you. Before deciding to trade foreign exchange you should carefully consider your investment objectives, level of experience, and risk appetite. The possibility exists that you could sustain a loss of some or all of your initial investment and therefore you should not invest money that you cannot afford to lose. You should be aware of all the risks associated with foreign exchange trading, and seek advice from an independent financial advisor if you have any doubts. Any opinions, news, research, analyses, prices, or other information contained on this website is provided as general market commentary and does not constitute investment advice. Forex Capital Markets LLC. will not accept liability for any loss or damage, including without limitation to, any loss of profit, which may arise directly or indirectly from use of or reliance on such information.

All times are GMT -5. The time now is 04:27 AM.
Copyright ©2009 Daily FX. All Rights Reserved.