Exploration Not Showing Results Despite Valid Condition

Hey guys,

I'm experiencing an issue where my Exploration analysis is not displaying any results, even though my code seems to be working as expected.

I have the following Filter condition in my code:

Filter = inPattern;
AddColumn (inPattern, "inPattern");
AddColumn (isBullish, "isBullish");
  • inPattern is True if time is 10:30 AM and when a bullish pattern (isBullish) is detected.
  • I verified this using _TRACE( "inPattern=" + inPattern);, and the Trace Log correctly shows inPattern = 1 at the expected bar.
  • However, when I run Exploration, it returns no results instead of displaying the bar where inPattern = 1.

Possible Causes I Considered:

  1. Code Logic: The rest of the code works as expected, and the conditions appear correct based on the Trace Log.
  2. Exploration Settings: I'm unsure if my settings are affecting the output.
  • Are there any common settings or filters in the Analysis window that might prevent Filter = inPattern; from returning results?

  • Any insights into debugging why the Exploration feature is not picking up the valid inPattern = 1 bars?

Here's the full code for reference

_TRACE( "!CLEAR!" );
Plot( Close, "Close", colorDefault, styleCandle );
tm = TimeNum();
BI = BarIndex();

//SESSION BREAKS 
isNewDay = Day() != Ref(Day(), -1);
PMstart = Ref(tm,-1) > tm;
PMStartTime = ValueWhen(PMstart,tm);;  	//premarket time start
StartTime 	= 093000; 
PMEndtime = 093000;		//premarket time end
premarket_end = Ref(tm, 1)==093000;
AHStartTime  = 160000;// afterhours time start
AHEndtime = 200000;  // afterhours time end
EndTime   = 100000;
TimeStop = 103000;
bsmo = BarsSince(premarket_end);  //bars since premarket end;
bsnd = BarsSince(isNewDay);  //bars since new day;
market_open = tm == StartTime;

isPreMarket = (tm >= PMStartTime AND tm < PMEndtime);  
isAfterHours = (tm > AHStartTime AND tm < AHEndtime);
PMend = tm == PMEndtime;

Plot( isPreMarket, "", ColorRGB(41, 37, 35), styleArea | styleOwnScale, 0, 1,0,-5 );  
Plot( isAfterHours, "", ColorRGB(24, 33, 55), styleArea | styleOwnScale, 0, 1,0,-5 );

//PREMARKET HIGH AND LOW
PM_High = ValueWhen(isPreMarket, HighestSince(tm == PMStartTime, H));
Plot_PMH = IIf(isPremarket OR isAfterHours, Null,PM_High);


PM_Low = ValueWhen(isPreMarket, LowestSince(tm == PMStartTime, L));
Plot_PML = IIf(isPremarket OR isAfterHours, Null,PM_Low);

PM_DB50 = (PM_High - PM_Low)/2 + PM_Low;
Plot_PMDB50 = IIf(isPremarket OR isAfterHours, Null,PM_DB50);

pmRange = PM_High-PM_Low;
tm_range = tm >= StartTime AND tm <= TimeStop; // from 9:30 to timestop
//_TRACE( "market open=" + market_open);



//DAY HIGH AND LOW AT TIME STOP
swingHigh = HHVBars(H,market_open); // No. of bars since swing3 (needs tweak - this will show up even after tm_range)

swingLow = LLVBars(L,market_open); // No. of bars since swing0 (needs tweak - this will show up even after tm_range)

LOD = ValueWhen(tm_range, LowestSince(premarket_end,L)); // value of L when LOD
isLOD = L==LOD AND tm_range; //bool LOD
index0 = ValueWhen(isLOD,BI);
swing0 = BarsSince(isLOD);
LOD_tm = ValueWhen(isLOD,tm);

HOD = ValueWhen(tm_range, HighestSince(premarket_end,H)); // value of H when HOD
isHOD = H==HOD AND tm_range; //bool HOD
index3 = ValueWhen(isHOD,BI);
HOD_tm = ValueWhen(isHOD,tm);

//tm_range_LOD = tm >= StartTime AND tm <= TimeStop; // from isLOD to timestop

SwingHigh = ValueWhen(tm_range, HighestSince(isLOD, H)); // Track the highest high since LOD
isSwingHigh = H == SwingHigh AND tm_range;              // Check if current bar is Swing High
swing3 = BarsSince(isHOD);



// Look Forward N Bars to Confirm No New SwingHigh
N_count = param("N",3,2,10,1);
N = N_count; // Number of future bars to confirm
NoFutureSwingHigh = True;

// Check for N bars ahead if there's another SwingHigh
for (i = 1; i <= N; i++) 
{
    NoFutureSwingHigh = NoFutureSwingHigh AND Ref(isSwingHigh, i) == 0; 
}

// Confirm Potential Swing
swingH = isSwingHigh AND NoFutureSwingHigh; //boolean

swingH = ExRem(swingH, isLOD);
bsSwingH = BarsSince(swingH); //bars since swingH

//Plot(SwingHigh,"SwingHigh", colorGreen, styleDashed);


// Start Counting Candles After SwingHigh
initialSwing = BarsSince(swingH); // Count bars since last SwingHigh
swing2 =  LLVBars(L,initialSwing);

// look forward N Bars to confirm no new Swing2
s2 = ValueWhen(tm_range, LowestSince(swingH,L)); //swing2

isSwing2 = L==s2 AND tm_range; //bool s2

// Get the bar index of swing0
swing0_index = ValueWhen(isLOD, BI); // Bar index of swing0

// Get the bar index of the last swing2
swing2_index = ValueWhen(isSwing2, BI); // Bar index of the last swing2

//Look forward for future swing2
N2 = IIf(swing2_index > swing0_index, swing2_index - swing0_index, Null);
n_2 = NumToStr(N2);
N2 = StrToNum(n_2);
NoFutureSwingLow = True;
for (i = 1; i <= N2; i++) 
{
    NoFutureSwingLow = NoFutureSwingLow AND Ref(isSwing2, i) == 0; 
}

noSwing2 = isSwing2 AND NoFutureSwingLow;

swing2_tm = ValueWhen(noSwing2 AND BI > swing0_index, tm);
swing0_tm = ValueWhen(isLOD,tm);
zone1 = tm >= swing0_tm AND tm <= Ref(swing2_tm,N2);

s1 = ValueWhen(zone1, HighestSince(swingH,H));
isSwing1 = H==s1 AND tm_range; //bool s1
swing1 = BarsSince(isSwing1);
s1_tm = ValueWhen(isSwing1,tm);


isBullish = swing3 < swing2 AND swing2 < swing1 AND swing1 < swing0 AND
			HOD > s1 AND s2 > LOD;

inPattern = tm == Timestop AND isBullish;
_TRACE( "inPattern=" + inPattern);


//This is the code to label points 0-1-2-3
for( i = 0; i < BarCount; i++ )
{

    if( inPattern[i])
		{
		// Check if swing0, swing3, and bsSwing1 are valid before plotting
		if ( !IsNull(swing0[i]) AND !IsNull(L[i-swing0[i]]) ) 
		{
			PlotText( "0", i - swing0[i], L[i-swing0[i]] * 0.999, colorWhite );
		}

		if ( !IsNull(swing3[i]) AND !IsNull(H[i-swing3[i]]) ) 
		{
			PlotText( "3", i - swing3[i], H[i-swing3[i]] * 1.001, colorWhite );
		}
		
		if ( !IsNull(swing2[i]) AND !IsNull(L[i-swing2[i]]) ) 
		{
			PlotText( "2", i - swing2[i], L[i-swing2[i]] * 0.999, colorWhite );
		}
		
		if ( !IsNull(swing1[i]) AND !IsNull(H[i-swing1[i]]) ) 
		{
			PlotText( "1", i - swing1[i], H[i-swing1[i]] * 1.001, colorWhite );
		}
    }
  

}

Filter = inPattern;
AddColumn (inPattern, "inPattern");
AddColumn (isBullish, "isBullish");



Any help would be greatly appreciated! Thanks so much in advance.

For Analysis - Exploration, what are the settings you have used?
ie. AFL alone is not sufficient.
Check & share Filter/ Periodicity / Date range etc details as it would be complete, or better would be to share an APX file.

1 Like

@arcee, to better understand what your code is doing, I suggest to comment out your _TRACE() line and then change the following code to:

dt = DateTime();
for( i = 0; i < BarCount; i++ )
{
    if( inPattern[i] )
    {
		_TRACEF("inPattern at %s", DateTimeToStr(dt[i], 3));

        // Check if swing0, swing3, and bsSwing1 are valid before plotting

Thanks for the reply. Here's the APX file for your reference

Also here are the analysis settings

Hope this one helps

Thanks as always @beppe I followed your instructions can you guide me if Im doing this correctly?

so for this part of the code this is what I did after commenting out the _TRACE()

dt = DateTime();

//This is the code to label points 0-1-2-3
for( i = 0; i < BarCount; i++ )
{

    if( inPattern[i])
		{
		_TRACEF("inPattern at %s", DateTimeToStr(dt[i], 3));
		// Check if swing0, swing3, and bsSwing1 are valid before plotting
		if ( !IsNull(swing0[i]) AND !IsNull(L[i-swing0[i]]) ) 
		{
			PlotText( "0", i - swing0[i], L[i-swing0[i]] * 0.999, colorWhite );
		}

		if ( !IsNull(swing3[i]) AND !IsNull(H[i-swing3[i]]) ) 
		{
			PlotText( "3", i - swing3[i], H[i-swing3[i]] * 1.001, colorWhite );
		}
		
		if ( !IsNull(swing2[i]) AND !IsNull(L[i-swing2[i]]) ) 
		{
			PlotText( "2", i - swing2[i], L[i-swing2[i]] * 0.999, colorWhite );
		}
		
		if ( !IsNull(swing1[i]) AND !IsNull(H[i-swing1[i]]) ) 
		{
			PlotText( "1", i - swing1[i], H[i-swing1[i]] * 1.001, colorWhite );
		}
    }
  

}

The log window confirms that these date indeed are inPattern for this particular dates

at the same time the Pattern appears in the chart as shown by the swing points ( 0,1,2,3)
which would not appear if inPattern is 0;

All seems to confirm inPattern == 1; but I can't seem to figure out why exploration cannot display the result

The AFX you sent me has Periodicity set to Daily. Your screenshot has Daily.
You are using TimeStop = 103000; in inPattern which is intraday timeframe.

You can start fixing from there.
image

3 Likes

Follow the advice of @nsm51.

I too suspect your are not using the correct periodicity in the Analysis dialog:

3 Likes

Thanks for the help @nsm51 and @beppe my database settings was inadvertently set to end-of-day which was preventing me from setting my analysis settings to lower timeframes. I then was able to set my periodicity to 1 minute. :pray: :pray:

1 Like