Sorry for delay.
What could I do in the current version:
1) The indicator displays CCI(10) in green and EMA(CCI(10), 3) in red.
2) It also draws to lines: red +100 and green -100
3) It also draws bars in case the EMA crossed red or green lines AND CCI also crosses them in the previous 5 periods.
If you don't like bars, just remove lines I marked in the code below (look for "-- remove")
- Code: Select all
-- 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("Rubicon CCI");
indicator:description("");
indicator:requiredSource(core.Bar);
indicator:type(core.Oscillator);
indicator.parameters:addInteger("CCI_N", "CCI parameter", "No description", 10);
indicator.parameters:addInteger("EMA_N", "EMA parameter", "No description", 3);
indicator.parameters:addColor("CCI_color", "Color of CCI", "Color of CCI", core.rgb(0, 255, 0));
indicator.parameters:addColor("EMA_color", "Color of EMA", "Color of EMA", 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 CCI_N;
local EMA_N;
local source = nil;
-- Streams block
local CCI = nil;
local EMA = nil;
local BARL = nil;
local BARS = nil;
local L1 = nil;
local L2 = nil;
local _CCI = nil;
local _EMA = nil;
-- Routine
function Prepare()
CCI_N = instance.parameters.CCI_N;
EMA_N = instance.parameters.EMA_N;
source = instance.source;
local name = profile:id() .. "(" .. source:name() .. ", " .. CCI_N .. ", " .. EMA_N .. ")";
instance:name(name);
L1 = instance:addStream("L1", core.Line, name .. ".L1", "L1", core.rgb(255, 0, 0), 0);
L2 = instance:addStream("L2", core.Line, name .. ".L2", "L2", core.rgb(0, 255, 0), 0);
-- remove two lines below if don't want bars
BARS = instance:addStream("BS", core.Bar, name .. ".BS", "BS", core.rgb(255, 0, 0), 0);
BARL = instance:addStream("BL", core.Bar, name .. ".BL", "BL", core.rgb(0, 255, 0), 0);
_CCI = core.indicators:create("CCI", source, CCI_N);
_EMA = core.indicators:create("EMA", _CCI.DATA, EMA_N);
CCI = instance:addStream("CCI", core.Line, name .. ".CCI", "CCI", instance.parameters.CCI_color, _CCI.DATA:first());
CCI:addLevel(-100);
CCI:addLevel(0);
CCI:addLevel(100);
EMA = instance:addStream("EMA", core.Line, name .. ".EMA", "EMA", instance.parameters.EMA_color, _EMA.DATA:first());
end
-- Indicator calculation routine
-- TODO: Add your code for calculation output values
function Update(period, mode)
local i;
_CCI:update(mode);
_EMA:update(mode);
L1[period] = 100;
L2[period] = -100;
if period >= _CCI.DATA:first() then
CCI[period] = _CCI.DATA[period];
end
if period >= _EMA.DATA:first() then
EMA[period] = _EMA.DATA[period];
end
-- remove from here if you don't like bars
if period >= _EMA.DATA:first() + 6 and period >= _CCI.DATA:first() + 6 then
if core.crossesOver(_EMA.DATA, -100, period) then
for i = period, period - 5, -1 do
if core.crossesOver(_CCI.DATA, -100, i) then
BARL[period] = -75;
break;
end
end
elseif core.crossesUnder(_EMA.DATA, 100, period) then
for i = period, period - 5, -1 do
if core.crossesUnder(_CCI.DATA, 100, i) then
BARS[period] = 75;
break;
end
end
end
end
-- remove to here if you don't like bars
end
Want will I be able to do in the new release of marketscope?
1) highlight area between +100 and -100 lines
2) replace bars with arrows pointed below and above +100/-100 lines.