Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

GRaB indicator
 Post subject: GRaB indicator Post rating: 0   New post Posted: Sat 30 Jul, 2011, 21:34 

User rating: 0
Joined: Sat 30 Jul, 2011, 21:27
Posts: 1
Location: FR
Hello,

I don't know if this is here (if not all my apologies) we can ask if someone knows how to create the GRaB indicator ?

I only have this base to help (from Marketscope):

-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
-- TODO: Add minimal and maximal value of numeric parameters and default color of the streams
function Init()
indicator:name("Grab Candles");
indicator:description("Grab Candles");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);


indicator.parameters:addGroup("MA");
indicator.parameters:addInteger("Period", "Period", "Period", 34);

indicator.parameters:addString("Method", "Method", "Method" , "MVA");
indicator.parameters:addStringAlternative("Method", "MVA", "MVA" , "MVA");
indicator.parameters:addStringAlternative("Method", "EMA", "EMA" , "EMA");
indicator.parameters:addStringAlternative("Method", "LWMA", "LWMA" , "LWMA");
indicator.parameters:addStringAlternative("Method", "TMA", "TMA" , "TMA");
indicator.parameters:addStringAlternative("Method", "SMMA", "SMMA" , "SMMA");
indicator.parameters:addStringAlternative("Method", "KAMA", "KAMA" , "KAMA");
indicator.parameters:addStringAlternative("Method", "WMA", "WMA" , "WMA");


indicator.parameters:addGroup("Style");
indicator.parameters:addBoolean("Show", "Show MA Lines", "", true);
indicator.parameters:addColor("Short_Up", "Color of Short Up", "", core.rgb(255, 0, 0));
indicator.parameters:addColor("Short_Down", "Color of Short Up", "", core.rgb(200, 0, 0));
indicator.parameters:addColor("Long_Up", "Color of Long Up", "", core.rgb(0, 255, 0));
indicator.parameters:addColor("Long_Down", "Color of Long Down", "", core.rgb(0, 200, 0));
indicator.parameters:addColor("Range_Up", "Color of Range Up", "", core.rgb(128, 128, 128));
indicator.parameters:addColor("Range_Down", "Color of Range Down", "", core.rgb(100, 100, 100));
end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- TODO: Refine the first period calculation for each of the output streams.
-- TODO: Calculate all constants, create instances all subsequent indicators and load all required libraries
-- Parameters block
local Period;

local first;
local source = nil;

-- Streams block
local Open = nil;
local Close = nil;
local High = nil;
local Low = nil;

local Method;


local MA={};
local OUT={};

local Show;
-- Routine
function Prepare()
Period = instance.parameters.Period;
source = instance.source;
Show = instance.parameters.Show;
Method = instance.parameters.Method;


local name = profile:id() .. "(" .. source:name() .. ", " .. Method .. ", " .. Period .. ")";
instance:name(name);


MA["High"] = core.indicators:create(Method, source.high, Period);
MA["Low"] = core.indicators:create(Method, source.low, Period);
MA["Close"] = core.indicators:create(Method, source.close, Period);

first = MA["Low"].DATA:first();

Open = instance:addStream("O", core.Line, name .. ".Open", "Open", core.rgb(0, 0, 0), first);
Close = instance:addStream("C", core.Line, name .. ".Close", "Close", core.rgb(0, 0, 0), first);
High = instance:addStream("H", core.Line, name .. ".High", "High", core.rgb(0, 0, 0), first);
Low = instance:addStream("L", core.Line, name .. ".Low", "Low", core.rgb(0, 0, 0), first);

instance:createCandleGroup("ZONE", "", Open, High, Low, Close);

if Show then
OUT["High"] = instance:addStream("Open", core.Line, name .. ".Open", "Open", instance.parameters.Short_Up, first);
OUT["Low"] = instance:addStream("Close", core.Line, name .. ".Close", "Close", instance.parameters.Long_Up, first);
OUT["Close"] = instance:addStream("High", core.Line, name .. ".High", "High", instance.parameters.Range_Up, first);
else

OUT["High"] = instance:addInternalStream (0, 0);
OUT["Low"] = instance:addInternalStream (0, 0);
OUT["Close"] = instance:addInternalStream (0, 0);

end


end

-- Indicator calculation routine
-- TODO: Add your code for calculation output values
function Update(period,mode)
if period < first or not source:hasData(period) then
return;
end

MA["High"]:update(mode);
MA["Low"]:update(mode);
MA["Close"]:update(mode);

OUT["High"][period]= MA["High"].DATA[period];
OUT["Low"][period]= MA["Low"].DATA[period];
OUT["Close"][period]= MA["Close"].DATA[period];

Open[period] = source.open[period];
Close[period] = source.close[period];
High[period] = source.high[period];
Low[period] = source.low[period];


if source.open[period]<= source.close[period] and source.close[period] > MA["High"].DATA[period] then

Open:setColor(period, instance.parameters.Long_Up);
elseif source.open[period] >= source.close[period] and source.close[period] > MA["High"].DATA[period] then

Open:setColor(period, instance.parameters.Long_Down);

end


if source.open[period]<= source.close[period] and source.close[period] < MA["Low"].DATA[period] then

Open:setColor(period, instance.parameters.Short_Up);
elseif source.open[period] >= source.close[period] and source.close[period] < MA["Low"].DATA[period] then

Open:setColor(period, instance.parameters.Short_Down);
end


if source.open[period]<= source.close[period] and source.close[period] < MA["High"].DATA[period] and source.close[period] > MA["Low"].DATA[period] then

Open:setColor(period, instance.parameters.Range_Up);
elseif source.open[period] >=source.close[period] and source.close[period] < MA["High"].DATA[period] and source.close[period] > MA["Low"].DATA[period] then

Open:setColor(period, instance.parameters.Range_Down);

end
end


Thanks in advance for your answer.
Kind regards


 
 Post subject: Re: GRaB indicator Post rating: 0   New post Posted: Tue 02 Aug, 2011, 16:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The source code for many indicators is published in JForex API, so you can take them as an example for your own indicator.
For an indicator which draws custom bars see:
com.dukascopy.indicators.HeikinAshiIndicator
And for an indicator which draw multiple output lines see:
com.dukascopy.indicators.EMAEnvelopesIndicator


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com