Buy & Sell signals in Explorer vs Range (From-To-dates)

Hi, and sorry if my question is really silly.

I have a very simple system:

// Medias
Periodo_Media_Rapida = 10;	
Periodo_Media_Lenta = 30; 
	
//Canal de Donchian
Periodo_Canal_Superior = 20; 
Periodo_Canal_Inferior = 20; 	

// Para el desempate en Score
Periodo_ROC = 25; 

////////// INDICADORES  

// Medias
Media_Rapida = MA(Close,Periodo_Media_Rapida);
Media_Lenta = MA(Close,Periodo_Media_Lenta);

//Canal de Donchian
Canal_Superior = HHV(Ref(High,-1), Periodo_Canal_Superior); 
Canal_Inferior = LLV(Ref(Low,-1), Periodo_Canal_Inferior); 

// Para el desempate
Momentum = ROC(Close,Periodo_ROC);
Volatilidad = ATR(20);

///////////  SETUPS  

// Medias
Medias_Alcistas = Media_Rapida > Ref(Media_Lenta,-5);
Medias_Bajistas = Media_Rapida < Ref(Media_Lenta,-5);

Cruce_Alcista = Cross(Media_Rapida,Media_Lenta);
Cruce_Bajista = Cross(Media_Lenta,Media_Rapida);

//Canal de Donchian
Ruptura_Canal_Superior = High > Canal_Superior;
Ruptura_Canal_Inferior = Low < Canal_Inferior;

// Para el desempate
Score = Momentum/Volatilidad;

//////////// REGLAS DEL SISTEMA  

//CONDICIONES DE ENTRADA
BuySetup= Ref(Medias_Alcistas,-1) AND Ref(Ruptura_Canal_Superior,-1) AND Ref(Mercado_Acista,-1);
Buy = BuySetup;
BuyPrice = Open;

// Para el desempate
PositionScore = Score;

//CONDICIONES DE SALIDA
//SellSetup = Ref(Cruce_Bajista,-1);
SellSetup = Ref(Cross(Media_Lenta,Close),-1);
Sell = SellSetup;
SellPrice = Open;

//Limpieza de Señales Extra
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

And in the Explorer, I want to see Buy or Sell signals that fall within the selected range. I don't want to see Sell signals that originate from Buy signals placed before the selected range (I'm not sure if I'm explaining myself clearly).

In Explorer, I've gotten this far so far:

if( Status("action") == actionExplore )
{
    bi = BarIndex(); //genera un array que contiene el número o índice de cada barra del gráfico
    
    SFBIR = Status( "firstbarinrange" );
	SLBIR = Status( "lastbarinrange" );
    
    InRange = bi >= SFBIR AND bi <= SLBIR;

    ValidBuy  = Buy  AND InRange;
    ValidSell = Sell AND InRange;

    Filter = ValidBuy OR ValidSell;

	AddColumn(Buy, "Buy"); 
	AddColumn(Sell, "Sell"); 
	AddColumn(Score, "Score"); 
}

But that doesn't work.
I would appreciate any help.

To be more specific, what I'm looking for is:
That the explorer starts with signals within the selected range, but if they are Sell signals (i.e., they come from a Buy signal prior to the range), it doesn't show them.

The issue is that Status("firstbarinrange") and Status("lastbarinrange") return arrays with one bar set to True. They do not return a bar number or bar index as you assumed.

Instead try Status(“barinrange”). From the AmiBroker help:

"barinrange" - returns 1 when current bar is within current auto-analysis From-To range

Thanks for the info, mradtke.

I've changed it to this:

if( Status("action") == actionExplore )
{
    ValidBuy  = Buy  AND Status( "barinrange" );
    ValidSell = Sell AND Status( "barinrange" );

    Filter = ValidBuy OR ValidSell;

	AddColumn(Buy, "Buy"); 
	AddColumn(Sell, "Sell"); 
	AddColumn(Score, "Score"); 
}

Look at what's happening in the Explorer (which has a range from January 1, 2025, to June 20, 2025). The first signals it identifies are Sells (which come from Buys made before the range), and I don't want to see those signals.

I would like the first signal in the Explorer to be a Buy, the one from January 6, 2025. This is the first trade within the range.

You could try something like this to verify that at least one valid Buy has already occurred before the Sell:

ValidSell = Sell AND Status( "barinrange" ) AND Highest(ValidBuy) > 0;

2 Likes