Page 1 of 3

Fractal-based Support/Resistance Lines

PostPosted: Wed Feb 17, 2010 5:30 pm
by Nikolay.Gekht
The simple indicator which starts a new support/resistance line every time when up or down fractal appears.

fbrs.png


Code: Select all
-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
function Init()
    indicator:name("Fractal Based Support/Resistance lines");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addColor("R_color", "Color of R", "Color of R", core.rgb(255, 192, 0));
    indicator.parameters:addColor("S_color", "Color of S", "Color of S", core.rgb(0, 192, 255));
end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- Parameters block
local first;
local source = nil;

-- Streams block
local R = nil;
local S = nil;

-- Routine
function Prepare()
    source = instance.source;
    first = source:first() + 4;

    local name = profile:id() .. "(" .. source:name() .. ")";
    instance:name(name);
    R = instance:addStream("R", core.Dot, name .. ".R", "R", instance.parameters.R_color, first);
    S = instance:addStream("S", core.Dot, name .. ".S", "S", instance.parameters.S_color, first);
end

-- Indicator calculation routine
function Update(period)
    if period >= first and source:hasData(period) then
        -- defect fractals on two periods ago
        local up, down, curr;
        up = false;
        down = false;
        curr = source.high[period - 2];
        if (curr >= source.high[period - 4] and curr >= source.high[period - 3] and
            curr >= source.high[period - 1] and curr >= source.high[period]) then
            up = true;
        end
        if up then
            R[period - 2] = curr;
            R[period - 1] = curr;
            R[period] = curr;
        else
            if R:hasData(period - 1) then
                R[period] = R[period - 1];
            end
        end
        curr = source.low[period - 2];
        if (curr <= source.low[period - 4] and curr <= source.low[period - 3] and
            curr <= source.low[period - 1] and curr <= source.low[period]) then
            down = true;
        end
        if down then
            S[period - 2] = curr;
            S[period - 1] = curr;
            S[period] = curr;
        else
            if S:hasData(period - 1) then
                S[period] = S[period - 1];
            end
        end
    end
end


Download:
FBSR.lua
(2.31 KiB) Downloaded 7260 times


FBSR with Fibonacci levels
FBSR_With_Fib.lua.png

FBSR_With_Fib.lua
(7.79 KiB) Downloaded 2295 times

Re: Fractal-based Support/Resistance Lines

PostPosted: Wed Oct 20, 2010 11:09 am
by kytkable
Hi,
I am a new one. My English is not well.
So many people download the indicator.
It shows that is very useful and helpful.Very thanks to
the worker and fxcodebase.com. I have a request, if
possible, Could anyone show me how to change the
R/S line form "....." to "____"?

Very thanks

Re: Fractal-based Support/Resistance Lines

PostPosted: Wed Nov 03, 2010 8:03 am
by thetruth
if you need lines only have to change core.Dot for core.Line in function prepare in lines
R= and S=.

Code: Select all
function Prepare()
    source = instance.source;
    first = source:first() + 4;

    local name = profile:id() .. "(" .. source:name() .. ")";
    instance:name(name);
    --core.Dot=core.Line
   R = instance:addStream("R", core.Line, name .. ".R", "R", instance.parameters.R_color, first);
    S = instance:addStream("S", core.Line, name .. ".S", "S", instance.parameters.S_color, first);
end

Re: Fractal-based Support/Resistance Lines

PostPosted: Sun Dec 19, 2010 10:46 am
by kelvincha
Good Job
That almost the best indicator ever
but I have a request
can i change the resistance and support to fiboncci retracement level of previous day
Thanks a lot

Re: Fractal-based Support/Resistance Lines

PostPosted: Sun Dec 19, 2010 10:59 am
by Apprentice
It is possible, but then it will be quite a different indicator.

Re: Fractal-based Support/Resistance Lines

PostPosted: Mon Dec 20, 2010 11:53 am
by Nikolay.Gekht
kelvincha wrote:Good Job
That almost the best indicator ever
but I have a request
can i change the resistance and support to fiboncci retracement level of previous day
Thanks a lot

Hm... As far as I see, this can be done just using PIVOT indicator. Choose "Fibonacci Retarement" in the mode, choose the levels you need and switch the historical mode "on" if you need to see historical levels.

Re: Fractal-based Support/Resistance Lines

PostPosted: Fri Feb 25, 2011 3:41 pm
by TradeKing
How do we change this indicator to lines instead of dots? I see it posted that we have to change core.dot from dot to lines but I don't even know where that would be done. Can someone please assist or change the indicator please. Thanks!

TradeKing

Re: Fractal-based Support/Resistance Lines

PostPosted: Sat Feb 26, 2011 5:51 am
by Apprentice
Something like this.
FBSR.lua
(2.71 KiB) Downloaded 2388 times

Re: Fractal-based Support/Resistance Lines

PostPosted: Wed Mar 02, 2011 2:43 pm
by TradeKing
Perfect! Thank you very much!

Re: Fractal-based Support/Resistance Lines

PostPosted: Fri Apr 08, 2011 1:13 am
by dollar
I have downloaded and transfered FBSR.Lua to my tradestation platform however it does not have this appearance as there are also vertical lines connecting to the horizonal lines which are very distracting and make the chart very busy. Is there a way for the code to be changed so that only the horizonal lines appear? The example would fit my eye very nicely for support and resistance only. THANK YOU in advance. Gene Dollar
dollar3539@yahoo.com