Marcel
January 22, 2021, 7:54pm
#1
I'm trying to set for a sell condition that there are 5 green or up bars since the buy. In this example code, it would appear that the count is resetting each time it sees a new buy condition. Can anyone point out my error?
Buy = Cross( MACD(), Signal() );
NumberBars = BarsSince( Buy );
UpBar = Close > Open;
BarsConditionTrue = Sum( UpBar, NumberBars );
Sell = iif( BarsConditionTrue > 5, 1, 0 );
Short = Cover = 0;
//remove excess Buy,Sell,Short,Cover signals
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
1 Like
fxshrat
January 22, 2021, 8:44pm
#2
It is similar to one previous thread of yours
I'm trying to make a simple short selling code. The rules are as follows:
Below the 100MA, short after 2 up bars
Cover after any 3 down bars following the short
I have a counter to add up 3 down bars any time after the short, but each time it sees an additional short signal, it resets the counter to 0.
I think because it is self referencing that I have to use a loop but I'm not sure how I can do that. Would a competent coder be able to help me? I'd certainly be willing to offer some modest cā¦
Buy = Cross( MACD(), Signal() );
UpBar = Close > Open;
/// Similar to
/// @link https://forum.amibroker.com/t/do-i-need-to-make-a-loop-for-self-referencing-code/17705/2
Sell = 0;
cnt_array = Null;
bprice = cnt = 0;
for ( i = 0; i < BarCount; i++ ) {
if ( Buy[ i ] && bprice == 0 ) {
bprice = BuyPrice[ i ];
} else Buy[ i ] = 0;
if ( bprice > 0 ) {
if ( UpBar[i] )
cnt++;
// exit if count of UpBar > n
if (cnt > 5) {
Sell[ i ] = 1;
bprice = cnt = 0;
}
cnt_array[ i ] = cnt; // store cnt to array
}
}
Plot( C, "Price", colorDefault, styleBar );
PlotShapes( Buy * shapeUpArrow + Sell * shapeDownArrow,
IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, L, H ) );
Plot( cnt_array, "UpBarCount", colorYellow, styleOwnScale );
3 Likes
Marcel
January 22, 2021, 9:30pm
#3
Thank you so much again @fxshrat , I hope all is well with you.
system
Closed
May 2, 2021, 9:31pm
#4
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.