Non-Lag Moving Average

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

Non-Lag Moving Average

Postby Alexander.Gettinger » Mon Sep 20, 2010 10:41 pm

viewtopic.php?f=27&t=2219

NonLagMA.png


NonLagMA.lua
(3.11 KiB) Downloaded 1895 times

SSNonLagMA.lua
Single Stream Version
(3.77 KiB) Downloaded 1084 times


NonLagMA Overlay.lua
(4.64 KiB) Downloaded 379 times


The indicator was revised and updated
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Non-Lag Moving Average

Postby colddog » Mon Sep 20, 2010 11:26 pm

Thanks so much for your help!
colddog
 
Posts: 3
Joined: Sun Sep 19, 2010 6:48 am

Re: Non-Lag Moving Average

Postby colddog » Wed Sep 22, 2010 10:33 am

Hi,

just wondering if its possible to include an option which changes the width of the line being drawn? so that i can make it thicker? :?: :D
colddog
 
Posts: 3
Joined: Sun Sep 19, 2010 6:48 am

Re: Non-Lag Moving Average

Postby Apprentice » Wed Sep 22, 2010 11:55 am

Added to development cue.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 23210
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Non-Lag Moving Average

Postby Alexander.Gettinger » Mon Oct 04, 2010 9:55 pm

Update Non-Lag Moving Average.
Added line styles.

Code: Select all
function Init()
    indicator:name("NonLagMA indicator");
    indicator:description("NonLagMA indicator");
    indicator:requiredSource(core.Tick);
    indicator:type(core.Indicator);
   
    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addInteger("Length", "Length", "Length", 9);
    indicator.parameters:addInteger("Filter", "Filter", "Filter", 0);
    indicator.parameters:addInteger("ColorBarBack", "ColorBarBack", "ColorBarBack", 2);
    indicator.parameters:addDouble("Deviation", "Deviation", "Deviation", 0);

    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("clrUP", "UP color", "UP color", core.rgb(0, 0, 255));
    indicator.parameters:addColor("clrDN", "DN color", "DN color", core.rgb(255, 0, 0));
   
    indicator.parameters:addInteger("widthLinReg", "Line width", "Line width", 1, 1, 5);
    indicator.parameters:addInteger("styleLinReg", "Line style", "Line style", core.LINE_SOLID);
    indicator.parameters:setFlag("styleLinReg", core.FLAG_LINE_STYLE);
end

local first;
local source = nil;
local Length;
local Filter;
local ColorBarBack;
local Deviation;
local buffUP=nil;
local buffDN=nil;
local trend;
local buff;
local Coeff;
local Phase;
local Len;

function Prepare()
    source = instance.source;
    Length=instance.parameters.Length;
    Filter=instance.parameters.Filter;
    ColorBarBack=instance.parameters.ColorBarBack;
    Deviation=instance.parameters.Deviation;
    trend = instance:addInternalStream(0, 0);
    buff = instance:addInternalStream(0, 0);
    first = source:first()+2;
    local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Length .. ", " .. instance.parameters.Filter .. ", " .. instance.parameters.ColorBarBack .. ", " .. instance.parameters.Deviation .. ")";
    instance:name(name);
    buffUp = instance:addStream("buffUp", core.Line, name .. ".Up", "Up", instance.parameters.clrUP, first);
    buffDn = instance:addStream("buffDn", core.Line, name .. ".Dn", "Dn", instance.parameters.clrDN, first);
    buffUp:setWidth(instance.parameters.widthLinReg);
    buffUp:setStyle(instance.parameters.styleLinReg);
    buffDn:setWidth(instance.parameters.widthLinReg);
    buffDn:setStyle(instance.parameters.styleLinReg);
    Coeff=3.*math.pi;
    Phase=Length-1;
    Len=Length*4.+Phase;
end

function Update(period, mode)
    if (period>first+Len+2) then
     local Weight=0;
     local Sum=0;
     local t=0;
     for i=0,Len-1,1 do
      local g=1./(Coeff*t+1.);
      if t<=0.5 then
       g=1.;
      end
      local beta=math.cos(math.pi*t);
      local alpha=g*beta;
      Sum=Sum+alpha*source[period-i];
      Weight=Weight+alpha;
      if t<1. then
       t=t+1./(Phase-1.);
      elseif t<Len-1. then
       t=t+7./(4.*Length-1.);
      end
     end
     if Weight>0. then
      buff[period]=(1.+Deviation/100.)*Sum/Weight;
     end
     if Filter>0. then
      if math.abs(buff[period]-buff[period-1])<Filter*source:pipSize() then
       buff[period]=buff[period-1];
      end
     end
     trend[period]=trend[period-1];
     if buff[period]-buff[period-1]>Filter*source:pipSize() then
      trend[period]=1;
     end
     if buff[period-1]-buff[period]>Filter*source:pipSize() then
      trend[period]=-1;
     end
     if trend[period]>0 then
      buffUp[period]=buff[period];
      if trend[period-ColorBarBack]<0 then
       buffUp[period-ColorBarBack]=buff[period-ColorBarBack];
      end
     end
     if trend[period]<0 then
      buffDn[period]=buff[period];
      if trend[period-ColorBarBack]>0 then
       buffDn[period-ColorBarBack]=buff[period-ColorBarBack];
      end
     end

    end
end
Attachments
NonLagMA.lua
(3.67 KiB) Downloaded 1036 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Re: Non-Lag Moving Average

Postby Apprentice » Fri Oct 22, 2010 12:30 pm

NonLagMA.lua
Version RC1
(4.34 KiB) Downloaded 1278 times

Single Line Option Added, Needed for compatibility with some indicators, signals.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 23210
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Non-Lag Moving Average

Postby Jigit Jigit » Fri Oct 29, 2010 3:28 pm

Can someone, please, test this indicator thoroughly?
It seems to struggle...

It is very slow to load, that is to say, it doesn't spread itself over the price action. One has to drag the chart back manually to actually make it draw itself (especially with a period greater than 100).

Also, is there a limit as to how many Non-lag MAs can be planted on one chart?
Once I load 10 of them they seem to kill Marketscope, it literally freezes.

I have already posted a request for a multiple non-lag indicator.
Do you think multiple non-lag MAs would work better if made into one indicator? Would it be easier for Marketscope to load?
Jigit Jigit
 
Posts: 54
Joined: Tue Aug 31, 2010 1:04 pm

Re: Non-Lag Moving Average

Postby thejesters1 » Mon Nov 01, 2010 3:02 am

a signal for this would be great. thanks
thejesters1
 
Posts: 17
Joined: Thu Jun 17, 2010 12:49 am

Re: Non-Lag Moving Average

Postby Apprentice » Mon Nov 01, 2010 4:00 am

Added to developmental cue.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 23210
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Non-Lag Moving Average

Postby Alexander.Gettinger » Tue Nov 09, 2010 2:15 am

Indicator updated. Added non-color mode.

Code: Select all
function Init()
    indicator:name("NonLagMA indicator");
    indicator:description("NonLagMA indicator");
    indicator:requiredSource(core.Tick);
    indicator:type(core.Indicator);
   
    indicator.parameters:addGroup("Calculation");
    indicator.parameters:addInteger("Length", "Length", "Length", 9);
    indicator.parameters:addInteger("Filter", "Filter", "Filter", 0);
    indicator.parameters:addInteger("ColorBarBack", "ColorBarBack", "ColorBarBack", 2);
    indicator.parameters:addDouble("Deviation", "Deviation", "Deviation", 0);
    indicator.parameters:addBoolean("ColorMode", "ColorMode", "ColorMode", true);

    indicator.parameters:addGroup("Style");
    indicator.parameters:addColor("MainClr", "Main color", "Main color", core.rgb(0, 255, 0));
    indicator.parameters:addColor("clrUP", "UP color", "UP color", core.rgb(0, 0, 255));
    indicator.parameters:addColor("clrDN", "DN color", "DN color", core.rgb(255, 0, 0));
   
    indicator.parameters:addInteger("widthLinReg", "Line width", "Line width", 1, 1, 5);
    indicator.parameters:addInteger("styleLinReg", "Line style", "Line style", core.LINE_SOLID);
    indicator.parameters:setFlag("styleLinReg", core.FLAG_LINE_STYLE);
end

local first;
local source = nil;
local Length;
local Filter;
local ColorBarBack;
local Deviation;
local buffUP=nil;
local buffDN=nil;
local trend;
local buff;
local Coeff;
local Phase;
local Len;
local ColorMode;
local MainBuff=nil;

function Prepare()
    source = instance.source;
    Length=instance.parameters.Length;
    Filter=instance.parameters.Filter;
    ColorMode=instance.parameters.ColorMode;
    ColorBarBack=instance.parameters.ColorBarBack;
    Deviation=instance.parameters.Deviation;
    trend = instance:addInternalStream(0, 0);
    buff = instance:addInternalStream(0, 0);
    first = source:first()+2;
    local name = profile:id() .. "(" .. source:name() .. ", " .. instance.parameters.Length .. ", " .. instance.parameters.Filter .. ", " .. instance.parameters.ColorBarBack .. ", " .. instance.parameters.Deviation .. ")";
    instance:name(name);
    MainBuff = instance:addStream("MainBuff", core.Line, name .. ".MA", "MA", instance.parameters.MainClr, first);
    buffUp = instance:addStream("buffUp", core.Line, name .. ".Up", "Up", instance.parameters.clrUP, first);
    buffDn = instance:addStream("buffDn", core.Line, name .. ".Dn", "Dn", instance.parameters.clrDN, first);
    MainBuff:setWidth(instance.parameters.widthLinReg);
    MainBuff:setStyle(instance.parameters.styleLinReg);
    buffUp:setWidth(instance.parameters.widthLinReg);
    buffUp:setStyle(instance.parameters.styleLinReg);
    buffDn:setWidth(instance.parameters.widthLinReg);
    buffDn:setStyle(instance.parameters.styleLinReg);
    Coeff=3.*math.pi;
    Phase=Length-1;
    Len=Length*4.+Phase;
end

function Update(period, mode)
    if (period>first+Len+2) then
     local Weight=0;
     local Sum=0;
     local t=0;
     for i=0,Len-1,1 do
      local g=1./(Coeff*t+1.);
      if t<=0.5 then
       g=1.;
      end
      local beta=math.cos(math.pi*t);
      local alpha=g*beta;
      Sum=Sum+alpha*source[period-i];
      Weight=Weight+alpha;
      if t<1. then
       t=t+1./(Phase-1.);
      elseif t<Len-1. then
       t=t+7./(4.*Length-1.);
      end
     end
     if Weight>0. then
      buff[period]=(1.+Deviation/100.)*Sum/Weight;
     end
     if Filter>0. then
      if math.abs(buff[period]-buff[period-1])<Filter*source:pipSize() then
       buff[period]=buff[period-1];
      end
     end
     trend[period]=trend[period-1];
     if buff[period]-buff[period-1]>Filter*source:pipSize() then
      trend[period]=1;
     end
     if buff[period-1]-buff[period]>Filter*source:pipSize() then
      trend[period]=-1;
     end
     if ColorMode==true then
      if trend[period]>0 then
       buffUp[period]=buff[period];
       if trend[period-ColorBarBack]<0 then
        buffUp[period-ColorBarBack]=buff[period-ColorBarBack];
       end
      end
      if trend[period]<0 then
       buffDn[period]=buff[period];
       if trend[period-ColorBarBack]>0 then
        buffDn[period-ColorBarBack]=buff[period-ColorBarBack];
       end
      end
     else
      if trend[period]>0 then
       MainBuff[period]=buff[period];
       if trend[period-ColorBarBack]<0 then
        MainBuff[period-ColorBarBack]=buff[period-ColorBarBack];
       end
      end
      if trend[period]<0 then
       MainBuff[period]=buff[period];
       if trend[period-ColorBarBack]>0 then
        MainBuff[period-ColorBarBack]=buff[period-ColorBarBack];
       end
      end
     
     end

    end
end
Attachments
NonLagMA2.lua
(4.62 KiB) Downloaded 1842 times
Alexander.Gettinger
FXCodeBase: Confirmed User
 
Posts: 3785
Joined: Wed Mar 31, 2010 9:40 pm
Location: Russia, Omsk

Next

Return to Custom Indicators

Who is online

Users browsing this forum: Google [Bot], wuhuilin11 and 14 guests