Plot shape in Daily Timeframe if Condition occured in1Minute

Hello Everyone!

I have this code that determines at 11:00 mark if a pattern exists.
Once it returns true it plots a shape to mark that the pattern happened.
However this is only plotted in the 1minute timeframe.
I'm trying to find a way to also plot the shape in a daily timeframe. So basically if the pattern exists intraday the shape will also be plotted in the daily candle.

So far here's my best attempt for that

//Need you Help for this Part :)

// Set the time frame to 1-minute
TimeFrameSet(in1Minute);

// Calculate the condition in 1-minute time frame
BSTS = BarsSince(tm == TimeStop); // bars since TS (timestop 11:00 mark)
inPattern_eod_1min = Ref(inPattern, -BSTS) == 1 AND !isPreMarket;

// Restore the original time frame
TimeFrameRestore();

// Expand the condition to the daily time frame
TimeFrameSet(inDaily);
inPattern_eod_daily = TimeFrameExpand(inPattern_eod_1min, in1Minute, expandLast);

// Restore the original time frame
TimeFrameRestore();

// Output the result
_TRACE("inPattern_eod=" + inPattern_eod_daily);


// Plot the shape at the daily timeframe
shape_inPattern_eod_daily = IIf(inPattern_eod_daily, shapeHollowDownArrow + shapePositionAbove, shapeNone);
PlotShapes(shape_inPattern_eod_daily, colorBlue, 0, Low);

// Output the result
_TRACE("inPattern_eod_daily=" + inPattern_eod_daily);

Hope you can help me out. Thank you in advance.

Here's the full code if you need rereference:

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

//SESSION BREAKS 
PMstart = Ref(tm,-1) > tm;
PMStartTime = ValueWhen(PMstart,tm);;  	//premarket time start
PMEndtime = 093000;		//premarket time end
AHStartTime  = 160000;// afterhours time start
AHEndtime = 200000;  // afterhours time end
TimeStop = 110000;

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);
Plot(Plot_PMH,"PM High", colorblue, style = styleDashed,minvalue=0, maxvalue=0, XShift=0,Zorder=0,width=1);

PM_Low = ValueWhen(isPreMarket, LowestSince(tm == PMStartTime, L));
Plot_PML = IIf(isPremarket OR isAfterHours, Null,PM_Low);
Plot(Plot_PML,"PM Low", colorblue, style = styleDashed,minvalue=0, maxvalue=0, XShift=0,Zorder=0,width=1);

//FORMULA
bsmo = BarsSince(PMend); //bars since market open
premarket_end = Ref(tm, 1)==093000;


leg_0_low = IIf(tm==TimeStop, LLV(L, bsmo),Null);
leg_0 = LLVBars(L, premarket_end);

//PCH after leg 0
pch_0_ref = LLVBars(H, Ref(leg_0,0));
pch_ref_0_High = IIf(tm==TimeStop, Ref( H, -pch_0_ref), Null);
pch_0 = Cross(C, Ref(H, -pch_0_ref));
pch_0 = ExRem(pch_0, leg_0==0);
bspch_0 = BarsSince(pch_0); // bars since pch_0

//mshape_pch_0 = IIf(pch_0, shapeHollowDownArrow + shapePositionAbove,shapeNone);
//PlotShapes(mshape_pch_0,colorblue, 0,L);


leg_2 = LLVBars(L, Ref(bspch_0,-1));
leg_2_low = IIf(tm==TimeStop, Ref( L, -leg_2), Null);


barDiff = bspch_0 - leg_2;

leg_1_High = IIf(tm==TimeStop,Ref(H, -(ValueWhen(leg_2==0, HHVBars(H, barDiff))+leg_2)) ,Null);
leg_1 = ValueWhen(leg_2==0, HHVBars(H, barDiff))+leg_2;


//PCH after leg 2
pch_2_ref = LLVBars(H, Ref(leg_2,0));
pch_ref_2_High = IIf(tm==TimeStop, Ref( H, -pch_2_ref), Null);
pch_2 = Cross(C, Ref(H, -pch_2_ref));
pch_2 = ExRem(pch_2, leg_2==0);
bspch_2 = BarsSince(pch_2); // bars since pch_0


//Break of Leg 1
leg_1_Break = Cross(C, Ref(H, -leg_1));
leg_1_Break = ExRem(leg_1_Break, leg_2==0);
bs_leg_1_Break = BarsSince(leg_1_Break); // bars since leg 1 break



leg_4 = LLVBars(L, bs_leg_1_Break);
leg_4_low = IIf(tm==TimeStop, Ref( L, -leg_4), Null);
barDiff2 = bs_leg_1_Break - leg_4;

leg_3_High = IIf(tm==TimeStop,Ref(H, -(ValueWhen(leg_4==0, HHVBars(H, barDiff2))+leg_4)) ,Null);
leg_3 = ValueWhen(leg_4==0, HHVBars(H, barDiff2))+leg_4;

//Break of Leg 1
leg_3_Break = Cross(C, Ref(H, -leg_3));
leg_3_Break = ExRem(leg_3_Break, leg_4==0);
bs_leg_3_Break = BarsSince(leg_3_Break); // bars since leg 3 break

leg_5_high = IIf(tm==TimeStop, HHV(H, bs_leg_3_Break),Null);
leg_5 = HHVBars(H, bs_leg_3_Break);


inSequence = leg_1 >= leg_2 AND 
			 leg_2 >= leg_3 AND
			 leg_3 >= leg_4 AND
			 leg_4 >= leg_5;


inPattern = tm == Timestop AND 
			inSequence;	


//SWING LABLES

for( i = 0; i < BarCount; i++ )
{

    if( inPattern[i] )
    {
		PlotText( "0" , i - Leg_0[i], L[i-leg_0[i]]*0.999, colorWhite);
		PlotText( "1" , i - leg_1[i], H[i-leg_1[i]]*1.0003, colorWhite);
		PlotText( "2" , i - Leg_2[i], L[i-leg_2[i]]*0.999, colorWhite);
		PlotText( "3" , i - leg_3[i], H[i-leg_3[i]]*1.0003, colorWhite);
		PlotText( "4" , i - Leg_4[i], L[i-leg_4[i]]*0.999, colorWhite);
		PlotText( "5" , i - leg_5[i], H[i-leg_5[i]]*1.0003, colorWhite);
		
        
    }
}



// Set the time frame to 1-minute
TimeFrameSet(in1Minute);

// Calculate the condition in 1-minute time frame
BSTS = BarsSince(tm == TimeStop); // bars since TS
inPattern_eod_1min = Ref(inPattern, -BSTS) == 1 AND !isPreMarket;

// Restore the original time frame
TimeFrameRestore();

// Expand the condition to the daily time frame
TimeFrameSet(inDaily);
inPattern_eod_daily = TimeFrameExpand(inPattern_eod_1min, in1Minute, expandLast);

// Restore the original time frame
TimeFrameRestore();

// Output the result
_TRACE("inPattern_eod=" + inPattern_eod_daily);


// Plot the shape at the daily timeframe
shape_inPattern_eod_daily = IIf(inPattern_eod_daily, shapeHollowDownArrow + shapePositionAbove, shapeNone);
PlotShapes(shape_inPattern_eod_daily, colorBlue, 0, Low);

// Output the result
_TRACE("inPattern_eod_daily=" + inPattern_eod_daily);

Hi
a similar question, have a look at below link

1 Like

Thank you so much @PanoS . :saluting_face:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.