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

Reply
 
Thread Tools Rate Thread
  #1 (permalink)  
Old 07-02-2009, 10:48 AM
Registered User
 
Join Date: Jul 2009
Posts: 4
jludwig is an unknown quantity at this point
How to reference Instrument information

How can I reference the pipsize in a custom indicator? Any code examples?
Reply With Quote
  #2 (permalink)  
Old 07-03-2009, 02:52 PM
Member
 
Join Date: Oct 2008
Posts: 465
Nikolay.Gekht is on a distinguished road
An example of the pipsize usage is in the Swing Index standard indicator. Please look at the Prepare method.
Code:
-- The formula is described in the Kaufman "Trading Systems and Methods" chapter 12 "Charting Systems" (page 286-287)

-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
    indicator:name(resources:get("name"));
    indicator:description(resources:get("description"));
    indicator:requiredSource(core.Bar);
    indicator:type(core.Oscillator);

    indicator.parameters:addColor("clrSI", resources:get("param_clrSI_name"), resources:get("param_clrSI_description"), core.rgb(255, 0, 0));
end

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

local first;
local source = nil;

-- Streams block
local SI = nil;
local T = nil;

-- Routine
function Prepare()
    source = instance.source;
    first = source:first() + 1;

    local name = profile:id() .. "(" .. source:name() .. ")";
    instance:name(name);
    SI = instance:addStream("SI", core.Line, name, "SI", instance.parameters.clrSI, first)
    T = source:pipSize() * 300;
end

-- Indicator calculation routine
function Update(period)
    if period >= first then
        local nom = source.close[period] - source.close[period - 1]
            + (.5 * (source.close[period] - source.open[period]))
            + (.25 * (source.close[period - 1] - source.open[period - 1]));

        local closePrev = source.close[period - 1];
        local highCurr = source.high[period];
        local lowCurr = source.low[period];
        local hc = math.abs(highCurr - closePrev);
        local lc = math.abs(lowCurr - closePrev);
        local hl = math.abs(highCurr - lowCurr);
        local co = math.abs(closePrev - source.open[period - 1]);

        local TR = math.max(hc, lc, hl);
        local ER = 0;
        if (closePrev > highCurr) then
            ER = hc;
        elseif (closePrev < lowCurr) then
            ER = lc;
        end
        local SH = co;
        local R = TR - 0.5 * ER + 0.25 * SH;
        local K = math.max(hc, lc);

        if (math.abs(R) < 1e-10) then
            SI[period] = 0;
        else
            SI[period] = 50.0 * nom * (K / T) / R;
        end
    end
end
Reply With Quote
  #3 (permalink)  
Old 07-03-2009, 04:25 PM
Registered User
 
Join Date: Jul 2009
Posts: 4
jludwig is an unknown quantity at this point
Doesn't work for me

When I do this, I get "attempt to call method 'pipSize' (a nil value)"
Reply With Quote
  #4 (permalink)  
Old 07-07-2009, 12:57 PM
Member
 
Join Date: Oct 2008
Posts: 465
Nikolay.Gekht is on a distinguished road
Sorry. This method is introduced in the last release of the Marketscope. This release will be available in July. I apologize for this inconvenience.
Reply With Quote
Reply

Tags
pipsize sdk

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 02:25 PM.
Copyright ©2009 Daily FX. All Rights Reserved.