Opening range plotting

Hi All,

I am plotting daily range and I want to plot it with the logic as below:

  1. If its upside then range should be when first lowest high is created.
  2. If its downside then range should be when first highest low is created.

Below is my code :

newday = Day() != Ref(Day(),-1);  //check if new day or not
FCO=ValueWhen(Day()!=Ref(Day(),-1),O); // Day first candle Open

ORBCandle = (H < HHV(H,newday) AND O > FCO) OR (L < LLV(L,newday) AND O > FCO);


ORBHIGH = ValueWhen(ORBCandle,HHV(H,newday));
ORBLOW = ValueWhen(ORBCandle,LLV(L,newday));

Plot(ORBHIGH,"ORBHigh",colorGreen,styleDots);
Plot(ORBLOW,"ORBLow",colorRed,styleDots);

The problem is that, I want to stop it once my first range is created but code keeps plotting it whenever condition is completed.

Example for lowerside range

Request your help to complete the code.

Thank you in advance.

Regards,
Mahesh

Add

ORBCandle = Sum(ORBCandle, BarsSince(newday)+1)==1;

Btw, this one

HHV(H,newday)

and this one

LLV(L,newday)

do not make sense (because second argument of those functions expect period but newday is true/false array)

Rather should be HighestSince and LowestSince.

So,

newday = Day() != Ref(Day(),-1);  //check if new day or not
FCO=ValueWhen(newday,O); // Day first candle Open

hh = HighestSince(newday,H);
ll = LowestSince(newday,L);
ORBCandle = (H < hh AND O > FCO) OR (L < ll AND O > FCO);
ORBCandle = Sum(ORBCandle, BarsSince(newday)+1)==1;

ORBHIGH = ValueWhen(ORBCandle,hh);
ORBLOW = ValueWhen(ORBCandle,ll);

Plot(ORBHIGH,"ORBHigh",colorGreen,styleDots);
Plot(ORBLOW,"ORBLow",colorRed,styleDots);

As for plot... alternatively you could use these lines to stop the Plot too.

Plot(IIf(ORBCandle, ORBHIGH, Null),"ORBHigh",colorGreen,styleDots);
Plot(IIf(ORBCandle, ORBLOW, Null),"ORBLow",colorRed,styleDots);
1 Like

Dear fxshrat,

Thank you so much for your efforts and it helped to correct some parameters but there are some issues still open and I am attaching my corrected code again with screenshots of wrong plotting.

I tried multiple options but not able to get through it.

newday = Day() != Ref(Day(),-1);  //check if new day or not
FCL=ValueWhen(newday,L); // Day first candle Open
FCH=ValueWhen(newday,H); // Day first candle high

hh = HighestSince(newday,H);
ll = LowestSince(newday,L);
ORBCandle = (H < hh AND L > FCL) OR (L > ll AND H < FCH);

ORBCandle = Sum(ORBCandle, BarsSince(newday)+1)==1;

ORBHIGH = ValueWhen(ORBCandle,hh);
ORBLOW = ValueWhen(ORBCandle,ll);

Stock1 Stock2 Stock3

Thank you.

Regards,
Mahesh

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