Strategy out of indicator code

All posts which do not fit into any other sections of the forum.

Moderator: admin

Strategy out of indicator code

Postby FamWue » Wed Oct 03, 2012 3:48 am

Hi,

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?
FamWue
 
Posts: 25
Joined: Mon Oct 01, 2012 2:38 am

Re: Strategy out of indicator code

Postby Apprentice » Wed Oct 03, 2012 4:04 am

BollingerBands.lua
(3.41 KiB) Downloaded 832 times

Your request has been added to the development list.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Strategy out of indicator code

Postby Alexander.Gettinger » Tue Feb 12, 2019 9:32 pm

Please try this strategy:
BollingerBands_Str.lua
(13.1 KiB) Downloaded 517 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Strategy out of indicator code

Postby Caufield » Wed May 01, 2019 7:05 am

Is that a newly developed strategy, Alexander?
We all need payday loans from time to time.
Caufield
 
Posts: 1
Joined: Tue Apr 30, 2019 5:35 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 6 guests