FXCM Forex Trading

True stochastic indicator

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

True stochastic indicator

Postby Alexander.Gettinger » Sun Sep 05, 2010 10:48 pm

viewtopic.php?f=27&t=1953
Indicator draw 3 stochastics on one chart.

TrueStochastic.png


Code: Select all
function Init()
    indicator:name("True stochastic");
    indicator:description("True stochastic");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Oscillator);
   
    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addInteger("PeriodK1", "Period K for stochastic 1", "Period K for stochastic 1", 8);
    indicator.parameters:addInteger("PeriodD1", "Period D for stochastic 1", "Period D for stochastic 1", 3);
    indicator.parameters:addInteger("PeriodK2", "Period K for stochastic 2", "Period K for stochastic 2", 16);
    indicator.parameters:addInteger("PeriodD2", "Period D for stochastic 2", "Period D for stochastic 2", 3);
    indicator.parameters:addInteger("PeriodK3", "Period K for stochastic 3", "Period K for stochastic 3", 34);
    indicator.parameters:addInteger("PeriodD3", "Period D for stochastic 3", "Period D for stochastic 3", 3);

    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("clr1", "Color of Stochastic 1", "Color of Stochastic 1", core.rgb(0, 255, 0));
    indicator.parameters:addColor("clr2", "Color of Stochastic 2", "Color of Stochastic 2", core.rgb(255, 0, 0));
    indicator.parameters:addColor("clr3", "Color of Stochastic 3", "Color of Stochastic 3", core.rgb(0, 0, 255));
end

local first;
local source = nil;
local PeriodK1;
local PeriodD1;
local PeriodK2;
local PeriodD2;
local PeriodK3;
local PeriodD3;
local Stochastic1;
local Stochastic2;
local Stochastic3;
local buff1;
local buff2;
local buff3;

function Prepare()
    source = instance.source;
    PeriodK1=instance.parameters.PeriodK1;
    PeriodD1=instance.parameters.PeriodD1;
    PeriodK2=instance.parameters.PeriodK2;
    PeriodD2=instance.parameters.PeriodD2;
    PeriodK3=instance.parameters.PeriodK3;
    PeriodD3=instance.parameters.PeriodD3;
    Stochastic1 = core.indicators:create("STOCHASTIC", source, PeriodK1,PeriodD1,2);
    Stochastic2 = core.indicators:create("STOCHASTIC", source, PeriodK2,PeriodD2,2);
    Stochastic3 = core.indicators:create("STOCHASTIC", source, PeriodK3,PeriodD3,2);
    first = math.max(Stochastic1.DATA:first(),Stochastic2.DATA:first(),Stochastic3.DATA:first())+2;
    local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.PeriodK1 .. ", " .. instance.parameters.PeriodD1 .. ", " .. instance.parameters.PeriodK2 .. ", " .. instance.parameters.PeriodD2 .. ", " .. instance.parameters.PeriodK3 .. ", " .. instance.parameters.PeriodD3 .. ")";
    instance:name(name);
    buff1 = instance:addStream("Stochastic1", core.Line, name .. ".Stochastic1", "Stochastic1", instance.parameters.clr1, first);
    buff2 = instance:addStream("Stochastic2", core.Line, name .. ".Stochastic2", "Stochastic2", instance.parameters.clr2, first);
    buff3 = instance:addStream("Stochastic3", core.Line, name .. ".Stochastic3", "Stochastic3", instance.parameters.clr3, first);
end

function Update(period, mode)
    Stochastic1:update(mode);
    Stochastic2:update(mode);
    Stochastic3:update(mode);
    if period>first+PeriodK1 then
     buff1[period]=Stochastic1.K[period];
    end
    if period>first+PeriodK2 then
     buff2[period]=Stochastic2.K[period];
    end
    if period>first+PeriodK3 then
     buff3[period]=Stochastic3.K[period];
    end
end

TrueStochastic.lua
(4.21 KiB) Downloaded 456 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 2713
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: True stochastic indicator

Postby bourik » Fri Feb 04, 2011 5:48 am

Hello

is it possible to modify the code to be able to change the size and the style of the differents stochastics which composed this indicator

Thanks
bourik
 
Posts: 13
Joined: Fri Feb 04, 2011 4:09 am

Re: True stochastic indicator

Postby Apprentice » Fri Feb 04, 2011 6:16 am

Style Option Added.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 16975
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: True stochastic indicator

Postby bourik » Fri Feb 04, 2011 6:26 am

Thanks a lot

I don't speak very well english to tell what I think about your job but your like a god for me :D

Have a good week end
bourik
 
Posts: 13
Joined: Fri Feb 04, 2011 4:09 am

Re: True stochastic indicator

Postby bourik » Fri Feb 04, 2011 6:31 am

Thanks you very very much ;)
bourik
 
Posts: 13
Joined: Fri Feb 04, 2011 4:09 am

Re: True stochastic indicator

Postby Apprentice » Fri Feb 17, 2017 10:10 am

Indicator was revised and updated.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 16975
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot] and 13 guests

cron