Pl. convert this code to .mq4 file

bharatk8

Active Member
#1
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");
indicator:description("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");
indicator:description("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
 

KelvinHand

Well-Known Member
#2
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");
indicator:description("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");
indicator:description("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
Don't waste time. Bollinger Band is in every charting package.
In MT4 indicator window, change top, bottom and Middle lines to Red, Green, Blue and then same into the template will do.

if you want to customize your own bollingerband, download the code from here:
http://codebase.mql4.com/252

Modified the to the following and compiled will do:
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
 

Similar threads

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?