Need AFL/PI code. Help me

#1
If
Lowest low<=open Price=>highest high
then
Buy=3 points above previous highest high candle
Exit= 6 points above previous highest high candle; or lowest low of previous candle

Trying in AFL wizard, but i am not familiar with coding as how to add 3 points on the previous candle stick high
 

casoni

Well-Known Member
#2
if
lowest low<=open price=>highest high
then
buy=3 points above previous highest high candle
exit= 6 points above previous highest high candle; or lowest low of previous candle

trying in afl wizard, but i am not familiar with coding as how to add 3 points on the previous candle stick high
buy=ref(h,-1)+3;
exit=ref(h,-1)+6 or ref(l,-1);
 
#3
Thanks casoni,

But it showing the blank as its not showing any signal. not even showing graph. i added to the Price List graph, then too its not showing...backtesting showing error 701, but scan showing many buy and sell trades at same price....

My concern is i want to enter at previous high candle + 3 and exit/sell at previous high candle 6 or if stock falls, then i want to exit at lowest of previous candle

thanks for the help


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

buy=ref(h,-1)+3;
sell=ref(h,-1)+6 or ref(l,-1);
 

casoni

Well-Known Member
#4
Thanks casoni,

But it showing the blank as its not showing any signal. not even showing graph. i added to the Price List graph, then too its not showing...backtesting showing error 701, but scan showing many buy and sell trades at same price....

My concern is i want to enter at previous high candle + 3 and exit/sell at previous high candle 6 or if stock falls, then i want to exit at lowest of previous candle

thanks for the help


_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

buy=ref(h,-1)+3;
sell=ref(h,-1)+6 or ref(l,-1);
to backtest you need to define Buy,Sell,Short,Cover rules
this will be your Buy,Sell
//Buy=H>Ref(H,-1)+3;
//Sell=H>Ref(H,-1)+6 OR C<Ref(L,-1);
Buy=C>Ref(H,-1)+3;
Sell=C>Ref(H,-1)+6 OR C<Ref(L,-1);

if still you have trouble , post the full concept
 
#5
Thanks Casoni

//Buy=H>Ref(H,-1)+3;
//Sell=H>Ref(H,-1)+6 OR C<Ref(L,-1);
Buy=C>Ref(H,-1)+3;
Sell=C>Ref(H,-1)+6 OR C<Ref(L,-1);
Short=C>Ref(L,-1)-3;
Cover=C>Ref(L,-1)-6 OR C<Ref(H,-1);

i want to enter into the trade two times
Condition 1---> when current open price is in between previous High and previous low Low
Condition 2--->when price moving upward towards high of previous candle ad crosses + 3 points, then BUY
condition 3---->if price return back after touching condition 2, then wait until it reaches low of previous candle. it it touch till previous low, then exit...it will act as stoploss
condition 4----> or if it reaches +6 points more than previous candle, then exit with 3 point profit.

same rule for Short

Condition 1---> when current open price is in between previous High and previous low Low
Condition 2--->when price moving Downwards towards Low of previous candle ad crosses - 3 points, then Short
condition 3---->if price return back after touching condition 2, then wait until it reaches High of previous candle. it it touch till previous high, then exit...it will act as stoploss
condition 4----> or if it reaches -6 points less than previous candle, then exit with 3 point profit.

I checked and backtested, showing buy sell short cover all at same price.
 

casoni

Well-Known Member
#6
is this system based on EOD analysis ? or its for intraday ..


x=Param("Entry ",3,1,10,1);
y=Param("Trget ",6,1,10,1);


long=Ref(H,-1)+x ;
shrt=Ref(L,-1)-x ;
buytarget=Ref(H,-1)+y ;
buystop =Ref(L,-1);
shorttarget= Ref(L,-1)-y ;
shortstop=Ref(H,-1);

cond1=O<Ref(H,-1) AND O>Ref(L,-1);
Buy = cond1 AND C>long;
Short= cond1 AND C<shrt;
Sell=C>buytarget OR C<buystop;
Cover=C<shorttarget OR C>shortstop;

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
 
Last edited:
#7
Ref(L,-1)>O<Ref(H,-1);
Buy=C>Ref(H,-1)+3;
Sell=C>Ref(H,-1)+6 OR C<Ref(L,-1);
ref(L,-1)>O<Ref(H,-1);
Short=C<Ref(L,-1)-3;
Cover=C<Ref(L,-1)-6 OR C>Ref(H,-1);


Checking for Intraday....but does it really matter :confused:
 

casoni

Well-Known Member
#8
Ref(L,-1)>O<Ref(H,-1);
Buy=C>Ref(H,-1)+3;
Sell=C>Ref(H,-1)+6 OR C<Ref(L,-1);
ref(L,-1)>O<Ref(H,-1);
Short=C<Ref(L,-1)-3;
Cover=C<Ref(L,-1)-6 OR C>Ref(H,-1);


Checking for Intraday....but does it really matter :confused:
this type of setup will be visualized nicely on Ieod , On EOD it will be confusing .... that all ..

you will get buy/sell or short/cover on same bar also .. because of target level are small ...



check the code i have posted in earlier messsage #6
 
#9
Symbol Trade Date Close

CRUDEOIL14DECFUT.MX Buy 10-12-2014 11:59:59 3932.0000
CRUDEOIL14DECFUT.MX Cover 10-12-2014 11:59:59 3932.0000
CRUDEOIL14DECFUT.MX Sell 10-12-2014 13:59:59 3910.0000
CRUDEOIL14DECFUT.MX Short 10-12-2014 13:59:59 3910.0000
CRUDEOIL14DECFUT.MX Short 10-12-2014 15:59:59 3892.0000
CRUDEOIL14DECFUT.MX Cover 10-12-2014 15:59:59 3892.0000
CRUDEOIL14DECFUT.MX Short 10-12-2014 19:59:59 3884.0000
CRUDEOIL14DECFUT.MX Cover 10-12-2014 21:59:59 3799.0000
CRUDEOIL14DECFUT.MX Short 11-12-2014 18:59:59 3790.0000
CRUDEOIL14DECFUT.MX Cover 11-12-2014 20:59:59 3807.0000
CRUDEOIL14DECFUT.MX Short 12-12-2014 13:59:59 3698.0000
CRUDEOIL14DECFUT.MX Buy 12-12-2014 17:59:59 3716.0000
CRUDEOIL14DECFUT.MX Cover 12-12-2014 17:59:59 3716.0000
CRUDEOIL14DECFUT.MX Sell 12-12-2014 18:59:59 3693.0000
CRUDEOIL14DECFUT.MX Short 12-12-2014 18:59:59 3693.0000
CRUDEOIL14DECFUT.MX Cover 12-12-2014 19:59:59 3680.0000
CRUDEOIL14DECFUT.MX Short 12-12-2014 21:59:59 3650.0000


Dont think its working in 1 hr chart....
it must be exited before new candle form
Its working but not what i calculated. Its not exiting trade on +-6 point...thats why showing different trades.

I think its because, if it touch any condition, and its not going towards target or stoploss, then system dont know what to do, and new trade condition will be there for new candle...so its creating different trades.....if it exit either target met or stoploss triggered, then it may work...
one thing more, as if its keep on rolling with new trades say rally candle, then stoploss is designed for previous candle and its not be the same as in rally candle or next to next candle.

only condition i think will work if it enter into trade and exit before new candle form or stoploss will be the same until the target met.
Buy= as per condition +3 ---- suppose condition met
stoploss= previous candle low----waiting
Sell= As per condition +6----------waiting

Now new candle form without hitting the target or hitting the stoploss, then stoploss shifted to previous candle and its not true, because stoploss or target will be same for first trade

And thanks for what you have done for me..... Thanks a lot
 
Last edited:

casoni

Well-Known Member
#10
Symbol Trade Date Close

CRUDEOIL14DECFUT.MX Buy 10-12-2014 11:59:59 3932.0000
CRUDEOIL14DECFUT.MX Cover 10-12-2014 11:59:59 3932.0000
CRUDEOIL14DECFUT.MX Sell 10-12-2014 13:59:59 3910.0000
CRUDEOIL14DECFUT.MX Short 10-12-2014 13:59:59 3910.0000
CRUDEOIL14DECFUT.MX Short 10-12-2014 15:59:59 3892.0000
CRUDEOIL14DECFUT.MX Cover 10-12-2014 15:59:59 3892.0000
CRUDEOIL14DECFUT.MX Short 10-12-2014 19:59:59 3884.0000
CRUDEOIL14DECFUT.MX Cover 10-12-2014 21:59:59 3799.0000
CRUDEOIL14DECFUT.MX Short 11-12-2014 18:59:59 3790.0000
CRUDEOIL14DECFUT.MX Cover 11-12-2014 20:59:59 3807.0000
CRUDEOIL14DECFUT.MX Short 12-12-2014 13:59:59 3698.0000
CRUDEOIL14DECFUT.MX Buy 12-12-2014 17:59:59 3716.0000
CRUDEOIL14DECFUT.MX Cover 12-12-2014 17:59:59 3716.0000
CRUDEOIL14DECFUT.MX Sell 12-12-2014 18:59:59 3693.0000
CRUDEOIL14DECFUT.MX Short 12-12-2014 18:59:59 3693.0000
CRUDEOIL14DECFUT.MX Cover 12-12-2014 19:59:59 3680.0000
CRUDEOIL14DECFUT.MX Short 12-12-2014 21:59:59 3650.0000


Dont think its working in 1 hr chart....
it must be exited before new candle form
Its working but not what i calculated. Its not exiting trade on +-6 point...thats why showing different trades.

I think its because, if it touch any condition, and its not going towards target or stoploss, then system dont know what to do, and new trade condition will be there for new candle...so its creating different trades.....if it exit either target met or stoploss triggered, then it may work...
one thing more, as if its keep on rolling with new trades say rally candle, then stoploss is designed for previous candle and its not be the same as in rally candle or next to next candle.

only condition i think will work if it enter into trade and exit before new candle form or stoploss will be the same until the target met.
Buy= as per condition +3 ---- suppose condition met
stoploss= previous candle low----waiting
Sell= As per condition +6----------waiting

Now new candle form without hitting the target or hitting the stoploss, then stoploss shifted to previous candle and its not true, because stoploss or target will be same for first trade

And thanks for what you have done for me..... Thanks a lot

then use this and check

Buy = cond1 AND H>long;
Short= cond1 AND L<shrt;
Sell=H>buytarget OR L<buystop;
Cover=L<shorttarget OR H>shortstop;
 

Similar threads