FXCM Forex Trading

Elders Safe Zone indicator

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

Elders Safe Zone indicator

Postby Alexander.Gettinger » Thu May 27, 2010 12:21 am

EldersSafeZone.png

Lua mq4/MT4 version
viewtopic.php?f=38&t=64055

Code: Select all
function Init()
    indicator:name("Elders Safe Zone indicator");
    indicator:description("");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);
   
    indicator.parameters:addInteger("LookBack", "LookBack", "No description", 10);
    indicator.parameters:addInteger("StopFactor", "StopFactor", "No description", 3);
    indicator.parameters:addInteger("EMALength", "EMALength", "No description", 13);


    indicator.parameters:addColor("Line_color", "Color of line", "Color of line", core.rgb(0, 255, 255));
end

local LookBack;
local StopFactor;
local EMALength;

local first;
local source = nil;
local buffLine=nil;
local EMA;

function Prepare()
    source = instance.source;
    LookBack = instance.parameters.LookBack;
    StopFactor = instance.parameters.StopFactor;
    EMALength = instance.parameters.EMALength;
    EMA = core.indicators:create("EMA", source.close, EMALength);
    first = EMA.DATA:first();
    local name = profile:id() .. "(" .. source:name() .. ", " .. LookBack .. ", " .. StopFactor .. ", " .. EMALength .. ")";
    instance:name(name);
    buffLine = instance:addStream("Line", core.Line, name .. ".Line", "Line", instance.parameters.Line_color, first);
end

function Update(period, mode)
    if (period>first+LookBack+3) then
     EMA:update(mode);
     local SafeStop=0.;
     local EMA0=EMA.DATA[period];
     local EMA1=EMA.DATA[period-1];
     local EMA2=EMA.DATA[period-2];
     local PreSafeStop=buffLine[period-1];
     local Pen=0.;
     local Counter=0;
     if EMA0>EMA1 then
      for value1=0,LookBack,1 do
       if source.low[period-value1]<source.low[period-value1-1] then
        Pen=source.low[period-value1-1]-source.low[period-value1]+Pen;
        Counter=Counter+1;
       end
      end
      if Counter>0 then
       SafeStop=source.close[period]-(StopFactor*Pen/Counter);
      else
       SafeStop=source.close[period]-(StopFactor*Pen);
      end
      if SafeStop<PreSafeStop and EMA1>EMA2 then
       SafeStop=PreSafeStop;
      end
     elseif EMA0<EMA1 then
      for value1=0,LookBack,1 do
       if source.high[period-value1]>source.high[period-value1-1] then
        Pen=source.high[period-value1]-source.high[period-value1-1]+Pen;
        Counter=Counter+1;
       end
      end
      if Counter>0 then
       SafeStop=source.close[period]+(StopFactor*Pen/Counter);
      else
       SafeStop=source.close[period]+(StopFactor*Pen);
      end
      if SafeStop>PreSafeStop and EMA1<EMA2 then
       SafeStop=PreSafeStop;
      end
     end
     PreSafeStop=SafeStop;
     buffLine[period]=SafeStop;
    end
end



Elders_Safe_Zone.lua
(2.63 KiB) Downloaded 665 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 2460
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Elders Safe Zone indicator

Postby Apprentice » Wed Jan 11, 2017 5:54 am

Indicator was revised and updated.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 14245
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Custom Indicators

Who is online

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