Marking Previous Week's OHLC

// Current Week only
WeekNow = Week() == LastValue(Week()) AND Year() == LastValue(Year());

Getting an error in the above line of the following code. I want to plot last OHLC lines on current week's chart only. Not in previous weekly charts. Same working for Daily and Monthly Charts but in weekly it shows an error 30, 70 and 1. Anybody help please.

_SECTION_BEGIN("Prior Week OHLC");

PWH_Color = ParamColor("PWH Color", colorRed);
PWH_Style = ParamStyle("PWH Style", styleThick | styleNoRescale);

PWL_Color = ParamColor("PWL Color", colorGreen);
PWL_Style = ParamStyle("PWL Style", styleThick | styleNoRescale);

CWO_Color = ParamColor("CWO Color", colorBlack);
CWO_Style = ParamStyle("CWO Style", styleThick | styleNoRescale);

PWC_Color = ParamColor("PWC Color", colorBlue);
PWC_Style = ParamStyle("PWC Style", styleThick | styleNoRescale);

// Get Weekly values
PWH_raw = TimeFrameGetPrice("H", inWeekly, -1);
PWL_raw = TimeFrameGetPrice("L", inWeekly, -1);
CWO_raw = TimeFrameGetPrice("O", inWeekly, 0);
PWC_raw = TimeFrameGetPrice("C", inWeekly, -1);

// Current Week only
WeekNow = Week() == LastValue(Week()) AND Year() == LastValue(Year());

PWH = IIf(WeekNow, PWH_raw, Null);
PWL = IIf(WeekNow, PWL_raw, Null);
CWO = IIf(WeekNow, CWO_raw, Null);
PWC = IIf(WeekNow, PWC_raw, Null);

xPos = BarCount + 4;

Plot(PWH, "PWH", PWH_Color, PWH_Style);
Plot(PWL, "PWL", PWL_Color, PWL_Style);
Plot(CWO, "CWO", CWO_Color, CWO_Style);
Plot(PWC, "PWC", PWC_Color, PWC_Style);

// Only show text if valid value exists
if (!IsNull(LastValue(PWH)))
    PlotText("Previous Week High", xPos, LastValue(PWH), PWH_Color);
if (!IsNull(LastValue(PWL)))
    PlotText("Previous Week Low", xPos, LastValue(PWL), PWL_Color);
if (!IsNull(LastValue(CWO)))
    PlotText("Current Week Open", xPos, LastValue(CWO), CWO_Color);
if (!IsNull(LastValue(PWC)))
    PlotText("Previous Week Close", xPos, LastValue(PWC), PWC_Color);

_SECTION_END();

LastValue is never Null as per documentation

If last bar of the ARRAY is undefined or Null (e.g., only 100-days loaded and you request the last value of a 200-day moving average) then the lastvalue function returns zero.

It's working for Monthly and Daily, but weekly I don't understand what's wrong.

_SECTION_BEGIN("Prior Month OHLC");

PMH_Color = ParamColor("PMH Color", colorRed);
PMH_Style = ParamStyle("PMH Style", styleThick | styleNoRescale);

PML_Color = ParamColor("PML Color", colorGreen);
PML_Style = ParamStyle("PML Style", styleThick | styleNoRescale);

CMO_Color = ParamColor("CMO Color", colorBlack);
CMO_Style = ParamStyle("CMO Style", styleThick | styleNoRescale);

PMC_Color = ParamColor("PMC Color", colorBlue);
PMC_Style = ParamStyle("PMC Style", styleThick | styleNoRescale);

// Get monthly values
PMH_raw = TimeFrameGetPrice("H", inMonthly, -1);
PML_raw = TimeFrameGetPrice("L", inMonthly, -1);
CMO_raw = TimeFrameGetPrice("O", inMonthly, 0);
PMC_raw = TimeFrameGetPrice("C", inMonthly, -1);

// Current month only
monthNow = Month() == LastValue(Month()) AND Year() == LastValue(Year());

PMH = IIf(monthNow, PMH_raw, Null);
PML = IIf(monthNow, PML_raw, Null);
CMO = IIf(monthNow, CMO_raw, Null);
PMC = IIf(monthNow, PMC_raw, Null);

xPos = BarCount + 4;

Plot(PMH, "PMH", PMH_Color, PMH_Style);
Plot(PML, "PML", PML_Color, PML_Style);
Plot(CMO, "CMO", CMO_Color, CMO_Style);
Plot(PMC, "PMC", PMC_Color, PMC_Style);

// Only show text if valid value exists
if (!IsNull(LastValue(PMH)))
    PlotText("Previous Month High", xPos, LastValue(PMH), PMH_Color);
if (!IsNull(LastValue(PML)))
    PlotText("Previous Month Low", xPos, LastValue(PML), PML_Color);
if (!IsNull(LastValue(CMO)))
    PlotText("Current Month Open", xPos, LastValue(CMO), CMO_Color);
if (!IsNull(LastValue(PMC)))
    PlotText("Previous Month Close", xPos, LastValue(PMC), PMC_Color);

_SECTION_END();


@midhunms , try to change the way you set the weekNow variable:

// Current Week only
dow = DayOfWeek();
newWeek = dow < Ref( dow, -1 );
week = Cum( newWeek );
weekNow = week == LastValue( Week );
1 Like