Please help in AFL-Coding this condition

#1
Hi,


I do not know much coding so need a little help. Thanks for visiting this thread. Please help if you can.


(Signal candle) C > HHV(H,12), hence, i buy at open of next candle.


But, within 2 or 3 candles price comes down and closes below the low of the signal candle. So, i close the trade at a loss. BUT AGAIN, price reverses (say in next 3 or 4 candles) and Closes above the High of the signal candle. In such a case i would like to enter again.


So, how do i refer to the candle / bar where the original signal had occurred ?


I do not want to use "ValueWhen" but want to use BarIndex or something to check if price again starts in original direction within "n" number of candles / bars.


How can i do it ??
 
#2
Hi,


I do not know much coding so need a little help. Thanks for visiting this thread. Please help if you can.


(Signal candle) C > HHV(H,12), hence, i buy at open of next candle.


But, within 2 or 3 candles price comes down and closes below the low of the signal candle. So, i close the trade at a loss. BUT AGAIN, price reverses (say in next 3 or 4 candles) and Closes above the High of the signal candle. In such a case i would like to enter again.

So, how do i refer to the candle / bar where the original signal had occurred ?

I do not want to use "ValueWhen" but want to use BarIndex or something to check if price again starts in original direction within "n" number of candles / bars.


How can i do it ??
well, if price reverses and Closes above the High of the signal candle, your code would automatically buy again cause High in the previous buy is also the highest in the last 12 bars.

Anyway if you want to know the buy bar number you could use

BarNumberAtBuy = ValueWhen (buy, barindex());

or

BarsSinceLastBuy= BarsSince (buy);



let me know if I centered the matter
 

casoni

Well-Known Member
#3
Hi,


I do not know much coding so need a little help. Thanks for visiting this thread. Please help if you can.


(Signal candle) C > HHV(H,12), hence, i buy at open of next candle.


But, within 2 or 3 candles price comes down and closes below the low of the signal candle. So, i close the trade at a loss. BUT AGAIN, price reverses (say in next 3 or 4 candles) and Closes above the High of the signal candle. In such a case i would like to enter again.


So, how do i refer to the candle / bar where the original signal had occurred ?

How can i do it ??
Hello Rook,
is this close to your theory ?
* Green bar is the signal bar...

 
#4
Thanks, Cippo.

I guess that's what i was looking for. I will try and get back to you on this.


well, if price reverses and Closes above the High of the signal candle, your code would automatically buy again cause High in the previous buy is also the highest in the last 12 bars.

Anyway if you want to know the buy bar number you could use

BarNumberAtBuy = ValueWhen (buy, barindex());

or

BarsSinceLastBuy= BarsSince (buy);



let me know if I centered the matter
 
#5
Casoni Sir, what i understood from the pic is.. and what fits the need is..

The green bar is signal bar and price falls below its low. So we close the position at loss.

the next green bar in the pic closes above previous green signal bar so we enter again.

So i guess that's what pic tell us. If that's the case, then yes, that's the needed solution.

Thanks..


Hello Rook,
is this close to your theory ?
* Green bar is the signal bar...

 

casoni

Well-Known Member
#6
Casoni Sir, what i understood from the pic is.. and what fits the need is..

The green bar is signal bar and price falls below its low. So we close the position at loss.

the next green bar in the pic closes above previous green signal bar so we enter again.

So i guess that's what pic tell us. If that's the case, then yes, that's the needed solution.

Thanks..
Code:
//(Signal candle) C > HHV(H,12), hence, i buy at open of next candle
hv=HHV(H,12);
Plot(hv,"HHV-12",4,1);
Blev=Cross(C,Ref(Hv,-1));
Buy=Ref(blev,-1);
BuyPrice=Open;
stop=ValueWhen(Blev,L,1);
Plot(stop,"Stop",3,32);
Sell=Cross(stop,L);
SellPrice=stop;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
PlotShapes(Buy*1,27,0,L,-15);
PlotShapes(sell*2,28,0,h,-15);
PlotShapes(Buy*23,2,0,buyprice,0);
PlotShapes(sell*23,2,0,sellprice,0);
COL=IIf(BLEV,5,31);
Plot(C,"Price",COL,132);