Page 1 of 1

Simple Moving Avergae ( SMA ) Vertical Shift

PostPosted: Thu Feb 04, 2010 6:30 am
by tradingkevin
Hi ,
I am looking for the indicator code that would be able to shift a SMA verticaly i.e. up and down ?
I was wondering if somebody had it in the forum ?

Most of the software offer a horizontal shift left and right but not many have the vertical UP and Down shift factor. I have been playing with in Forex Tester software and If found it quiet nice tool to have.

Thanks

Kevin

Re: Simple Moving Avergae ( SMA ) Vertical Shift

PostPosted: Thu Feb 04, 2010 9:36 am
by Nikolay.Gekht
This is the very simple modification of the MVA

mvas.PNG


Code: Select all
-- initializes the indicator
function Init()
    indicator:name("Simple Moving Average With Shift");
    indicator:description("");
    indicator:requiredSource(core.Tick);
    indicator:type(core.Indicator);

    indicator.parameters:addInteger("N", "Number Of Periods", "", 7, 2, 10000);
    indicator.parameters:addDouble("S", "Shift", "", 0, -100, 100);
    indicator.parameters:addColor("clr", "Color", "", core.rgb(255, 255, 0));
end

local first = 0;
local n = 0;
local s = 0;
local source = nil;
local out = nil;

-- initializes the instance of the indicator
function Prepare()
    source = instance.source;
    n = instance.parameters.N;
    s = instance.parameters.S;
    first = n + source:first() - 1;
    local name = profile:id() .. "(" .. source:name() .. "," .. n .. "," .. s .. ")";
    instance:name(name);
    out = instance:addStream("MVA", core.Line, name, "MVA", instance.parameters.clr,  first)
end

-- calculate the value
function Update(period)
    if (period >= first) then
        out[period] = core.avg(source, core.rangeTo(period, n)) + s;
    end
end


Download
mvas.lua
(1.09 KiB) Downloaded 1146 times

Re: Simple Moving Avergae ( SMA ) Vertical Shift

PostPosted: Thu Feb 04, 2010 7:00 pm
by tradingkevin
super Nikolay ! quick and to the point ! I love it. THanks for the quick response and help.

Sincerely
Kevin

Re: Simple Moving Avergae ( SMA ) Vertical Shift

PostPosted: Thu Feb 04, 2010 11:14 pm
by Nikolay.Gekht
You are welcome! Thank you for using our products!