Hello guys!
Nice to join your community.
I will be very thankful if you can help me and advise if the following AFL codes are correct. I am trying a very simple strategy just to test my skills in AFL. The strategy is very simple and it is price based. Rules as follows:
If the price drops a certain percentage BUY.
Close at the end of the day.
I made two versions of this AFL.
One of the codes uses the DAILY timeframe.
The second code uses a 5m timeframe (and actually can be modified to fit any timeframe easily).
The final results from the two AFL codes show some difference but this is expected.
AFL_1:
SetPositionSize(5, spsPercentOfEquity );
SetOption("MaxOpenPositions", 20);
SetOption("AllowSameBarExit", True);
SetTradeDelays(0,0,0,0);
Parameter = Optimize("Parameter", 0.95, 0.9, 0.93, 0.01);
BuyPrice = Ref(C,-1)*Parameter;
SellPrice = Close;
Buy = IIf((L <= Ref(C,-1)*Parameter), 1, 0);
Sell = C > 0;
Filter = 1;
AddColumn(Close, "Close");
AddColumn(Ref(C,-1)*Parameter, "Ref(C,-1)*Parameter)");
AddColumn(L, "LOW");
AFL_2:
SetPositionSize(100, spsPercentOfEquity );
SetOption("MaxOpenPositions", 5);
SetTradeDelays(1,0,0,0);
Parameter = Optimize("Parameter", 0.95, 0.9, 0.98, 0.01);
tn = TimeNum();
PriceAtTime = 0;
Counter = 0;
Start = 0;
for (i = 1; i < BarCount; i++)
{
if(tn[i] == 0 AND Counter < 2016) // Price at 00:00 h -> 5m chart
{
PriceAtTime[i] = Open[i]; // assigning the price to variable
Counter = 0;
Start = 1; // this is used to signal that the counter can start counting
}
if(Counter > 0)
{
PriceAtTime[i] = PriceAtTime[i-Counter];
}
if(Start == 1)
{
Counter++;
}
if( Counter >= 2016)
{
Counter = 0;
}
}
Buy = C <= PriceAtTime*Parameter;
Sell = tn == 000000;
BuyPrice = O;
SellPrice = C;
Filter = 1;
AddColumn(PriceAtTime, "PriceAtTime");
AddColumn(Close, "Close");
AddColumn(tn, "tn");
Thank you for your attention