AFL to plot line on next few bars

colion

Active Member
#21
It is still not clear exactly what your problem is. Your original question was "suggest how to combine different indicator signals that appear on different bars, into one." So, do you want a buy/sell when all three signals occur simultaneously or, for example, when all three signals are in effect (i.e., all have been triggered and none have reversed)?

Your buy/sell code I believe breaks down to:

Buy = Buy1 and Buy2 and Buy3
Sell = Sell1 and Sell2 and Sell3
ExRem(), ExRem()

Buy1/Sell1 occur on one bar and the other two conditions potentially over a range of bars. You must decide how you want to handle this situation. Depending on what you decide using individually or in combination (1) ExRem() which reverts array values after the signal to 0, (2) Flip() which holds the true value until a reversal or (3) something like BarsSince() should be able to make the code do what you want.

On another matter, there is something wrong with VWAP when using daily data (it has a constant value of 1). Your code might be OK for intraday but I did not check. For daily data I use vwap = MA( ( ( H + L ) / 2 ) * V, period ) / MA( V, period ). In any case, you can easily check the values that you are getting with readily available programs/websites/broker platforms.
 
#22
Hi Colion,

when all three signals are in effect (i.e., all have been triggered and none have reversed)?
Yes, when all 3 have triggered and none have reversed yet.

Buy1/Sell1 occur on one bar and the other two conditions potentially over a range of bars.
Yes, that describes the conditions perfectly.

You must decide how you want to handle this situation. Depending on what you decide using individually or in combination (1) ExRem() which reverts array values after the signal to 0, (2) Flip() which holds the true value until a reversal or (3) something like BarsSince() should be able to make the code do what you want.
Would you be kind enough to describe how exrem and barsince can be used ? Another Forum member Happy Singh suggested me to use Flip for individual conditions and it seemed to have worked for now. At least, in the initial testing.

On another matter, there is something wrong with VWAP when using daily data (it has a constant value of 1). Your code might be OK for intraday but I did not check. For daily data I use vwap = MA( ( ( H + L ) / 2 ) * V, period ) / MA( V, period ). In any case, you can easily check the values that you are getting with readily available programs/websites/broker platforms.
Yes, even i found that when i used intraday VWAP i got wrong results. Many thanks for sharing your VWAP formula. Let me try to substitute with your formula.
 

KelvinHand

Well-Known Member
#23
Hi,
Is it possible plot lines only next few bars from selected value and it should not be extended after that. Please find sample image below. Thanks for the help



Thanks
- look back 10 bars


PHP:
Plot(C, "", colorBlack, styleCandle);

Solution = H>Ref(H, -1) AND Ref(H, -1)>Ref(H, -2) AND 
     H>Ref(H, 1) AND 
     H>Ref(H, 2) AND 
     H>Ref(H, 3) AND 
     H>Ref(H, 4) AND 
     H>Ref(H, 5) AND 
     H>Ref(H, 6) AND 
     H>Ref(H, 7) AND 
     H>Ref(H, 8) AND 
     H>Ref(H, 9);

Kelvin = ValueWhen(Solution , H);  

KH = BarsSince(Solution);

Hand= iif(KH<10,Kelvin, Null); 

Plot(Hand, "KelvinHand", colorRed, styledots);
 
Last edited:

colion

Active Member
#24
Would you be kind enough to describe how exrem and barsince can be used ? Another Forum member Happy Singh suggested me to use Flip for individual conditions and it seemed to have worked for now. At least, in the initial testing.
As I said and as noted in the Users Guide, ExRem() changes Buy/Sell array values to zero after the signal which you say you do not want because you want all signals to trigger and not be reversed which is why Flip() works. Sounds like you are done so why the original question? As for BarsSince() one way is buyCondition = IIF( BarsSince( Buy ) < BarsSince( Sell ), 1, 0 )
 
Last edited:
#25
As I said and as noted in the Users Guide, ExRem() changes Buy/Sell array values to zero after the signal which you say you do not want because you want all signals to trigger and not be reversed which is why Flip() works. Sounds like you are done so why the original question? As for BarsSince() one way is buyCondition = IIF( BarsSince( Buy ) < BarsSince( Sell ), 1, 0 )
Thank You, Colion. Now it is pretty clear how to use flip and buysince.

:thumb:
:)
 

rvlv

Active Member
#26
Hi Kelvin Hand

kindly check if following is ok for drawing line at lowest of 10 bars-suspect last line has error possibly.
thanks
HTML:
//DRAW LINE AT LOWEST OF 10 BARS-in the similarity of KelvinHand code

SolutionDN = L<Ref(L, -1) AND Ref(L, -1)<Ref(L, -2) AND 
     L<Ref(L, 1) AND 
     L<Ref(L, 2) AND 
     L<Ref(L, 3) AND 
     L<Ref(L, 4) AND 
     L<Ref(L, 5) AND 
     L<Ref(L, 6) AND 
     L<Ref(L, 7) AND 
     L<Ref(L, 8) AND 
     L<Ref(L, 9);

KelvinDN = ValueWhen(Solution , L);  

KHDN = BarsSince(SolutionDN);

HandDN= IIf(KHDN<10,KelvinDN, Null); 

Plot(HandDN, "KelvinHandDN", colorGreen, styleDots);












- look back 10 bars


PHP:
Plot(C, "", colorBlack, styleCandle);

Solution = H>Ref(H, -1) AND Ref(H, -1)>Ref(H, -2) AND 
     H>Ref(H, 1) AND 
     H>Ref(H, 2) AND 
     H>Ref(H, 3) AND 
     H>Ref(H, 4) AND 
     H>Ref(H, 5) AND 
     H>Ref(H, 6) AND 
     H>Ref(H, 7) AND 
     H>Ref(H, 8) AND 
     H>Ref(H, 9);

Kelvin = ValueWhen(Solution , H);  

KH = BarsSince(Solution);

Hand= iif(KH<10,Kelvin, Null); 

Plot(Hand, "KelvinHand", colorRed, styledots);
 

KelvinHand

Well-Known Member
#27
Hi Kelvin Hand

kindly check if following is ok for drawing line at lowest of 10 bars-suspect last line has error possibly.
thanks
//DRAW LINE AT LOWEST OF 10 BARS-in the similarity of KelvinHand code

SolutionDN = L<Ref(L, -1) AND Ref(L, -1)<Ref(L, -2) AND
L<Ref(L, 1) AND
L<Ref(L, 2) AND
L<Ref(L, 3) AND
L<Ref(L, 4) AND
L<Ref(L, 5) AND
L<Ref(L, 6) AND
L<Ref(L, 7) AND
L<Ref(L, 8) AND
L<Ref(L, 9);

KelvinDN = ValueWhen(Solution<==== , L);

KHDN = BarsSince(SolutionDN);

HandDN= IIf(KHDN<10,KelvinDN, Null);

Plot(HandDN, "KelvinHandDN", colorGreen, styleDots);
 

Similar threads