Simple Moving Avergae ( SMA ) Vertical Shift

If you need an Indicator or Signal developed or translated from other language, please post all Indicator development REQUESTS to this section here.

Moderator: admin

Simple Moving Avergae ( SMA ) Vertical Shift

Postby tradingkevin » Thu Feb 04, 2010 6:30 am

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
tradingkevin
FXCodeBase: Confirmed User
 
Posts: 9
Joined: Wed Feb 03, 2010 2:22 pm

Re: Simple Moving Avergae ( SMA ) Vertical Shift

Postby Nikolay.Gekht » Thu Feb 04, 2010 9:36 am

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 1137 times
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Simple Moving Avergae ( SMA ) Vertical Shift

Postby tradingkevin » Thu Feb 04, 2010 7:00 pm

super Nikolay ! quick and to the point ! I love it. THanks for the quick response and help.

Sincerely
Kevin
tradingkevin
FXCodeBase: Confirmed User
 
Posts: 9
Joined: Wed Feb 03, 2010 2:22 pm

Re: Simple Moving Avergae ( SMA ) Vertical Shift

Postby Nikolay.Gekht » Thu Feb 04, 2010 11:14 pm

You are welcome! Thank you for using our products!
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC


Return to Indicator and Signal Requests

Who is online

Users browsing this forum: No registered users and 14 guests