I want to buy same scrip at every interval of 100 days and hold it for 10 days on daily timeframe.
But when I run the code, it does nothing. Any idea how to achieve this task.
Hi Siraj,
your code doesn't produce any trade because you wrote wrong conditions. You have to consider that AFL interprete any variable as an array and the word "buy" and "sell" are reserved for long entry and exit signals. For example by writing: Buy = 1;
you are telling AFL to buy for every day. Moreover adding the second condition is pointless because all the possible entry points are already set on TRUE.
For further information on how AFL works I can suggest to read carefully the manual.
Your task could be solved in different ways either by looping or using the array features of AFL.
I could suggest you this one that use AFL's array processing features:
// buy_every_100_days.afl
//determining the first trading day:
bi = BarIndex();
firstBI = ValueWhen(Status("firstbarinrange"),bi);
barsSinceFirstBuy = bi - firstBI;
// signals every 100 bars:
Buy = barsSinceFirstBuy % 100 == 0;
Sell = 0;
// stop after 10 bars
ApplyStop(stopTypeNBar, stopModeBars, 10);