how to use for loops (?)

neon

New Member
#1
Hi all ! I'm new here and I'm new in Amibroker. I'm looking help for write a code for back test for rules:
1. buy when MACD cross Signal , and....
2. the same conditions like in 1. but occured max 10 days befor 1.

I'm thinking the best way is to use for loop but how to write it in AFL ...?

please, help ....
 

neon

New Member
#3
Hi All,
I 've created two codes:

// j1 = condition of cross

1.
for (i=1; i < 4; i++)
{
factor = Ref( j1, -i );
}
buy = j1 and factor >0;

2.
for( i = 1; i < 4; i++ )
{
VarSet( "ab"+i, Ref( j1, -i ) );
}
con1 = ab1+ab2+ab3;
con2 = con1>0;
buy = j1 and con2;

...
1. is not working good, because buy only for j1 and Ref(j1,-3).
2. is working good but is not smooth.

Could you correct please ????
 
#4
Have you tried the following :

cond = condition for cross ;

Buy = hhv(cond ,10 ) == 1 // for cross in any of past 10 days

Buy = ref(cond ,-10 ) == 1 // for cross 10 days back
 

neon

New Member
#5
thanks Pankaj, but...
work but need to modifed:

Buy = cand And Ref((hhv(cond ,10 ) == 1),-1);
now it is ok.

...but still I'm thinking tha the bettre will be to use for...
this code need to be modify.
I belive somebody can do this.

for (i=1; i < 4; i++)
{
factor = Ref( cond, -i );
}
buy = cond and factor >0;
 
#6
It is a very Difficult to predict The Intraday trend for any Stock.
Follow the below method to get an 360 degree overview how the market behaves and where the common trader do not pay attention.

Price and volume is the main parameter for any trading.
On any of your trading software open any scrip.
open the chart
set to 5 min candle stick pattern
Add 3 study of Average line
5 mins, 15 mins and 30 mins.

Follow the indication of these line.
Buy the Scrip if the 5 mins average line cut the 30 mins average line and move up (increase in volume)
Sell the the Scrip if the 5 mins average line cut the 30 mins average line and move down (increase in volume)

Hope This might be very helpfull for All the levels of investers and traders.

thanks enjoy trading:)