i built an easy indicator code without signal filters...
- Code: Select all
-- Bollinger Bänder und SMA 10
-- Visualisieren der Ausbrüche
function Init()
indicator:name("BollingerBands");
indicator:description("Bollinger");
indicator:requiredSource(core.Bar);
indicator:type(core.Indicator);
indicator:setTag("group", "Bollinger & SMA");
indicator.parameters:addGroup("Calculation BB & SMA");
indicator.parameters:addInteger("NBB", "Periods BB", "Periods BB", 20, 1, 10000);
indicator.parameters:addInteger("NSMA", "Periods SMA", "Periods SMA", 10, 1, 10000);
indicator.parameters:addDouble("Dev", "Dev", "Dev", 2.0, 0.0001, 1000.0);
indicator.parameters:addGroup("Style");
indicator.parameters:addColor("BB", "Farbe BB", "BB", core.rgb(255, 0, 0));
indicator.parameters:addColor("SMA", "Farbe SMA", "SMA", core.rgb(0, 0,255));
indicator.parameters:addGroup("Arrows");
indicator.parameters:addColor("DN_Clr", "DN Color", "DN Color", core.rgb(255, 0, 0));
indicator.parameters:addColor("UP_Clr", "UP Color", "UP Color", core.rgb(0, 255, 0));
indicator.parameters:addInteger("ArrowSize", "Arrow size", "Arrow size", 15);
end
-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- Parameters block
local NBB;
local NSMA;
local D;
local firstPeriod;
local source = nil;
-- Streams block
local TL = nil;
local BL = nil;
local AL = nil;
local SMA10 = nil;
local TL1 = nil;
local BL1 = nil;
local AL1 = nil;
local SMA101 = nil;
local Sum = nil;
--Arrows
local up=nil;
local down=nil;
-- Routine
function Prepare()
NBB = instance.parameters.NBB;
NSMA = instance.parameters.NSMA;
Pip = instance.parameters.Pip;
D = instance.parameters.Dev;
source = instance.source;
firstPeriod = source:first() + NBB - 1;
local name = profile:id() .. "(" .. source:name() .. ", " .. NBB .. ", " .. D .. ")";
instance:name(name);
TL = instance:addStream("TL", core.Line, name .. ".TL", "TL", instance.parameters.BB, firstPeriod)
BL = instance:addStream("BL", core.Line, name .. ".BL", "BL", instance.parameters.BB, firstPeriod)
AL = instance:addStream("AL", core.Line, name .. ".AL", "AL", instance.parameters.SMA, firstPeriod)
SMA10 = instance:addStream("MVA", core.Line, name, "MVA", instance.parameters.SMA, firstPeriod)
--Arrows
up = instance:createTextOutput ("Up", "Up", "Wingdings", instance.parameters.ArrowSize, core.H_Center, core.V_Bottom, instance.parameters.UP_Clr, 0);
down = instance:createTextOutput ("Dn", "Dn", "Wingdings", instance.parameters.ArrowSize, core.H_Center, core.V_Top, instance.parameters.DN_Clr, 0);
end
-- Indicator calculation routine
function Update(period)
if period >= firstPeriod then
local ml = mathex.avg(source.close, period - NBB + 1, period);
local d = mathex.stdev(source.close, period - NBB + 1, period);
local Dd = D * d;
TL[period] = ml + Dd;
BL[period] = ml - Dd;
AL[period] = ml;
SMA10[period] = mathex.avg(source.close, period - NSMA + 1, period);
--Alle Ausbrüche
if source.high[period] > TL[period] then
down:set(period, source.high[period], "\226");
end
if source.low[period] < BL[period] then
up:set(period, source.low[period], "\225");
end
end
end
... and now i want this indicator to trade by the following conditions.
When the price crosses over the bollinger high band Open Trade Short with a Stoploss of 20 Pips and a Target to the SMA20.
When the price crosses under the bollinger low band Open Trade long with SL 20 and Target SMA20.
I tried a few hours by myselt but it didn't work out.
Can anyone help me?