Condition to get rid of continuing lines when Day, Week, Month changes

Sorry if this question is too basic and/or already answered but I am unable to figure it out. On Daily charts after a bit of search I found a way but not on other time-frames.

Plot( C, "", colorDefault, styleCandle );

MrktOpen = 093059;
MrktClose = 163059;
DayCond = TimeNum() >= MrktOpen AND TimeNum() <= MrktClose;
//WkCond = ?
//MnthCond = ?
//YrCond = ?

Filter = 1;
ch = ParamList( "Choose Timeframe", "Daily|Weekly|Monthly|Yearly", 0 );
switch( ch )
{
	 case "Daily":
		 prevDayH = TimeFrameGetPrice( "H", inDaily, -1, expandfirst );
		 prevDayL = TimeFrameGetPrice( "L", inDaily, -1, expandfirst );
		 prevDayC = TimeFrameGetPrice( "C", inDaily, -1, expandfirst );
		 DayPvt = ( prevDayH + prevDayL + prevDayC ) / 3;
		 Plot( IIf( DayCond, DayPvt, Null ), "DayPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 AddColumn( DayPvt, "DayPvt", 1.2 );
	 break;
	 case "Weekly":
		 prevWkH = TimeFrameGetPrice( "H", inWeekly, -1, expandfirst );
		 prevWkL = TimeFrameGetPrice( "L", inWeekly, -1, expandfirst );
		 prevWkC = TimeFrameGetPrice( "C", inWeekly, -1, expandfirst );
		 WkPvt = ( prevWkH + prevWkL + prevWkC ) / 3;
		 //Plot( IIf( WkCond, WkPvt, Null ), "WkPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 Plot( WkPvt, "WkPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 AddColumn( WkPvt, "WkPvt", 1.2 );
	 break;
	 case "Monthly":
		 prevMnthH = TimeFrameGetPrice( "H", inMonthly, -1, expandfirst );
		 prevMnthL = TimeFrameGetPrice( "L", inMonthly, -1, expandfirst );
		 prevMnthC = TimeFrameGetPrice( "C", inMonthly, -1, expandfirst );
		 MnthPvt = ( prevMnthH + prevMnthL + prevMnthC ) / 3;
		 //Plot( IIf( MnthCond, MnthPvt, Null ), "MnthPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 Plot( MnthPvt, "MnthPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 AddColumn( MnthPvt, "MnthPvt", 1.2 );
	 break;
	 case "Yearly":
		 prevYrH = TimeFrameGetPrice( "H", inYearly, -1, expandfirst );
		 prevYrL = TimeFrameGetPrice( "L", inYearly, -1, expandfirst );
		 prevYrC = TimeFrameGetPrice( "C", inYearly, -1, expandfirst );
		 YrPvt = ( prevYrH + prevYrL + prevYrC ) / 3;
		 //Plot( IIf( YrCond, YrPvt, Null ), "YrPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 Plot( YrPvt, "YrPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 AddColumn( YrPvt, "YrPvt", 1.2 );
	 break;
}

1

2

This is the best that I can think of. Any other simpler solution are most welcome.

Plot( C, "", colorDefault, styleCandle );

dtDayStartComp = TimeFrameCompress( DateTime(), inDaily, compressOpen );
dtDayStartExp = TimeFrameExpand( dtDayStartComp, inDaily, expandFirst );
dtDayEndComp = TimeFrameCompress( DateTime(), inDaily, compressLast );
dtDayEndExp = TimeFrameExpand( dtDayEndComp, inDaily, expandFirst );
DayCond = DateTime() >= dtDayStartExp AND DateTime() < dtDayEndExp;

dtWkStartComp = TimeFrameCompress( DateTime(), inWeekly, compressOpen );
dtWkStartExp = TimeFrameExpand( dtWkStartComp, inWeekly, expandFirst );
dtWkEndComp = TimeFrameCompress( DateTime(), inWeekly, compressLast );
dtWkEndExp = TimeFrameExpand( dtWkEndComp, inWeekly, expandFirst );
WkCond = DateTime() >= dtWkStartExp AND DateTime() < dtWkEndExp;

dtMnthStartComp = TimeFrameCompress( DateTime(), inMonthly, compressOpen );
dtMnthStartExp = TimeFrameExpand( dtMnthStartComp, inMonthly, expandFirst );
dtMnthEndComp = TimeFrameCompress( DateTime(), inMonthly, compressLast );
dtMnthEndExp = TimeFrameExpand( dtMnthEndComp, inMonthly, expandFirst );
MnthCond = DateTime() >= dtMnthStartExp AND DateTime() < dtMnthEndExp;

dtYrStartComp = TimeFrameCompress( DateTime(), inYearly, compressOpen );
dtYrStartExp = TimeFrameExpand( dtYrStartComp, inYearly, expandFirst );
dtYrEndComp = TimeFrameCompress( DateTime(), inYearly, compressLast );
dtYrEndExp = TimeFrameExpand( dtYrEndComp, inYearly, expandFirst );
YrCond = DateTime() >= dtYrStartExp AND DateTime() < dtYrEndExp;

Filter = 1;
ch = ParamList( "Choose Timeframe", "Daily|Weekly|Monthly|Yearly", 0 );
switch( ch )
{
	 case "Daily":
		 prevDayH = TimeFrameGetPrice( "H", inDaily, -1, expandfirst );
		 prevDayL = TimeFrameGetPrice( "L", inDaily, -1, expandfirst );
		 prevDayC = TimeFrameGetPrice( "C", inDaily, -1, expandfirst );
		 DayPvt = ( prevDayH + prevDayL + prevDayC ) / 3;
		 Plot( IIf( DayCond, DayPvt, Null ), "DayPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 AddColumn( DayPvt, "DayPvt", 1.2 );
	 break;
	 case "Weekly":
		 prevWkH = TimeFrameGetPrice( "H", inWeekly, -1, expandfirst );
		 prevWkL = TimeFrameGetPrice( "L", inWeekly, -1, expandfirst );
		 prevWkC = TimeFrameGetPrice( "C", inWeekly, -1, expandfirst );
		 WkPvt = ( prevWkH + prevWkL + prevWkC ) / 3;
		 Plot( IIf( WkCond, WkPvt, Null ), "WkPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 //Plot( WkPvt, "WkPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 AddColumn( WkPvt, "WkPvt", 1.2 );
	 break;
	 case "Monthly":
		 prevMnthH = TimeFrameGetPrice( "H", inMonthly, -1, expandfirst );
		 prevMnthL = TimeFrameGetPrice( "L", inMonthly, -1, expandfirst );
		 prevMnthC = TimeFrameGetPrice( "C", inMonthly, -1, expandfirst );
		 MnthPvt = ( prevMnthH + prevMnthL + prevMnthC ) / 3;
		 Plot( IIf( MnthCond, MnthPvt, Null ), "MnthPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 AddColumn( MnthPvt, "MnthPvt", 1.2 );
	 break;
	 case "Yearly":
		 prevYrH = TimeFrameGetPrice( "H", inYearly, -1, expandfirst );
		 prevYrL = TimeFrameGetPrice( "L", inYearly, -1, expandfirst );
		 prevYrC = TimeFrameGetPrice( "C", inYearly, -1, expandfirst );
		 YrPvt = ( prevYrH + prevYrL + prevYrC ) / 3;
		 Plot( IIf( YrCond, YrPvt, Null ), "YrPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 AddColumn( YrPvt, "YrPvt", 1.2 );
	 break;
}

Thank you

Hi

can this table help you?

// Example 1. get previous week Open price 
TimeFrameGetPrice( "O", inWeekly, -1 ) 

// Example 2. get weekly Close price 3 weeks ago 
TimeFrameGetPrice( "C", inWeekly, -3 ) 

// Example 3. get weekly High price 2 weeks ago 
TimeFrameGetPrice( "H", inWeekly, -2 ) 

// Example 4. get this week Open price. 
TimeFrameGetPrice( "O", inWeekly, 0 ) 

// Example 5. get previous Day High when working on intraday data 
TimeFrameGetPrice( "H", inDaily, -1 ) 

https://www.amibroker.com/guide/afl/timeframeset.html

form the Users Guide

interval defines time frame interval in seconds. So 60 means 1-minute. For the convenience the following interval constants are pre-defined:

  • in1Minute = 60
  • in5Minute = 5 * 60
  • in15Minute = 15 * 60
  • inHourly = 3600
  • inDaily = 24 * 3600
  • inWeekly = 5 * 24 * 3600 + 1 = 432001
  • inMonthly = 25 * 24 * 3600 + 1 = 2160001
  • inQuarterly (new in 5.20)* inYearly (new in 5.20)

To get other intervals you can use multiple of pre-defined intervals, for example: ( 3*in1Minute ) gives 3 minute bars. Or you can use 3 * inDaily for 3-day bars.

@cougar if you truly don't like the visual "empty" space at the end of each period you can plot again the same array shifted to the right

		 Plot( IIf( MnthCond, MnthPvt, Null ), "MnthPvt", colorWhite, styleLine | styleNoRescale, Null, Null, 0, 0, 1 );
		 Plot( IIf( MnthCond, MnthPvt, Null ), "MnthPvt", colorYellow, styleLine | styleNoRescale, Null, Null, 2, 0, 1 ); // fill the "empty" space - used a different color to distinguish where it is plotted
1 Like

@Cougar Maybe not necessarily in this case, but in general I suggest using styleStaircase instead of styleLine (to avoid those skew lines) for similar Plots ...

2 Likes

@beppe you are always steps ahead of me, may be miles. Lol :slight_smile:

1 Like