FXCM Forex Trading

[Upd Oct, 08] Automatic Levels Indicator (Fibonacci, Gann)

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

[Upd Oct, 08] Automatic Levels Indicator (Fibonacci, Gann)

Postby Nikolay.Gekht » Thu Apr 15, 2010 8:18 pm

The indicator draws the Fibonacci or Gann levels between the highest high and lowest low value for the specified number of the latest bars. When new price arrives and highest high or lowest low are changed, the levels are moved.

You can select either fibonacci or gann levels and how much lines to show (variants: 3, 5, 7 or 9).

AUTOLEV1.png


Update Oct, 08 2010
1) New lines set 3 lines (alt) is added. 0/50%/100% levels are used.
2) Label now are options, you can switch them off.
3) Now you can see the level and the price by moving mouse cursor over the line and wait a bit until tooltip appears.
4) Styles and line width are added.
5) Indicator code is a bit optimized.

Download the new version of indicator:
AUTOLEV2.lua
(5.93 KiB) Downloaded 2391 times


Download the indicator (older version):
AUTOLEV1.lua
(4.67 KiB) Downloaded 2092 times


Code: Select all
-- Indicator profile initialization routine
-- Defines indicator profile properties and indicator parameters
-- TODO: Add minimal and maximal value of numeric parameters and default color of the streams
function Init()
    indicator:name("Automatic Fib or Gann levels on the base of H/L values");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);

    indicator.parameters:addGroup("Parameters");
    indicator.parameters:addInteger("N", "Number of periods to find H/L", "", 50);
    indicator.parameters:addString("M", "Lines Method", "", "F");
    indicator.parameters:addStringAlternative("M", "Fibonacci", "", "F");
    indicator.parameters:addStringAlternative("M", "Gann", "", "G");
    indicator.parameters:addString("L", "Levels number", "", "3");
    indicator.parameters:addStringAlternative("L", "3 Lines", "", "3");
    indicator.parameters:addStringAlternative("L", "3 Lines (alt)", "", "3a");
    indicator.parameters:addStringAlternative("L", "5 Lines", "", "5");
    indicator.parameters:addStringAlternative("L", "7 Lines", "", "7");
    indicator.parameters:addStringAlternative("L", "9 Lines", "", "9");
    indicator.parameters:addInteger("E", "Number of bars to show lines after the latest bar char", "", 20, 1, 100);
    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("L_color", "Color of level lines", "", core.rgb(255, 255, 0));
    indicator.parameters:addInteger("L_width", "Width of level lines", "", 1, 1, 5);
    indicator.parameters:addInteger("L_style", "Style level lines", "", core.LINE_SOLID);
    indicator.parameters:setFlag("L_style", core.FLAG_LINE_STYLE);
    indicator.parameters:addColor("M_color", "Time marker color", "", core.rgb(255, 0, 0));
    indicator.parameters:addInteger("M_width", "Width of level lines", "", 1, 1, 5);
    indicator.parameters:addInteger("M_style", "Style level lines", "", core.LINE_DOT);
    indicator.parameters:setFlag("M_style", core.FLAG_LINE_STYLE);
    indicator.parameters:addBoolean("ShowLabels", "Show Line Labels", "", true);
end

-- Indicator instance initialization routine
-- Processes indicator parameters and creates output streams
-- TODO: Refine the first period calculation for each of the output streams.
-- TODO: Calculate all constants, create instances all subsequent indicators and load all required libraries
-- Parameters block
local N;
local M;
local L;
local E;
local L_color;
local L_width;
local L_style;
local M_color;
local M_width;
local M_style;
local ShowLabels;
--local T_color;

local first;
local source = nil;
local barSize;
local format;

-- Streams block
local D = nil;

-- Routine
function Prepare()
    N = instance.parameters.N;
    M = instance.parameters.M;
    L = instance.parameters.L;
    E = instance.parameters.E;
    L_color = instance.parameters.L_color;
    L_width = instance.parameters.L_width;
    L_style = instance.parameters.L_style;
    M_color = instance.parameters.M_color;
    M_width = instance.parameters.M_width;
    M_style = instance.parameters.M_style;
    ShowLabels = instance.parameters.ShowLabels;
    --T_color = instance.parameters.T_color;
    source = instance.source;
    local s, e;
    s, e = core.getcandle(source:barSize(), core.now(), 0);
    barSize = math.floor(((e - s) * 1440) + 0.5) / 1440;

    first = source:first() + N;

    local name = profile:id() .. "(" .. source:name() .. ", " .. N .. ", " .. M .. ", " .. L .. ")";
    instance:name(name);
    D = instance:addStream("D", core.Line, name, "D", instance.parameters.L_color, first, E);
    format = "%.3f=%." .. source:getPrecision() .. "f";
end

local MIN = nil;
local MAX = nil;
local P = nil;
local levels = nil;
local index = nil;

-- Indicator calculation routine
function Update(period)
    if period >= first and period == source:size() - 1 then
        local min, max, minp, maxp, p, k, v, f, t, price, d, label;
        min, max, minp, maxp = core.minmax(source, core.rangeTo(period, N));
        p = math.min(minp, maxp);
        if MIN == nil or
           MIN ~= min or MAX ~= max or P ~= p then
            MIN = min;
            MAX = max;
            d = max - min;
            P = p;

            if levels == nil then
                CalcLevels();
            end
            local idx;
            idx = index[L];

            f = source:date(p);
            t = source:date(source:size() - 1) + ((E - 1) * barSize);

            for k, v in pairs(idx) do
                price = min + d * levels[v];
                label = string.format(format, levels[v], price);
                core.host:execute("drawLine", k, f, price, t, price, L_color, L_style, L_width, label);
                if ShowLabels then
                    core.host:execute("drawLabel", k, f, price, label);
                end
            end
            core.host:execute("drawLine", 10, f, min, f, max, M_color, M_style, M_width);
        end
    end
end

function CalcLevels()
    levels = {};
    index = {};
    if M == "F" then
        levels[1] = -0.236;
        levels[2] = 0;
        levels[3] = 0.236;
        levels[4] = 0.382;
        levels[5] = 0.5;
        levels[6] = 0.618;
        levels[7] = 0.764;
        levels[8] = 1;
        levels[9] = 1.272;
        index["3"] = {4, 5, 6};
        index["3a"] = {2, 5, 8};
        index["5"] = {2, 4, 5, 6, 8};
        index["7"] = {2, 3, 4, 5, 6, 7, 8};
        index["9"] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    else
        levels[1] = 0;
        levels[2] = 0.125;
        levels[3] = 0.25;
        levels[4] = 0.375;
        levels[5] = 0.5;
        levels[6] = 0.625;
        levels[7] = 0.75;
        levels[8] = 0.875;
        levels[9] = 1;
        index["3"] = {3, 5, 7};
        index["3a"] = {1, 5, 9};
        index["5"] = {1, 3, 5, 7, 9};
        index["7"] = {1, 3, 4, 5, 6, 7, 9};
        index["9"] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    end
end
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1230
Joined: Wed Dec 16, 2009 6:39 pm
Location: Morrisville, NC

Re: Automatic Levels Indicator (Fibonacci, Gann)

Postby beni40 » Tue Apr 27, 2010 2:35 am

nice work
is it posible to get fib levels -27 and - 68


best regards
bent
beni40
 
Posts: 3
Joined: Sun Feb 28, 2010 9:44 am

Re: Automatic Levels Indicator (Fibonacci, Gann)

Postby Nikolay.Gekht » Wed May 05, 2010 4:19 pm

I'm afraid that complex settings of the indicators will dramatically reduce the easiness of usage. However, anyone can create their own version of the indicator.

It is very easy to change the indicator to support these levels as you wish. Below is a part of the indicator which is responsible for the levels. I also added a lot of comment which explain how you can change them. Just find this code in the indicator and make any changes.

Code: Select all
function CalcLevels()
    levels = {};
    index = {};
    if M == "F" then
        --- here is all possible levels for the fibonacci.
        --- The number inside the square bracket is a number of the line,
        --- the value after = is the level.
        --- You can change the value of the level to any level you wish.
        levels[1] = -0.236;
        levels[2] = 0;
        levels[3] = 0.236;
        levels[4] = 0.382;
        levels[5] = 0.5;
        levels[6] = 0.618;
        levels[7] = 0.764;
        levels[8] = 1;
        levels[9] = 1.272;
        --- here is lists of levels for 3, 5, 7 and 9 lines. You can select any other levels if you wish
        index["3"] = {4, 5, 6};
        index["5"] = {2, 4, 5, 6, 8};
        index["7"] = {2, 3, 4, 5, 6, 7, 8};
        index["9"] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    else
        --- here is all possible levels for the gann. You can change them exactly like the fibonacci levels
        levels[1] = 0;
        levels[2] = 0.125;
        levels[3] = 0.25;
        levels[4] = 0.375;
        levels[5] = 0.5;
        levels[6] = 0.625;
        levels[7] = 0.75;
        levels[8] = 0.875;
        levels[9] = 1;
        index["3"] = {3, 5, 7};
        index["5"] = {1, 3, 5, 7, 9};
        index["7"] = {1, 3, 4, 5, 6, 7, 9};
        index["9"] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
    end
end
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1230
Joined: Wed Dec 16, 2009 6:39 pm
Location: Morrisville, NC

Re: Automatic Levels Indicator (Fibonacci, Gann)

Postby cmac0351 » Tue Jul 20, 2010 10:57 pm

Hello,

Is there any way to get this to lock in to a specific time frame instead of it refreshing when new candles open? I would like to have it for 1:00 AM - 4:00 AM EST each day. Thank you.
cmac0351
 
Posts: 2
Joined: Tue Jul 20, 2010 10:52 pm

Re: Automatic Levels Indicator (Fibonacci, Gann)

Postby Nikolay.Gekht » Tue Jul 27, 2010 10:09 am

Yes, it's possible. Added to the development queue.
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1230
Joined: Wed Dec 16, 2009 6:39 pm
Location: Morrisville, NC

Re: Automatic Levels Indicator (Fibonacci, Gann)

Postby sedraude » Wed Oct 06, 2010 8:45 pm

Hi Nikolay,

Thank you for your great indi, Can you help me to make this indi has a option to display only the High-level (100%), Low (0%) and Middle (50%) as well?

Thank you in advance.
sedraude
 
Posts: 33
Joined: Thu Aug 26, 2010 3:00 am

Re: [Upd Oct, 08] Automatic Levels Indicator (Fibonacci, Gann)

Postby Nikolay.Gekht » Fri Oct 08, 2010 12:10 pm

Update Oct, 08 2010
1) New lines set 3 lines (alt) is added. 0/50%/100% levels are used.
2) Label now are options, you can switch them off.
3) Now you can see the level and the price by moving mouse cursor over the line and wait a bit until tooltip appears.
4) Styles and line width are added.
5) Indicator code is a bit optimized.

See AUTOLEV2.lua in the first post.
Nikolay.Gekht
FXCodeBase: Base Builder
 
Posts: 1230
Joined: Wed Dec 16, 2009 6:39 pm
Location: Morrisville, NC

Re: [Upd Oct, 08] Automatic Levels Indicator (Fibonacci, Gann)

Postby sedraude » Sat Oct 09, 2010 11:51 pm

wow, very fast yah...

Thank you Nikolay, great indi and very usefull!
sedraude
 
Posts: 33
Joined: Thu Aug 26, 2010 3:00 am

Re: [Upd Oct, 08] Automatic Levels Indicator (Fibonacci, Gann)

Postby arindam89 » Wed Jun 13, 2012 6:01 am

Nikolay.Gekht wrote:Update Oct, 08 2010
1) New lines set 3 lines (alt) is added. 0/50%/100% levels are used.
2) Label now are options, you can switch them off.
3) Now you can see the level and the price by moving mouse cursor over the line and wait a bit until tooltip appears.
4) Styles and line width are added.
5) Indicator code is a bit optimized.

See AUTOLEV2.lua in the first post.


hi Nikolay.Gekht
this is one of the greatest works mankind has ever made .I have a very very simple request for you ....
can you make this a strategy that goes short at 0.382 and long on 0.618 please
thanks
by arindam roy
arindam89
 
Posts: 53
Joined: Mon Dec 12, 2011 5:39 am

Re: [Upd Oct, 08] Automatic Levels Indicator (Fibonacci, Gann)

Postby arindam89 » Thu Jun 14, 2012 9:28 pm

arindam89 wrote:
Nikolay.Gekht wrote:Update Oct, 08 2010
1) New lines set 3 lines (alt) is added. 0/50%/100% levels are used.
2) Label now are options, you can switch them off.
3) Now you can see the level and the price by moving mouse cursor over the line and wait a bit until tooltip appears.
4) Styles and line width are added.
5) Indicator code is a bit optimized.

See AUTOLEV2.lua in the first post.


hi Nikolay.Gekht
this is one of the greatest works mankind has ever made .I have a very very simple request for you ....
can you make this a strategy that goes short at 0.382 and long on 0.618 please
thanks
by arindam roy


hi Nikolay.Gekht
I am eagerly waiting with great expectation that you will make my strategy
1.open short when market touches from above or below the 0.382
2.open long when market touches from above or below the 0.618
please can you code this this
thanks
by
arindam roy
india
9830538277
arindam89@yahoo.com
arindam89
 
Posts: 53
Joined: Mon Dec 12, 2011 5:39 am

Next

Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot], Yahoo [Bot] and 13 guests