Any programmer experts willing to take this and change it to a MQ4 ??
-- 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("CUMULATIVE VOLUME INDEX");
indicator:description("CUMULATIVE VOLUME INDEX");
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator.parameters:addGroup("Selector");
local Currency={"USD", "EUR", "GBP", "CHF", "JPY", "AUD", "NZD", "CAD"};
local i;
indicator.parameters:addString("Currency" , "Base Currency ", "",Currency[1]);
for i =1, 8 , 1 do
indicator.parameters:addStringAlternative("Currency", Currency, "", Currency);
end
indicator.parameters:addGroup("Style");
indicator.parameters:addColor("color", "Color of CVI", "Color of CVI", core.rgb(255, 0, 0));
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 first;
local source = nil;
-- Streams block
local Out={};
local Currency;
local loading={};
local List={};
local Count;
local RawList, RawCount;
local SourceData={};
local pauto = "(%a%a%a)/(%a%a%a)";
local Color;
local host;
local offset;
local weekoffset;
local MA={};
-- Routine
function Prepare(nameOnly)
Method = instance.parameters.Method;
Color = instance.parameters.color;
Currency = instance.parameters.Currency;
host = core.host;
offset = host:execute("getTradingDayOffset");
weekoffset = host:execute("getTradingWeekOffset");
source = instance.source;
first = source:first();
local name = profile:id() .. "(" .. source:name() .. ", " .. Currency .. ")";
instance:name(name);
local crncy1, crncy2;
RawList, RawCount= getInstrumentList();
local i ;
local FLAG= false;
Count=0;
for i = 1, RawCount, 1 do
FLAG= false;
crncy1, crncy2 = string.match(RawList, pauto);
if (crncy1== Currency) or (crncy2== Currency )then
FLAG= true;
end
if FLAG then
Count = Count+ 1;
List[Count]= RawList
end
end
for i = 1, Count, 1 do
SourceData = core.host:execute("getSyncHistory", List, source:barSize(), source:isBid(), 0 , 200+i , 100+i);
loading = true;
end
if (not (nameOnly)) then
CVI = instance:addStream("CVI", core.Line, name, "CVI", Color, first);
end
end
function getInstrumentList()
local list={};
local count = 0;
local row, enum;
enum = core.host:findTable("offers"):enumerator();
row = enum:next();
while row ~= nil do
count = count + 1;
list[count] = row.Instrument;
row = enum:next();
end
return list, count;
end
local Advancing =0;
local Declining=0;
-- 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
Advancing =0;
Declining=0;
for i = 1, Count, 1 do
if loading then
return;
end
end
local i;
local p;
for i = 1, Count, 1 do
p= Initialization(i, period)
Calculate(i, p, period);
end
end
function Calculate(i,p, period)
if not p then
return;
end
local Num={0,0,0,0,0,0,0,0};
local j;
local crncy1, crncy2;
crncy1, crncy2 = string.match(List, pauto);
if crncy1 == Currency then
if SourceData.close > SourceData.close[p-1] then
Advancing= Advancing+ SourceData.volume;
elseif SourceData.close < SourceData.close[p-1] then
Declining= Declining + SourceData.volume;
end
elseif crncy2 == Currency then
if SourceData.close > SourceData.close[p-1] then
Declining= Declining + SourceData.volume;
elseif SourceData.close < SourceData.close[p-1] then
Advancing= Advancing+ SourceData.volume;
end
end
CVI[period]=CVI[period-1] + ( Advancing - Declining);
end
-- the function is called when the async operation is finished
function AsyncOperationFinished(cookie)
local i;
for i = 1, Count, 1 do
if cookie == 100+i then
loading = true;
elseif cookie == 200+i then
loading = false;
instance:updateFrom(0);
end
end
return core.ASYNC_REDRAW;
end
function Initialization(i,period)
local Candle;
Candle = core.getcandle(source:barSize(), source:date(period), offset, weekoffset);
if loading or SourceData:size() == 0 then
return false ;
end
if period < source:first() then
return false;
end
local p = core.findDate(SourceData, Candle, false);
-- candle is not found
if p < 0 then
return false;
else return p;
end
end
-- 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("CUMULATIVE VOLUME INDEX");
indicator:description("CUMULATIVE VOLUME INDEX");
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator.parameters:addGroup("Selector");
local Currency={"USD", "EUR", "GBP", "CHF", "JPY", "AUD", "NZD", "CAD"};
local i;
indicator.parameters:addString("Currency" , "Base Currency ", "",Currency[1]);
for i =1, 8 , 1 do
indicator.parameters:addStringAlternative("Currency", Currency, "", Currency);
end
indicator.parameters:addGroup("Style");
indicator.parameters:addColor("color", "Color of CVI", "Color of CVI", core.rgb(255, 0, 0));
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 first;
local source = nil;
-- Streams block
local Out={};
local Currency;
local loading={};
local List={};
local Count;
local RawList, RawCount;
local SourceData={};
local pauto = "(%a%a%a)/(%a%a%a)";
local Color;
local host;
local offset;
local weekoffset;
local MA={};
-- Routine
function Prepare(nameOnly)
Method = instance.parameters.Method;
Color = instance.parameters.color;
Currency = instance.parameters.Currency;
host = core.host;
offset = host:execute("getTradingDayOffset");
weekoffset = host:execute("getTradingWeekOffset");
source = instance.source;
first = source:first();
local name = profile:id() .. "(" .. source:name() .. ", " .. Currency .. ")";
instance:name(name);
local crncy1, crncy2;
RawList, RawCount= getInstrumentList();
local i ;
local FLAG= false;
Count=0;
for i = 1, RawCount, 1 do
FLAG= false;
crncy1, crncy2 = string.match(RawList, pauto);
if (crncy1== Currency) or (crncy2== Currency )then
FLAG= true;
end
if FLAG then
Count = Count+ 1;
List[Count]= RawList
end
end
for i = 1, Count, 1 do
SourceData = core.host:execute("getSyncHistory", List, source:barSize(), source:isBid(), 0 , 200+i , 100+i);
loading = true;
end
if (not (nameOnly)) then
CVI = instance:addStream("CVI", core.Line, name, "CVI", Color, first);
end
end
function getInstrumentList()
local list={};
local count = 0;
local row, enum;
enum = core.host:findTable("offers"):enumerator();
row = enum:next();
while row ~= nil do
count = count + 1;
list[count] = row.Instrument;
row = enum:next();
end
return list, count;
end
local Advancing =0;
local Declining=0;
-- 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
Advancing =0;
Declining=0;
for i = 1, Count, 1 do
if loading then
return;
end
end
local i;
local p;
for i = 1, Count, 1 do
p= Initialization(i, period)
Calculate(i, p, period);
end
end
function Calculate(i,p, period)
if not p then
return;
end
local Num={0,0,0,0,0,0,0,0};
local j;
local crncy1, crncy2;
crncy1, crncy2 = string.match(List, pauto);
if crncy1 == Currency then
if SourceData.close > SourceData.close[p-1] then
Advancing= Advancing+ SourceData.volume;
elseif SourceData.close < SourceData.close[p-1] then
Declining= Declining + SourceData.volume;
end
elseif crncy2 == Currency then
if SourceData.close > SourceData.close[p-1] then
Declining= Declining + SourceData.volume;
elseif SourceData.close < SourceData.close[p-1] then
Advancing= Advancing+ SourceData.volume;
end
end
CVI[period]=CVI[period-1] + ( Advancing - Declining);
end
-- the function is called when the async operation is finished
function AsyncOperationFinished(cookie)
local i;
for i = 1, Count, 1 do
if cookie == 100+i then
loading = true;
elseif cookie == 200+i then
loading = false;
instance:updateFrom(0);
end
end
return core.ASYNC_REDRAW;
end
function Initialization(i,period)
local Candle;
Candle = core.getcandle(source:barSize(), source:date(period), offset, weekoffset);
if loading or SourceData:size() == 0 then
return false ;
end
if period < source:first() then
return false;
end
local p = core.findDate(SourceData, Candle, false);
-- candle is not found
if p < 0 then
return false;
else return p;
end
end