I'm trying to write code which can return some results if the total volume of current day in percent is greater than average volume of past 5 days.
Is it correct to get the average volume of past 5 days?
AverageVolume = MA(Volume, 5);
Let's say the average volume of past 5 days is 10000 then what I want is if at any moment, the volume of current trading day exceeds the average, then it should give me an alert.
Now I want the total volume of the current day for something like this to work:
if(TodayTotalVolume > AverageVolume) {
// Do something here
}
How to get total value of current trading day in real time so that the alert gets generated the moment the condition is satisfied?
Yeah I had read that manual before and know how to add custom columns.
In the code you gave, you have used Volume but won't that give me the volume of the most recent candle formed? If I select daily timeframe, then it will give me volume only after the trading session is over, if I select 15 minute candle then it will only give me volume of the most recent 15 minute candle?
I'm looking for the total traded volume of running trading session at any given point of time when the market is open.
But the data feed I have is not a plugin, it's a software which feeds data into Amibroker so I checked the realtime quote but that was empty. So I can't use the variables given on the above link.
Is there any alternative way to get the total traded volume since market got open in real time?
@sarupria you need to learn how to ask questions AND thank for responses. Your response is unceremonious and does not encourage anyone to help you any further.
Not sure why thought my reply was "unceremonious", it's a normal conversation but if saying thanks is your criteria to provide help then I'll make sure to say thanks whenever I'm in touch with you. Thanks!
Here is version not being dependent on timeframe functions.
It is around three times faster on 100k bars (according to code check and profile).
Results are the same ones (see picture) (while in below version results are also inline between EOD and intraday).
/// @link http://forum.amibroker.com/t/how-to-scan-for-stocks-having-current-day-volume-greater-than-average-of-past-few-days/4612/11
/// code not being dependent on time frame functions
/// instead using sparse functions
/// alternative calculation by fxshrat
dn = DateNum();
newday = dn != Ref(dn , -1);
if( Interval() < inDaily ) { // intraday
SetBarsRequired( 1500 );
TodayVolume = SumSince(newday, V) + ValueWhen(newday, V);
Vcomp = SparseCompress(newday, Ref(TodayVolume, -1));
// Avg. of previous past days
FiveDayAvg = ValueWhen(newday, SparseExpand(newday, MA(Vcomp, period = 5)), 1);
} else {// if EOD
TodayVolume = V;
// Avg. of previous past daily bars
FiveDayAvg = Ref(MA(V, period = 5), -1);
}
/// @link http://forum.amibroker.com/t/how-to-scan-for-stocks-having-current-day-volume-greater-than-average-of-past-few-days/4612/5
/// example output by portfoliobuilder
/////////////////////
// Explore
/////////////////////
Filter = 1;
dynamic_colour = IIf( TodayVolume > FiveDayAvg, colorGreen, colorDefault );
AddColumn( V, "Volume this bar", 1.0 );
AddColumn( TodayVolume, "Cum Volume Today", 1.0, colorDefault, dynamic_colour );
AddColumn( FiveDayAvg, "FiveDayAvg", 1.0 );
/////////////////////
// Chart
/////////////////////
Plot( TodayVolume , "Today Cum Vol", colorRed, styleline );
Plot( FiveDayAvg, "FiveDayAvg", colorbrightgreen, styleDashed );
I think that @portfoliobuilder explained it well enough in his post. Tomasz provided you with ready to use solution (meeting the criteria of your first post), but you didn't say "thank you". Instead you have just changed your criteria and expected another try ...
Tomasz should really appreciate that
Maybe you don't know this yet (because you are a newcomer - you have joined a week ago) but "He" --> Tomasz is the owner and chief software architect of AmiBroker, so I would be really cautious with such remarks... Tomasz is a little bit more experienced in this field, than you
in general, that's a pity, that there is no short info (some kind of short statistics) below the profile picture/pictogram of each user, allowing everyone (especially new users) to quickly recognize more experienced users. In my opinion it would be helpful, because most users don't visit other members' profiles.