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

Reply
 
Thread Tools Rate Thread
  #1 (permalink)  
Old 09-23-2009, 05:55 PM
Member
 
Join Date: Oct 2008
Posts: 474
Nikolay.Gekht is on a distinguished road
Example: Gator

Here is a source code for the GATOR oscillator as it is described at Gator Oscillator by Bill Williams | Forex Indicators Guide.

1) Create the file gator.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 gator.lua file created at the previous steps

IMPORTANT NOTE At the moment of indicator writing (Sep, 23 2009), the indicator core library has an error which prevents the gator indicator from working well. Please, download the fixed core here and replace indicore2 file with this file in the ""C:\Program Files\Candleworks\FXTS2\" and/or "C:\Program Files\Candleworks\FXOrder2Go\" folders, in case your version is earlier than Sep, 23 2009.

Code:
-- initializes the indicator
function Init()
    indicator:name("Gator");
    indicator:description("")
    indicator:requiredSource(core.Tick);
    indicator:type(core.Oscillator);

    indicator.parameters:addInteger("JawN", "Number of periods for smoothing the alligator jaw", "", 13, 2, 1000);
    indicator.parameters:addInteger("JawS", "Number of periods for shifting the alligator jaw", "", 8, 1, 100);
    indicator.parameters:addInteger("TeethN", "Number of periods for smoothing the alligator teeth", "", 8, 2, 1000);
    indicator.parameters:addInteger("TeethS", "Number of periods for shifting the alligator teeth", "", 5, 1, 100);
    indicator.parameters:addInteger("LipsN", "Number of periods for smoothing the alligator lips", "", 5, 2, 1000);
    indicator.parameters:addInteger("LipsS", "Number of periods for shifting the alligator lips", "", 3, 1, 100);
    indicator.parameters:addString("MTH", "Alligator Smoothing method", "", "MVA");
    indicator.parameters:addStringAlternative("MTH", "MVA", "", "MVA");
    indicator.parameters:addStringAlternative("MTH", "EMA", "", "EMA");
    indicator.parameters:addStringAlternative("MTH", "LWMA", "", "LWMA");
    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

-- lines parameters
local JawN, JawS;
local TeethN, TeethS;
local LipsN, LipsC;

-- indicator source
local source;

-- alligator lines
local Jaw, Teeth, Lips;
-- alligator lines sources
local JawSrc, TeethSrc, LipsSrc;
-- gator bars
local Up, Down, UpRed, UpGreen, DownRed, DownGreen;
-- bar's parameters
local UpExtent, DownExtent;
local UpFirst, DownFirst;

-- process parameters and prepare for calculations
function Prepare()
    JawN = instance.parameters.JawN;
    JawS = instance.parameters.JawS;
    TeethN = instance.parameters.TeethN;
    TeethS = instance.parameters.TeethS;
    LipsN = instance.parameters.LipsN;
    LipsS = instance.parameters.LipsS;

    source = instance.source;

    JawSrc = core.indicators:create(instance.parameters.MTH, source, JawN, core.rgb(0, 0, 0));
    TeethSrc = core.indicators:create(instance.parameters.MTH, source, TeethN, core.rgb(0, 0, 0));
    LipsSrc = core.indicators:create(instance.parameters.MTH, source, LipsN, core.rgb(0, 0, 0));

    local name = profile:id() .. "(" .. source:name() .. ", " .. JawN .. "(" .. JawS .. ")," .. TeethN .. "(" .. TeethS .. ")," .. LipsN .. "(" .. LipsS .. "))";
    instance:name(name);


    Jaw = instance:addInternalStream(JawSrc.DATA:first() + JawS, JawS);
    Teeth = instance:addInternalStream(TeethSrc.DATA:first() + TeethS, TeethS);
    Lips = instance:addInternalStream(LipsSrc.DATA:first() + LipsS, LipsS);

    UpExtent = math.min(JawS, TeethS);
    UpFirst = math.max(Jaw:first(), Teeth:first());
    Up = instance:addStream("UP", core.Line, name .. ".UP", "UP", instance.parameters.CL_color, UpFirst, UpExtent);
    Up:addLevel(0);
    UpRed = instance:addStream("UPR", core.Bar, name .. ".UPR", "UPR", instance.parameters.RO_color, UpFirst, UpExtent);
    UpGreen = instance:addStream("UPG", core.Bar, name .. ".UPG", "UPG", instance.parameters.GO_color, UpFirst, UpExtent);

    DownExtent = math.min(TeethS, LipsS);
    DownFirst = math.max(Teeth:first(), Lips:first());
    Down = instance:addStream("DOWN", core.Line, name .. ".DN", "DN", instance.parameters.CL_color, DownFirst, DownExtent);
    DownRed = instance:addStream("DNR", core.Bar, name .. ".DNR", "DNR", instance.parameters.RO_color, DownFirst, DownExtent);
    DownGreen = instance:addStream("DNG", core.Bar, name .. ".DNG", "DNG", instance.parameters.GO_color, DownFirst, DownExtent);


end

-- Indicator calculation routine
function Update(period, mode)
    -- calculate alligator
    JawSrc:update(mode);
    TeethSrc:update(mode);
    LipsSrc:update(mode);

    if (period + JawS >= 0 and period >= JawSrc.DATA:first()) then
        Jaw[period + JawS] = JawSrc.DATA[period];
    end

    if (period + TeethS >= 0 and period >= TeethSrc.DATA:first()) then
        Teeth[period + TeethS] = TeethSrc.DATA[period];
    end

    if (period + LipsS >= 0 and period >= LipsSrc.DATA:first()) then
        Lips[period + LipsS] = LipsSrc.DATA[period];
    end
    -- calculate gator
    if period >= UpFirst then
        Up[period + UpExtent] = math.abs(Jaw[period + UpExtent] - Teeth[period + UpExtent]);
        if period >= UpFirst + 1 then
            if Up[period + UpExtent] >= Up[period + UpExtent - 1] then
                UpGreen[period + UpExtent] = Up[period + UpExtent];
            else
                UpRed[period + UpExtent] = Up[period + UpExtent];
            end
        end
    end
    if period >= DownFirst then
        Down[period + DownExtent] = -math.abs(Teeth[period + DownExtent] - Lips[period + DownExtent]);
        if period >= DownFirst + 1 then
            if Down[period + DownExtent] >= Down[period + DownExtent - 1] then
                DownGreen[period + DownExtent] = Down[period + DownExtent];
            else
                DownRed[period + DownExtent] = Down[period + DownExtent];
            end
        end
    end
end
Attached Images
 

Last edited by Nikolay.Gekht; 09-23-2009 at 05:57 PM..
Reply With Quote
  #2 (permalink)  
Old 11-01-2009, 11:46 PM
Registered User
 
Join Date: Sep 2009
Posts: 4
dorischg is an unknown quantity at this point
I have replaced the "indicore2" file and tried to add it to my chart, but it's not working. It showed "[string "gator.lua"]:97: index out of range". Is there any way to fix it?
Reply With Quote
  #3 (permalink)  
Old 11-02-2009, 11:24 AM
Member
 
Join Date: Oct 2008
Posts: 474
Nikolay.Gekht is on a distinguished road
Could you please ensure that you did not try to "Save As" the indicore2.dll directly to Marketscope's folder when Marketscope is already started? In that case, IE or Mozilla will not be able to replace the file because it is locked and just creates the new file named like indicore2(2).dll.
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:56 PM.
Copyright ©2009 Daily FX. All Rights Reserved.