Volume Indicator: Volume Adjusted Moving Average (VAMA)

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

Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby Apprentice » Wed Oct 06, 2010 1:45 am

VAMA.png

Volume Adjusted Moving Average ( VAMA)
It is calculated by dividing the value of transactions, by the total volume for the period of interest.
VAMA.lua
(3.26 KiB) Downloaded 2863 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36435
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby gg_frx » Sat Oct 09, 2010 9:15 am

in my opinion this is not real VWAP indicator.
here some links
http://www.linnsoft.com/tour/techind/vwap.htm
http://stockcharts.com/help/doku.php?id ... ghted_aver
http://ensign.editme.com/vwap

VWAP usually works from left (beginning of the day ) to right ( now or end of the day) than restarts for next session.
actual VAMA indicator works from right to left, adding data like a classical moving average for a given number of bars, so at every new bar the calculated trading horizon is not from the beginning of the day but from now to x bars in the past on the current timeframe.

actual coded formula is the same as that on the links ?
or the VAMA use a different formula ?

anyway i think that is better to create a new real VWAP indicator with:
- possibility to use close price or typical price (close is the standard)
- possibility to define a start and end time ( begin of the trading session and end of the day are standard in stock markets but in forex market there are more sessions an is more flexible)
- possibility to use upper and lower bands with standard deviation, or a given value in pip or other ... (please look at the given linnsoft link)

ty ;)
gg_frx
FXCodeBase: Confirmed User
 
Posts: 38
Joined: Thu Dec 17, 2009 8:42 am

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby Apprentice » Sat Oct 09, 2010 9:33 am

Thanks for the warning

The three formulas, each slightly different.
I am satisfied with the current version, the formula corresponds to your example.

I can write the indicator, indicators, which will have the opportunity for adding bands, and some of your other suggestions, Create in sesion version or option .

The only thing that can change the current indicator is a choice between the types of streams.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36435
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby Apprentice » Sun Oct 10, 2010 3:08 pm

VWAP.png

Volume Weighted Average Price (VWAP)
Unlike VAMA, VWAP handled only Intraday timeframe.
Calculate the VWAP indicator from the beginning of the trading day.
VWAP.lua
(7.71 KiB) Downloaded 3254 times
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36435
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby gg_frx » Mon Oct 11, 2010 3:26 pm

Apprentice wrote:
VWAP.png

Volume Weighted Average Price (VWAP)
Unlike VAMA, VWAP handled only Inraday timeframe.
Calculate the VWAP indicator from the beginning of the trading day.
VWAP.lua


thank for the fast coding ;)
i tested the indicator but i found that it restarts at 4.00 GMT (7.00 on your chart example)
this is not the beginning of trading day in forex market ... in theory the start is at 22 GMT, but can be most useful if you add an option where we can set a start time and an end time so we can trace, for instance, only asian session or only the european session or only 5 hours from a particular chart pattern.
gg_frx
FXCodeBase: Confirmed User
 
Posts: 38
Joined: Thu Dec 17, 2009 8:42 am

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby patick » Tue Oct 12, 2010 4:12 pm

Vwap v2.jpg

If anyone is interested, I added 1 more std dev line to the code. You can see from the picture it is very helpful to have that 3rd deviation.

gg-frx - You actually don't what the indy to start at the beginning of the trade day. It needs a certain amount of prior volume for its calculations. I think Apprentice picked a good time. Try it out and see.
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("Volume Weighted Average Price (VWAP)");
    indicator:description("Volume Weighted Average Price (VWAP)");
    indicator:requiredSource(core.Bar);
    indicator:type(core.Indicator);
   indicator:setTag("group", "Volume Indicators");
   
   indicator.parameters:addGroup("Band Parameters");
   indicator.parameters:addBoolean("BAND", "Show Bands", "" , true);   
   indicator.parameters:addDouble("ONE", "First Multiplier", "" , 1);
   indicator.parameters:addDouble("TWO", "Second Multiplier", "" , 2);
   indicator.parameters:addDouble("THREE", "Third Multiplier", "" , 3);
   indicator.parameters:addGroup("Price Type");
   indicator.parameters:addString("Type", "CLOSE", "", "C");
    indicator.parameters:addStringAlternative("Type", "OPEN", "", "O");
    indicator.parameters:addStringAlternative("Type", "HIGH", "", "H");
    indicator.parameters:addStringAlternative("Type", "LOW", "", "L");
    indicator.parameters:addStringAlternative("Type","CLOSE", "", "C");
    indicator.parameters:addStringAlternative("Type", "MEDIAN", "", "M");
    indicator.parameters:addStringAlternative("Type", "TYPICAL", "", "T");
    indicator.parameters:addStringAlternative("Type", "WEIGHTED", "", "W");
   
   
    indicator.parameters:addInteger("width","Width", "", 1, 1, 5);
    indicator.parameters:addInteger("style", "Style", "", core.LINE_SOLID);
    indicator.parameters:setFlag("style", core.FLAG_LINE_STYLE);
    indicator.parameters:addColor("VAMA_color", "Color of VWAP Line", "", core.rgb(0, 0, 255));
   
   indicator.parameters:addGroup("First band Line Style");
   indicator.parameters:addInteger("widthONE","Width", "", 1, 1, 5);
    indicator.parameters:addInteger("styleONE", "Style", "", core.LINE_SOLID);
    indicator.parameters:setFlag("styleONE", core.FLAG_LINE_STYLE);
    indicator.parameters:addColor("ONE_color", "Band Color", "", core.rgb(255, 0, 0));
   
   indicator.parameters:addGroup("Second band Line Style");
   indicator.parameters:addInteger("widthTWO","Width", "", 1, 1, 5);
    indicator.parameters:addInteger("styleTWO", "Style", "", core.LINE_SOLID);
    indicator.parameters:setFlag("styleTWO", core.FLAG_LINE_STYLE);
    indicator.parameters:addColor("TWO_color", "Band Color", "", core.rgb(0, 255, 0));
   
   indicator.parameters:addGroup("Third band Line Style");
   indicator.parameters:addInteger("widthTHREE","Width", "", 1, 1, 5);
    indicator.parameters:addInteger("styleTHREE", "Style", "", core.LINE_SOLID);
    indicator.parameters:setFlag("styleTHREE", core.FLAG_LINE_STYLE);
    indicator.parameters:addColor("THREE_color", "Band Color", "", core.rgb(255, 0, 0));
   
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

local first;
local source = nil;
local PriceTimesVolume;
local VAMA = nil;
local host;
local offset;
local weekoffset;
local s=nil
local e=nil;
local START=nil;
local Type;
local p;
local RAW;
local DEV;
local UP={};
local DOWN={};
local BAND;
local ONE;
local TWO;
local THREE;

function Prepare()
   ONE=instance.parameters.ONE;
   TWO=instance.parameters.TWO;
    THREE=instance.parameters.THREE
   Type=instance.parameters.Type;
   BAND=instance.parameters.BAND;
    source = instance.source;
    first = source:first();
   
    if Type == "O" then
        p = source.open;
    elseif Type == "H" then
        p = source.high;
    elseif Type == "L" then
        p = source.low;
    elseif Type == "M" then
        p = source.median;
    elseif Type == "T" then
        p = source.typical;
    elseif Type == "W" then
        p = source.weighted;
    else
        p = source.close;
    end
   
   host = core.host;
   offset = host:execute("getTradingDayOffset");
    weekoffset = host:execute("getTradingWeekOffset");
   
   PriceTimesVolume = instance:addInternalStream(first,0);   

    local name = profile:id() .. "(" .. source:name() .. ")";
    instance:name(name);
    VAMA = instance:addStream("VAMA", core.Line, name, "VAMA", instance.parameters.VAMA_color, first);
   VAMA:setWidth(instance.parameters.width);
    VAMA:setStyle(instance.parameters.style);
   
   if BAND then
   
   RAW=instance:addInternalStream (first, 0)
   UP[1] = instance:addStream("UP"..1, core.Line, name, "UP 1", instance.parameters.ONE_color, first);
   UP[1]:setWidth(instance.parameters.widthONE);
    UP[1]:setStyle(instance.parameters.styleONE);
   DOWN[1] = instance:addStream("DOWN"..1, core.Line, name, "DOWN 1", instance.parameters.ONE_color, first);
   DOWN[1]:setWidth(instance.parameters.widthONE);
    DOWN[1]:setStyle(instance.parameters.styleONE);
   UP[2] = instance:addStream("UP"..2, core.Line, name, "UP 2", instance.parameters.TWO_color, first);
   UP[2]:setWidth(instance.parameters.widthTWO);
    UP[2]:setStyle(instance.parameters.styleTWO);
   DOWN[2] = instance:addStream("DOWN"..2, core.Line, name, "DOWN 2", instance.parameters.TWO_color, first);
   DOWN[2]:setWidth(instance.parameters.widthTWO);
    DOWN[2]:setStyle(instance.parameters.styleTWO);
   UP[3] = instance:addStream("UP"..3, core.Line, name, "UP 3", instance.parameters.THREE_color, first);
   UP[3]:setWidth(instance.parameters.widthTHREE);
    UP[3]:setStyle(instance.parameters.styleTHREE);
   DOWN[3] = instance:addStream("DOWN"..3, core.Line, name, "DOWN 3", instance.parameters.THREE_color, first);
   DOWN[3]:setWidth(instance.parameters.widthTHREE);
    DOWN[3]:setStyle(instance.parameters.styleTHREE);
   end

end

-- Indicator calculation routine
-- TODO: Add your code for calculation output values
function Update(period)
    if period >= first and source:hasData(period) then
   
             if core.getcandle("D1", source:date(period),0, 0) ~= s then
             s, e = core.getcandle("D1", source:date(period),0, 0);
             START = findDateFast(source, s, false);   
             end
   
        PriceTimesVolume[period]=p[period] *source.volume[period];
      
       if START ~= -1 then      
            VAMA[period] = core.sum(PriceTimesVolume,core.range(START,period))/core.sum(source.volume,core.range(START, period));   
            
            if BAND then
            RAW[period] = p[period]-VAMA[period];
            DEV=core.stdev (RAW, core.range(START, period));
            UP[1][period]=  VAMA[period] + DEV*ONE;
            DOWN[1][period]=VAMA[period] - DEV*ONE;
            UP[2][period]=  VAMA[period] + DEV*TWO;
            DOWN[2][period]=VAMA[period] - DEV*TWO;
            UP[3][period]=  VAMA[period] + DEV*THREE;
            DOWN[3][period]=VAMA[period] - DEV*THREE;
            end
      end
      
    end
   
end

function findDateFast(stream, date, precise)
    local datesec = nil;
    local periodsec = nil;
    local min, max, mid;

    datesec = math.floor(date * 86400 + 0.5)

    min = 0;
    max = stream:size() - 1;

    while true do
        mid = math.floor((min + max) / 2);
        periodsec = math.floor(stream:date(mid) * 86400 + 0.5);
        if datesec == periodsec then
            return mid;
        elseif datesec > periodsec then
            min = mid + 1;
        else
            max = mid - 1;
        end
        if min > max then
            if precise then
                return -1;
            else
                return min - 1;
            end
        end
    end
end

VWAP.lua
(7.71 KiB) Downloaded 2320 times
patick
 
Posts: 36
Joined: Tue Mar 30, 2010 2:11 pm

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby gg_frx » Wed Jan 19, 2011 4:52 am

i resumed this old thread to ask if is possible to insert start and end time in vwap indicator and add the 3rd deviation too like patick

ty ;)
gg_frx
FXCodeBase: Confirmed User
 
Posts: 38
Joined: Thu Dec 17, 2009 8:42 am

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby bomberone3 » Tue Oct 25, 2011 3:41 pm

Is it possible add the POC value?
bomberone3
 
Posts: 21
Joined: Wed Oct 12, 2011 3:08 am

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby Apprentice » Tue Oct 25, 2011 4:53 pm

I did not get the impression that this indicator has a POC, value.
Can you elaborate.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36435
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Volume Indicator: Volume Adjusted Moving Average (VAMA)

Postby bomberone3 » Wed Oct 26, 2011 2:12 am

I read book about market profile, so I ask if is it possible add poc and vpoc.
bomberone3
 
Posts: 21
Joined: Wed Oct 12, 2011 3:08 am

Next

Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot] and 31 guests