Here is the STARC Bands indicator that was developed by user's request. Original topic with the request: http://www.fxcodebase.com/code/viewtopic.php?f=18&t=159
Description on how to use this indicator you can find here:
http://www.investopedia.com/terms/s/starc.asp
Screenshot:
Download:
Source:
- Code: Select all
--- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
indicator:name("STARC Band");
indicator:description("Indicates upper and lower limits of price movement.");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);
indicator.parameters:addInteger("USM", "Multiplier", "The deviation multiplier", 2);
indicator.parameters:addInteger("SMA_N", "Number of MVA periods", "The number of periods used in the Moving Average calculation", 6);
indicator.parameters:addInteger("ATR_N", "Number of ATR periods", "The number of periods used in the Average True Range calculation", 14);
indicator.parameters:addColor("UB_color", "Upper line color", "The color of the upper line", core.rgb(0, 255, 0));
indicator.parameters:addColor("LB_color", "Lower line color", "The color of the lower line", core.rgb(255,0,0));
indicator.parameters:addColor("AL_color", "Average line color", "The color of the average line", core.rgb(192,192,192));
end
-- Parameters block
local USM;
local first;
local source = nil;
-- internal indicators
local SMA = nil;
local ATR = nil;
-- Streams block
local UB = nil;
local LB = nil;
local AL = nil;
-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
function Prepare()
USM = instance.parameters.USM;
source = instance.source;
local SMA_N = instance.parameters.SMA_N;
local ATR_N = instance.parameters.ATR_N;
local PriceType = instance.parameters.SMA_source;
local name = profile:id() .. "(" .. source:name() .. ", ".. USM .. ", ".. SMA_N .. ", ".. ATR_N .. ")";
instance:name(name);
local pricestream = source.close;
SMA = core.indicators:create("MVA", pricestream, SMA_N);
ATR = core.indicators:create("ATR", source, ATR_N);
first = math.max(SMA.DATA:first(), ATR.DATA:first());
UB = instance:addStream("UB", core.Line, name, "Uppper Band", instance.parameters.UB_color, first);
LB = instance:addStream("LB", core.Line, name, "Lower Band", instance.parameters.LB_color, first);
AL = instance:addStream("AL", core.Line, name, "Average", instance.parameters.AL_color, first);
end
-- Indicator calculation routine
-- TODO: Add your code for calculation output values
function Update(period, mode)
SMA:update(mode);
ATR:update(mode);
if period >= first and source:hasData(period) then
local smaVal = SMA.DATA[period];
local atrVal = USM * ATR.DATA[period];
UB[period] = smaVal + atrVal;
LB[period] = smaVal - atrVal;
AL[period] = smaVal;
end
end
Respond to this topic if you have questions.