Help needed for this simple afl

#1
Hello friends,


1st Afl
=======
Can anyone help me to write this simple trading system to backtest.
The buy criteria goes as such;

Buy on the third bar in a series of three consecutive higher highs and
the buy bar (ie the third bar) must be a bar whose close is greater than the open.
So far things are ok but I want to sell on the fourth bar close.
Please make the necessary correction in the afl below.

I want to sell on the next day of the buy bar and run the system to see
how many winners and losers will this system give me over a given period.



Cond1 = High > Ref(High,-1) AND Ref(High,-1) > Ref(High,-2);

Filter = 1 AND Cond1 and C > H;

buy = Cond1 and C > H;

// I want to sell on the next day of the buy
Sell = ????;

If I write the sell statement as
Sell = Ref(Close,1); then I get numerious red arrows following the above criteria and the system
does not give correct values when I back test it or when I click for report generation.

On the basis of selling the following day I can use a number of combinations as filters and get some simple trading systems.
The afl can give which criterias are a good one day winners. Of course this is a system and one can get more losers than winners.





2nd AFL
=======

One sees various coloured labels corresponding to indicators in the right side in the price label axis.
The last traded price or Close is in black.

I want to write for example an afl which will correspond to a particular criteria eg.
if the current close is above the 200 dma so the same should be filtered and shown


one can write
Filter = Cross(Close, dma(close,200);

but since i have the dma line on the chart in the colour red and a red label on the value label axis on the right
with a numerical value corresponding to the last dma(200) value. I also have a close price label of the last bar
in black,

How can I write the same filter as above but using only the label colours which I know before hand.


Thanks in advance,
bam
 
#2
Hello,

I know the solution for only 1st AFL, what u can do is
Sell=buy; // essentially u are selling based on the rule of buy

But when u run the back test, under the settings menu, make the sell order delay by the no. of days which u require.
Steps :
Under the automatic analysis once u have edited the afl file save it and close
Below the scan and explore buttons there is settings.. open it
It opens the menu backtester settings. Under this select Trades menu, under this set the Sell delay to 1 with default buy delay as zero. This will essentially close the trade on the next day. Useful for back testing.

Hope this will suffice. I am yet not knowledgeable to answer 2nd AFL query.

regards,
mohan.
 
#4
Here goes your first AFL :

_SECTION_BEGIN("Buy-Sell");
BuyCondition = H > Ref(H, -1) AND Ref(H, -1) > Ref(H, -2) AND Ref(H, -2) > Ref(H, -3) AND C > O;

Buy = 0; Sell = 0; LongPosition = 0;
for (i = 1; i < BarCount; i++)
{ if (LongPosition == 0 AND BuyCondition == 1) {Buy=1; Sell=0; BuyPrice=C; LongPosition=1; BarBought=i;}
if (LongPosition == 1 AND i == BarBought + 1) {Buy=0; Sell=1; SellPrice=C; LongPosition=0;}
}


Buyshape = Buy * shapeUpArrow;
SellShape = Sell * shapeDownArrow;

PlotShapes(BuyShape, colorLime, 0, L);
PlotShapes(SellShape, colorOrange, 0, H);
_SECTION_END();
 

MSN1979

Well-Known Member
#7
Here goes your first AFL :

_SECTION_BEGIN("Buy-Sell");
BuyCondition = H > Ref(H, -1) AND Ref(H, -1) > Ref(H, -2) AND Ref(H, -2) > Ref(H, -3) AND C > O;


Buy = 0; Sell = 0; LongPosition = 0;
for (i = 1; i < BarCount; i++)
{ if (LongPosition == 0 AND BuyCondition == 1) {Buy=1; Sell=0; BuyPrice=C; LongPosition=1; BarBought=i;}
if (LongPosition == 1 AND i == BarBought + 1) {Buy=0; Sell=1; SellPrice=C; LongPosition=0;}
}



Buyshape = Buy * shapeUpArrow;
SellShape = Sell * shapeDownArrow;


PlotShapes(BuyShape, colorLime, 0, L);
PlotShapes(SellShape, colorOrange, 0, H);
_SECTION_END();
1543119080470.png


This AFL is returning errr in yellow line

Any experts can fix this? Please.
 

Similar threads