indiTraders - Forum for the Active Indian Trader  

Go Back   indiTraders - Forum for the Active Indian Trader > Tools > Software > MetaTrader

Reply
 
Bookmark and Share LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 21-06-2013, 01:09 PM
bharatk8 bharatk8 is offline
Regulars
 
Join Date: Jan 2010
Posts: 271
Thanks: 212
Thanked 120 Times in 70 Posts
bharatk8 will become famous soon enoughbharatk8 will become famous soon enough
Default help required to create .mq4 file

I have not used meta editor of MT4 for compiling and making .mq4 file.

I have a code which plots BB with deviation in decimal points. Pl. convert it to .mq4 file

-- The indicator corresponds to the Bollinger Bands indicator in MetaTrader.
-- The formula is described in the Kaufman "Trading Systems and Methods" chapter 5 "Trend System" (page 91-94)

-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
indicator:name("Bollinger Bands Decimal - Original");
indicatorescription("Original Bollinger Bands with Decimal Support");
indicator:requiredSource(core.Tick);
indicator:type(core.Indicator);

indicator.parameters:addDouble("N", "Number of periods", "Number of periods", 20.0);
indicator.parameters:addDouble("Dev", "Number of standard deviations", "Number of standard deviations", 2.0);
indicator.parameters:addColor("clrBBP", "clrBBP", "clrBBP", core.rgb(255, 0, 0));
indicator.parameters:addColor("clrBBM", "clrBBM", "clrBBM", core.rgb(0, 255, 0));
indicator.parameters:addColor("clrBBA", "clrBBA", "clrBBA", core.rgb(0, 0, 255));
end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- Parameters block
local N;
local D;

local firstPeriod;
local source = nil;

-- Streams block
local TL = nil;
local BL = nil;

-- Routine
function Prepare()
N = instance.parameters.N;
D = instance.parameters.Dev;
source = instance.source;
firstPeriod = source:first() + N - 1;

local name = "Bollinger Bands in Decimal (" .. N .. ", " .. D .. ")";
instance:name(name);

TL = instance:addStream("TL", core.Line, name .. ".TL", "TL", instance.parameters.clrBBP, firstPeriod)
BL = instance:addStream("BL", core.Line, name .. ".BL", "BL", instance.parameters.clrBBM, firstPeriod)
AL = instance:addStream("AL", core.Line, name .. ".AL", "AL", instance.parameters.clrBBA, firstPeriod)
end

-- Indicator calculation routine
function Update(period)
if period >= firstPeriod then
local p = core.rangeTo(period, N);
local ml = core.avg(source, p);
local d = core.stdev(source, p);

TL[period] = ml + D * d;
BL[period] = ml - D * d;
AL[period] = ml;
end
end




-- The indicator corresponds to the Bollinger Bands indicator in MetaTrader.
-- The formula is described in the Kaufman "Trading Systems and Methods" chapter 5 "Trend System" (page 91-94)

-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
indicator:name("Bollinger Bands Decimal - Original");
indicatorescription("Original Bollinger Bands with Decimal Support");
indicator:requiredSource(core.Tick);
indicator:type(core.Indicator);

indicator.parameters:addDouble("N", "Number of periods", "Number of periods", 20.0);
indicator.parameters:addDouble("Dev", "Number of standard deviations", "Number of standard deviations", 2.0);
indicator.parameters:addColor("clrBBP", "clrBBP", "clrBBP", core.rgb(255, 0, 0));
indicator.parameters:addColor("clrBBM", "clrBBM", "clrBBM", core.rgb(0, 255, 0));
indicator.parameters:addColor("clrBBA", "clrBBA", "clrBBA", core.rgb(0, 0, 255));
end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- Parameters block
local N;
local D;

local firstPeriod;
local source = nil;

-- Streams block
local TL = nil;
local BL = nil;

-- Routine
function Prepare()
N = instance.parameters.N;
D = instance.parameters.Dev;
source = instance.source;
firstPeriod = source:first() + N - 1;

local name = "Bollinger Bands in Decimal (" .. N .. ", " .. D .. ")";
instance:name(name);

TL = instance:addStream("TL", core.Line, name .. ".TL", "TL", instance.parameters.clrBBP, firstPeriod)
BL = instance:addStream("BL", core.Line, name .. ".BL", "BL", instance.parameters.clrBBM, firstPeriod)
AL = instance:addStream("AL", core.Line, name .. ".AL", "AL", instance.parameters.clrBBA, firstPeriod)
end

-- Indicator calculation routine
function Update(period)
if period >= firstPeriod then
local p = core.rangeTo(period, N);
local ml = core.avg(source, p);
local d = core.stdev(source, p);

TL[period] = ml + D * d;
BL[period] = ml - D * d;
AL[period] = ml;
end
end
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

indiTraders - Forum for the Active Indian Trader > Tools > Software > MetaTrader


Thread Tools
Display Modes

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT +5.5. The time now is 10:17 PM.


vBulletin Copyright by vBulletin

Content Relevant URLs by vBSEO 3.3.2