# How to find events

hi all
what i need is to find out the number of event happened in n period

H1=HHV(High,10);
L1=LLV(Low,10);

diffh1l1= (H1+L1)/2;

priceup=Close>diffh1l1 ;

pricedown=Close<diffh1l1 ;

so how many time (priceup=Close>diffh1l1 it happen in the pass 10 dayes

and so how many time ( pricedown=Close<diffh1l1 ; ) it happen in the pass 10 dayes

my idea is to find out the stock that fluctuations continuously move up and down

thank you

hi all i find this one but it give me the same number in both CountConditions

up or down

thank you

@needhelp use the SUM function.
AFL Function Reference - SUM

``````priod1=15;

bshi = HHVBars(High,priod1); // find the number of the BAR when the highest value occurs

bsLO = LLVBars(Low,priod1);// find the number of the BAR when the lowest value occurs

thefrist=IIf(bshi>bsLO,bshi,bsLO);// find which one occurs first

hiestv=HHV(High,thefrist);// find the highest value

lowestv=LLV(Low,thefrist); // find the lowest value

centerp= (hiestv+lowestv)/2; // find the mid value

Condition1= Close> centerp; //Condition1
Condition2= Close< centerp;//Condition2

// how to find  ( how many times Condition1 occurs in )

//  thefrist=IIf(bshi>bsLO,bshi,bsLO);// find which one occurs first

// how to find  ( how many times Condition2 occurs in )
//  thefrist=IIf(bshi>bsLO,bshi,bsLO);// find which one occurs first

Conditionhi = Condition1;
CountConditionshi = Cum(Conditionhi);
Conditionlo = Condition2;
CountConditionslo = Cum(Conditionlo);
``````

so it is not what i want
also when the event occur in the last day it will count 14 days not 15

thank you

hi all
i need help i tried many times but i think is the age problem .

``````H1 			= HHV( High, 10 );
L1 			= LLV( Low, 10 );
diffh1l1 	= ( H1 + L1 ) / 2;

priceup 	= Close > diffh1l1 ;
pricedown 	= Close < diffh1l1 ;

// use function SUM to add up the number of occurrences in past 10 bars
UpPrev10 	= Sum( priceup, 10 );
DnPrev10 	= Sum( pricedown, 10 );

``````

so how many time ( not in the 10 days)

if H1 occurs in 3 days ago and L1 occurs in 8 days ago

than we will use 8 days to find the number of occurrences

thank you again

this what i did after your help

``````priod1=10;

H1 			= HHV( High, 10 );
L1 			= LLV( Low, 10 );
diffh1l1 	= ( H1 + L1 ) / 2;

newpireiod=IIf(HHVBars(High,priod1)>LLVBars(Low,priod1),HHVBars(High,priod1),LLVBars(Low,priod1));// find which one occurs firs

priceup 	= Close > diffh1l1 ;
pricedown 	= Close < diffh1l1 ;

// use function SUM to add up the number of occurrences in past 10 bars
UpPrev10 	= Sum( priceup, newpireiod );
DnPrev10 	= Sum( pricedown, newpireiod );
``````

but i odes not count the last bar
the l1 occurs in 2 days the h1 occurs in 7 days (but it count the hi in 6 days)

thank you

i think you are right because will check the occurrences between them

thank you

sorry but I get different result

``````_SECTION_BEGIN("test");

priod1=30;

H1 			= HHV( High, priod1 );
L1 			= LLV( Low, priod1 );
diffh1l1 	= ( H1 + L1 ) / 2;

newpireiod=IIf(HHVBars(High,priod1)>LLVBars(Low,priod1),HHVBars(High,priod1),LLVBars(Low,priod1));// find which one occurs firs

priceup 	= Close > diffh1l1 ;
pricedown 	= Close < diffh1l1 ;

// use function SUM to add up the number of occurrences in past 10 bars
UpPrev10 	= Sum( priceup, newpireiod );
DnPrev10 	= Sum( pricedown, newpireiod );

Filter=1;

_SECTION_END();
``````  sorry all for taking from your time
and thank you for your help

black line is

``````diffh1l1 	= ( H1 + L1 ) / 2;

``````

thank you

Did you try to add all your variables in the exploration? This helps in "tracing" the results.

``````AddColumn( h1, "h1", 1.2,colorGreen);
``````
2 Likes

yes
but the important how many days up and down based on center line

``````AddColumn( UpPrev10, "UpPrev10", 1.2,colorGreen);
``````

based in new period

``````AddColumn( newpireiod, "newpireiod", 1.2,colorGreen);
``````

when i change this line

``````newpireiod=IIf(HHVBars(High,priod1)>LLVBars(Low,priod1),HHVBars(High,priod1),LLVBars(Low,priod1));// find which one occurs firs
``````

to

``````newpireiod=IIf(HHVBars(High,priod1)>LLVBars(Low,priod1),LLVBars(Low,priod1),HHVBars(High,priod1));// find which one occurs last
``````

it is give me good result so far

and i think is logic to measure the stock fluctuating between hi and low

so the solution from [portfoliobuilder] was good

thank you for both of you

Maybe I will find a stock that meets the specifications at least, trying to become rich before I die

The idea is to find out which stock is worth \$1, and after five days or less, it will jump to 20 or more, or achieve a rate of 500% and higher.

That's why I bought AmiBrooker and started learning coding AFL

sounds like you need to backtest your trading strategy. With the backtest result you can see how realistic your expectation is.
Good luck.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.