# Consider only current date bars

dist=2;
bcolor=scolor=colorBlue;

for( i = 0; i < BarCount ; i++ )
{

``````xx  = Sum(Buy,i ); // counting of long trades. xx will not get a higher value until a new long position is Open
// therefor if we only allow one long and one short position (Exrem() ) xx can also be used as an identification
//	number for the diffrent positions.
yy  = Sum(Short,i);

if( Buy[i]==1)  PlotText("LONG : " + xx[i] + "\nBuyPrice: "+ BuyPrice[ i ], i, H[ i ]-dist, colorBlack, bcolor );

if( Short[i]==1 ) PlotText( "SHORT : "+ yy[i]+ "\nShortprice: "+ ShortPrice[ i ], i, L[ i ]+dist, colorBlack, bcolor );

}
``````

The above code in my statergy plots the trade counts as below screenshoot.

It counts the trades from the first bar on the chart.
But I want it should count the trades for the current date only.
Also it consumes a lot of memory I think as the afl becomes very slow.

In your code you are not using Sum, Buy, Short arrays correctly.

You may check these sites
https://www.amibroker.com/guide/h_understandafl.html
https://www.amibroker.com/guide/a_mistakes.html

I am a new-bee, just got the afl from:

Here the author also got puzzled and left it uncompleted. However I liked the logic.

People on this forum generally donâ€™t respond very well to queries of the form â€śCan you write my code for me?â€ť. You will get a much better response if you try your best to write some code, analyze where things are going wrong, and then ask for help when you get stuck.

If you want to count the number of entries that have occurred so far on each day, you could start with something like the following untested code:

``````isStartOfDay = Day() != Ref(Day(),-1);
numShorts = SumSince(isStartOfDay, Short);
``````

In other words, the count will start at 0 each morning, and increase through the end of the day.

Matt

Thanks for your help @ Matt.

I tried using your code , but no success.

and then let me have the snippet for my idea.

Thanks for your help @ Matt.

I tried using your code and could correctly captured the total buy trades and short trades for the current date , JUST NOW I GOT MY FIRST SUCCESS !!! THANKS A A LOT.

now my next targets are to capture:
TOTAL NUMBER OF LOSS TRADES FOR THE DAY =
TOTAL NUMBER OF PROFIT TRADES FOR THE DAY =
TOTAL LOSS/PROFIT FOR THE DAY =

Please give me some hint codes and I will work on it and do it.

Hi;

The below code counts the trades for the day, but I want to add another condition for counting trades in between 9:30 to 3:25â€”

``````isStartOfDay = Day() != Ref(Day(),-1);
numShorts = SumSince(isStartOfDay, Short);
``````

``````isStartOfDay = Day() != Ref(Day(),-1) AND (091600>TimeNum()<152800);
``````

But its not working. Could you please guide further.

Your code is incorrect. You can not write

``````X > Y < Z; // WRONG
``````

Joining any conditions require `AND, OR` operators, so you need to write this:

``````X > Y AND Y < Z;
``````
1 Like