Go Back   DailyFX Forum > FXCM Products and Services > FXProgrammers > Discussion / Support Forum > Indicator SDK Support

Reply
 
Thread Tools Rate Thread
  #1 (permalink)  
Old 09-22-2009, 06:08 PM
Member
 
Join Date: Oct 2008
Posts: 474
Nikolay.Gekht is on a distinguished road
Example: Acceleration/Deceleration

Here is an examples of Acceleration/Deceleration oscillator as it is described at Accelerator/Decelerator Oscillator - Bill Williams - Technical Indicators - Technical Analysis

How to install:

1) Create the file AC.lua
2) Copy the code below into this file
3) Save the file
or
1,2,3) Just right-click on this link and choose "Save As..." from the menu.

4) Go to "Charts/Chart/Manage Custom Indicators" menu of the Trading Station
5) Click "Load"
6) Choose the AC.lua file create at the previous steps

Please note that Awesome Oscillator indicator must be also installed (Example: Awesome Oscillator) and named AO.lua

Code:
function Init()
    indicator:name("Acceleration/Deceleration");
    indicator:description("No description");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Oscillator);

    indicator.parameters:addInteger("FM", "Fast Moving Average for Awesome oscillator", "The number of periods to calculate the fast moving average of the median price", 5, 2, 10000);
    indicator.parameters:addInteger("SM", "Slow Moving Average for Awesome oscillator", "The number of periods to calculate the slow moving average of the median price", 35, 2, 10000);
    indicator.parameters:addInteger("M", "Moving Average for Acceleration/Deceleration", "The number of periods to calculate the moving average of the AO", 5, 2, 10000);
    indicator.parameters:addColor("CL_color", "Color for covering line", "Color for covering line", core.rgb(255, 255, 255));
    indicator.parameters:addColor("GO_color", "Color for higher bars", "Color for higher bars", core.rgb(0, 255, 0));
    indicator.parameters:addColor("RO_color", "Color for lower bars", "Color for lower bars", core.rgb(255, 0, 0));
end

local FM;
local SM;
local M;

local first;
local source = nil;

-- Streams block
local CL = nil;
local GO = nil;
local RO = nil;

local AO = nil;
local MVA = nil;

function Prepare()
    FM = instance.parameters.FM;
    SM = instance.parameters.SM;
    M = instance.parameters.M;

    source = instance.source;

    AO = core.indicators:create("AO", source, FM, SM);
    MVA = core.indicators:create("MVA", AO.DATA, M);
    first = MVA.DATA:first();

    local name = profile:id() .. "(" .. source:name() .. ", " .. FM .. ", " .. SM .. ", " .. M .. ")";
    instance:name(name);
    CL = instance:addStream("AC", core.Line, name .. ".AC", "AC", instance.parameters.CL_color, first);
    CL:addLevel(0);
    GO = instance:addStream("GO", core.Bar, name .. ".GO", "GO", instance.parameters.GO_color, first);
    RO = instance:addStream("RO", core.Bar, name .. ".RO", "RO", instance.parameters.RO_color, first);
end

function Update(period, mode)
    AO:update(mode);
    MVA:update(mode);

    if (period >= first) then
        CL[period] = AO.DATA[period] - MVA.DATA[period];
    end
    if (period >= first + 1) then
        if (CL[period] > CL[period - 1]) then
            GO[period] = CL[period];
        else
            RO[period] = CL[period];
        end
    end
end

Last edited by Nikolay.Gekht; 09-22-2009 at 06:12 PM..
Reply With Quote
  #2 (permalink)  
Old 09-23-2009, 12:50 AM
Registered User
 
Join Date: Sep 2009
Posts: 4
dorischg is an unknown quantity at this point
Thumbs up

Thank you very much!
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 10:01 PM.
Copyright ©2009 Daily FX. All Rights Reserved.