Advanced Fractal

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

Advanced Fractal

Postby Apprentice » Wed Apr 21, 2010 4:37 am

Advanced  Fractal.png
Advanced Fractal


Advanced, Fractal indicator allows you to change, length of time frame that is checked. The algorithm allows only odd numbers.

Advanced Fractal.lua
Advanced Fractal.lua
(2.1 KiB) Downloaded 5792 times


Advanced Fractal Trend Overlay.lua.png

Changes in trend are registered as follows.

Up Trend.
The closing price is higher than the Up fractal.
Down Trend
The closing price is lower than the Down fractal.

Advanced Fractal Trend Overlay.lua
(4.13 KiB) Downloaded 3116 times


Strategy based on Advanced Fractal Trend Overlay can be found here.
viewtopic.php?f=31&t=8283&p=18329#p18329

MT4/MQ4 version.
posting.php?mode=post&f=38
Advanced  Fractal Label.png


Advanced fractal Labeling Tool will show you all the fractals, from 1 onwards,
and their weight.

1
3 Candles fractal
2
5 Candles fractal
3
7 Candles fractal
and so on.

Advanced Fractal Label.lua
(2.14 KiB) Downloaded 1931 times


AFBSR.png

AFBSR.lua
(2.76 KiB) Downloaded 2044 times


Adv_Fractal_support_ resistance.png

Adv_Fractal_support_ resistance .lua
After first cross, support becomes resistance and vice versa.
After second cross line is not valid any more.
(5.38 KiB) Downloaded 2036 times


Advanced_Fractal_with_Alert.lua
(9.54 KiB) Downloaded 1170 times


Dec 14, 2015: Compatibility issue Fixed. _Alert helper is not longer needed.

If you want to use updated version of this indicator,
please make sure to use TS Version 01.14.101415. or higher.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 17407
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Advanced Fractal

Postby bjmerkel » Wed Apr 21, 2010 2:52 pm

what exactly does the number of fractals (odd) mean? Thanks a lot!
bjmerkel
 
Posts: 24
Joined: Wed Apr 21, 2010 2:50 pm

Re: Advanced Fractal

Postby bjmerkel » Wed Apr 21, 2010 3:23 pm

is the length of time minutes or how does that work?
bjmerkel
 
Posts: 24
Joined: Wed Apr 21, 2010 2:50 pm

Re: Advanced Fractal

Postby Nikolay.Gekht » Wed Apr 21, 2010 4:18 pm

The fractal is usually found in terms of bars, not minutes.

The standard up fractal is the bar which has high higher than 2 previous and 2 next bars.
The standard down fractal is the bar which has low lower than 2 previous and 2 next bars.

It does not matter how long the bar is - a minute, an hour or a day.

So, as you can see the length of the "pattern" is 5 bars. Two bars before, two bars after and the tested bar itself.

Unlike the standard fractal indicator, the indicator above is able to check more than 2 bars before and after the testing bar. So, length of the pattern can be 5 (two before/two after/one tested), 7 (three before/three after/one tested), 9 (four before/four after/one tested) and so on...

So, because we have one bar to test and the same number of bars to test after and before, the length of the pattern will always an odd value (3, 5, 7, 9, 11 and so on), unlike even values (2, 4, 6, 8 and so on).
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1222
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Advanced Fractal

Postby thetruth » Thu Aug 12, 2010 4:24 pm

can you put a other time frame option??
example, if you are in a 5 min time frame, calculate the fractal in 15 min? and put this in
same graph?
thanks!! and good work!!
thetruth
 
Posts: 43
Joined: Thu Feb 25, 2010 3:39 pm

Re: Advanced Fractal

Postby Alexander.Gettinger » Sun Sep 05, 2010 10:40 pm

Other timeframe version of advanced fractal.

BF_AdvancedFractal.png


Code: Select all
function Init()
    indicator:name("Bigger timeframe advanced fractal");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addString("BS", "Time frame to calculate advanced fractal", "", "D1");
    indicator.parameters:setFlag("BS", core.FLAG_PERIODS);
    indicator.parameters:addInteger("Frame", "Number of fractals (Odd)", "Number of fractals (Odd)", 5, 5,99);

    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("UP", "Up fractal color", "Up fractal color", core.rgb(0,255,0));
    indicator.parameters:addColor("DOWN", "Down fractal color", "Down fractal color", core.rgb(255,0,0));

end

local source;                   -- the source
local bf_data = nil;          -- the high/low data
local Frame;
local BS;
local bf_length;                 -- length of the bigger frame in seconds
local dates;                    -- candle dates
local host;
local day_offset;
local week_offset;
local extent;
local up;
local down;
local Indout;
local Shift;
local TF_Coeff;

function Prepare()
    source = instance.source;
    host = core.host;

    day_offset = host:execute("getTradingDayOffset");
    week_offset = host:execute("getTradingWeekOffset");

    BS = instance.parameters.BS;
    Frame = instance.parameters.Frame;
    extent = 20;

    local s, e, s1, e1;

    s, e = core.getcandle(source:barSize(), core.now(), 0, 0);
    s1, e1 = core.getcandle(BS, core.now(), 0, 0);
    assert ((e - s) <= (e1 - s1), "The chosen time frame must be bigger than the chart time frame!");
    bf_length = math.floor((e1 - s1) * 86400 + 0.5);

    local name = profile:id() .. "(" .. source:name() .. "," .. BS .. "," .. Frame .. ")";
    instance:name(name);
    up = instance:createTextOutput ("Up", "Up", "Wingdings", 10, core.H_Center, core.V_Top, instance.parameters.UP, 0);
    down = instance:createTextOutput ("Dn", "Dn", "Wingdings", 10, core.H_Center, core.V_Bottom, instance.parameters.DOWN, 0);
    Indout = instance:addStream("out", core.Line, name .. ".Ind", "Ind", core.rgb(0,255,0), 0);
    Shift=(Frame-1)/2;
    TF_Coeff=(e1-s1)/(e-s);
end


local loading = false;
local loadingFrom, loadingTo;
local pday = nil;

-- the function which is called to calculate the period
function Update(period, mode)
    -- get date and time of the hi/lo candle in the reference data
    local bf_candle;
    bf_candle = core.getcandle(BS, source:date(period-Shift), day_offset, week_offset);

    -- if data for the specific candle are still loading
    -- then do nothing
    if loading and bf_candle >= loadingFrom and (loadingTo == 0 or bf_candle <= loadingTo) then
        return ;
    end

    -- if the period is before the source start
    -- the do nothing
    if period-Shift*(TF_Coeff+1) < source:first() then
        return ;
    end
   
    -- if data is not loaded yet at all
    -- load the data
    if bf_data == nil then
        -- there is no data at all, load initial data
        local to, t;
        local from;

        if (source:isAlive()) then
            -- if the source is subscribed for updates
            -- then subscribe the current collection as well
            to = 0;
        else
            -- else load up to the last currently available date
            t, to = core.getcandle(BS, source:date(period-Shift), day_offset, week_offset);
        end

        from = core.getcandle(BS, source:date(source:first()), day_offset, week_offset);
        Indout:setBookmark(1, period);
        -- shift so the bigger frame data is able to provide us with the stoch data at the first period
        from = math.floor(from * 86400 - (bf_length * extent) + 0.5) / 86400;
        local nontrading, nontradingend;
        nontrading, nontradingend = core.isnontrading(from, day_offset);
        if nontrading then
            -- if it is non-trading, shift for two days to skip the non-trading periods
            from = math.floor((from - 2) * 86400 - (bf_length * extent) + 0.5) / 86400;
        end
        loading = true;
        loadingFrom = from;
        loadingTo = to;
        bf_data = host:execute("getHistory", 1, source:instrument(), BS, loadingFrom, to, source:isBid());
        return ;
    end

    -- check whether the requested candle is before
    -- the reference collection start
    if (bf_candle < bf_data:date(0)) then
        Indout:setBookmark(1, period);
        if loading then
            return ;
        end
        -- shift so the bigger frame data is able to provide us with the stoch data at the first period
        from = math.floor(bf_candle * 86400 - (bf_length * extent) + 0.5) / 86400;
        local nontrading, nontradingend;
        nontrading, nontradingend = core.isnontrading(from, day_offset);
        if nontrading then
            -- if it is non-trading, shift for two days to skip the non-trading periods
            from = math.floor((from - 2) * 86400 - (bf_length * extent) + 0.5) / 86400;
        end
        loading = true;
        loadingFrom = from;
        loadingTo = bf_data:date(0);
        host:execute("extendHistory", 1, bf_data, loadingFrom, loadingTo);
        return ;
    end

    -- check whether the requested candle is after
    -- the reference collection end
    if (not(source:isAlive()) and bf_candle > bf_data:date(bf_data:size() - 1)) then
        Indout:setBookmark(1, period);
        if loading then
            return ;
        end
        loading = true;
        loadingFrom = bf_data:date(bf_data:size() - 1);
        loadingTo = bf_candle;
        host:execute("extendHistory", 1, bf_data, loadingFrom, loadingTo);
        return ;
    end

    local p;
    p = findDateFast(bf_data, bf_candle, true);
    if p == -1 then
        return ;
    end
    if p>bf_data:size()-1 then
     return ;
    end
   
    local Fl=true;
    for i=1,(Frame-1)/2,1 do
     if bf_data.high[p-Shift]<bf_data.high[p-i-Shift] or bf_data.high[p-Shift]<bf_data.high[p+i-Shift] then
      Fl=false;
     end
    end
    if Fl==true then
     up:set(period-Shift*(TF_Coeff+1), bf_data.high[p-Shift], "\226");
--     up:set(period, bf_data.high[p-Shift], "\226");
    end
    Fl=true;
    for i=1,(Frame-1)/2,1 do
     if bf_data.low[p-Shift]>bf_data.low[p-i-Shift] or bf_data.low[p-Shift]>bf_data.low[p+i-Shift] then
      Fl=false;
     end
    end
    if Fl==true then
     down:set(period-Shift*(TF_Coeff+1), bf_data.low[p-Shift], "\225");
--     down:set(period, bf_data.low[p-Shift], "\225");
    end
   
end

-- the function is called when the async operation is finished
function AsyncOperationFinished(cookie)
    local period;

    pday = nil;
    period = Indout:getBookmark(1);

    if (period < 0) then
        period = 0;
    end
    loading = false;
    instance:updateFrom(period);
end

function findDateFast(stream, date, precise)
    local datesec = nil;
    local periodsec = nil;
    local min, max, mid;

    datesec = math.floor(date * 86400 + 0.5)

    min = 0;
    max = stream:size() - 1;

    while true do
        mid = math.floor((min + max) / 2);
        periodsec = math.floor(stream:date(mid) * 86400 + 0.5);
        if datesec == periodsec then
            return mid;
        elseif datesec > periodsec then
            min = mid + 1;
        else
            max = mid - 1;
        end
        if min > max then
            if precise then
                return -1;
            else
                return min - 1;
            end
        end
    end
end
Attachments
BF_AdvancedFractal.lua
(7.57 KiB) Downloaded 2036 times
Last edited by Alexander.Gettinger on Fri Jul 01, 2011 12:02 pm, edited 2 times in total.
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 2902
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Advanced Fractal

Postby Jigit Jigit » Sat Oct 30, 2010 10:41 am

Hi,
Thank you for this excellent indicator Alexander.

Can you, please, help me with the following problems:
1) I have just installed the new Marketscope patch (the one posted here) and (as a result?) BF_Advanced_Fractal stopped working. I leave the the default settings, it does start loading but after a short while an "error" message appears in a bracket, on its label (see the pic in the attachment)

2) Why do the arrows representing fractals point in the directions opposite to the directions of the fractals they represent? That is to say, why is a fractal up represented by a down arrow, and a down fractal by an up arrow? Don't you think it's rather misleading?

I'll be much obliged for you help on those issues.
Cheers
Attachments
BF Advanced Fractal (Error).png
BF_Advanced_Fractal (Error)
Jigit Jigit
 
Posts: 54
Joined: Tue Aug 31, 2010 1:04 pm

Re: Advanced Fractal

Postby Apprentice » Sun Oct 31, 2010 6:39 am

Thank you for your report.
It is probably a bug in the indicators,
which platform previously have not detected.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 17407
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Advanced Fractal

Postby Alexander.Gettinger » Sun Oct 31, 2010 11:45 am

I cann't to repeat error.
Try to load indicator once again.
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 2902
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Advanced Fractal

Postby Jigit Jigit » Sun Oct 31, 2010 3:33 pm

Cheers Alexander,
I have tried to load it again but it didn't help.
So I uninstalled the patch and it works now.
I guess there must be something wrong with this patch then.

What about those "misleading arrows" business?
Why do they point in the opposite directions (both in the standard Marketscope indicator and in yours BF_Advanced)?
Jigit Jigit
 
Posts: 54
Joined: Tue Aug 31, 2010 1:04 pm

Next

Return to Custom Indicators

Who is online

Users browsing this forum: Google [Bot] and 12 guests