[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [amibroker] sum only positive days



PureBytes Links

Trading Reference Links

Here's what I came up with, verbose for clarity, not sure what it means as
an indicator:

-------------
lookback = Param("Lookback", 20, 1, 100, 1);

bi = BarIndex();

up_day = close > Ref(c, -1);	// or close > open;
bi_of_first_up_day_to_count = ValueWhen(up_day, bi, lookback);
bars_back_to_count_up = bi - bi_of_first_up_day_to_count + 1;
up_vol = Sum(v * up_day, bars_back_to_count_up);

down_day = close < Ref(close, -1);	// or close < 0pen;
bi_of_first_down_day_to_count = ValueWhen(down_day, bi, lookback);
bars_back_to_count_down = bi - bi_of_first_down_day_to_count + 1;
down_vol = Sum(v * down_day, bars_back_to_count_down);

up_down_vol_diff = up_vol - down_vol;

filter = 1;
AddColumn(bi, "BarIndex", 1.0);
AddColumn(v, "Volume", 1.0);
//AddColumn(c, "Close");

AddColumn(up_day, "Up day", 1.0);
AddColumn(bi_of_first_up_day_to_count, "bi_of_first_up_day_to_count", 1.0);
AddColumn(bars_back_to_count_up, "bars_back_to_count_up", 1.0);
AddColumn(up_vol, "Up volume", 1.0);

AddColumn(down_day, "Down day", 1.0);
AddColumn(bi_of_first_down_day_to_count, "bi_of_first_down_day_to_count",
1.0);
AddColumn(bars_back_to_count_down, "bars_back_to_count_down", 1.0);
AddColumn(down_vol, "Down volume", 1.0);

AddColumn(up_down_vol_diff, "Volume diff", 1.0);

Plot(c, "Price", colorDefault, styleCandle);
Plot(up_down_vol_diff, "Volume diff", colorBlue,
styleHistogram+styleOwnScale);
-----------------

HTH,

Dave



> I want to sum the volume of the last 20 up days and compare it to
> the last 20 down days. This is not to be confused with summing
> the up days of the last 20 bars,  Simple code such as  plot(
> c>ref(c,-1)"",4,2);  will plot just the up days and
> x=iif(c>ref(c,-1),v,0) can calculate the volume but how do I sum
> the last 20 bars where x>0 as opposed to summing the last 20 bars of X  ?
>
> TIA
>
> Regards,
> Jayson
>
>


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/