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 showsinPattern = 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:
- Code Logic: The rest of the code works as expected, and the conditions appear correct based on the Trace Log.
- 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.