def errorInAggregation =
timeFrame == timeFrame.YEAR and !(cap == AggregationPeriod.MONTH or cap == AggregationPeriod.DAY) or
timeFrame == timeFrame.YEAR and cap == AggregationPeriod.DAY and BarNumber() < 510 or
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH or
timeFrame == timeFrame."OPT EXP" and cap >= AggregationPeriod.OPT_EXP;

def cBar = if IsNaN(close) then 0 else BarNumber();
def LastBar = HighestAll(cBar);
def isExtention = BarNumber() > LastBar;

def C_ ;
def H_ ;
def L_ ;

if isExtention
then {

C_ = C_[1];
H_ = H_[1];
L_ = L_[1];
} else

if timeFrame == timeFrame."YEAR"
then {

C_ = if IsNewYear then close[1] else C_[1];
H_ = if IsNewYear then high else Max(H_[1], high);
L_ = if IsNewYear then low else Min(L_[1], low);
}
else {

C_ = if BarNumber() <= 1 then open else close(period = timeFrame)[1];
H_ = if BarNumber() <= 1 then open else high(period = timeFrame)[1];
L_ = if BarNumber() <= 1 then open else low(period = timeFrame)[1];
}

def C ;
def H ;
def L ;

if timeFrame == timeFrame."YEAR"
then {

C = if IsNewYear then C_ else C[1];
H = if IsNewYear then H_[1] else H[1];
L = if IsNewYear then L_[1] else L[1];
}
else {

C = C_;
H = H_;
L = L_;
}

plot Cl;
plot Hi;
plot Lw;
if (showOnlyLast and !isExtention)
then {

## Question

## Mark 44

Hey guys, just wondering if we could have a previous Month/Year H/L/C indicator built.

I have enclosed my TOS script to give you an idea of what I had in mind.

Thanks

declare once_per_bar;

declare upper;

declare real_size;

input Pivots = {"Shadows", default "Normal"};

input showOnlyLast = no;

input ShowCloud = yes;

input showBubble = yes;

input ShiftBubble = 5;

def n1 = ShiftBubble + 1;

input timeFrame = { "DAY", "WEEK", "MONTH", "OPT EXP", default "YEAR"};

def cap = GetAggregationPeriod();

def errorInAggregation =

timeFrame == timeFrame.YEAR and !(cap == AggregationPeriod.MONTH or cap == AggregationPeriod.DAY) or

timeFrame == timeFrame.YEAR and cap == AggregationPeriod.DAY and BarNumber() < 510 or

timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or

timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH or

timeFrame == timeFrame."OPT EXP" and cap >= AggregationPeriod.OPT_EXP;

AddLabel( errorInAggregation, "Agregation Error", Color.RED);

def IsNewYear = GetYear() != GetYear()[1];

#def IsNewFrame = GetYYYYMMDD(period = timeFrame);

def cBar = if IsNaN(close) then 0 else BarNumber();

def LastBar = HighestAll(cBar);

def isExtention = BarNumber() > LastBar;

def C_ ;

def H_ ;

def L_ ;

if isExtention

then {

C_ = C_[1];

H_ = H_[1];

L_ = L_[1];

} else

if timeFrame == timeFrame."YEAR"

then {

C_ = if IsNewYear then close[1] else C_[1];

H_ = if IsNewYear then high else Max(H_[1], high);

L_ = if IsNewYear then low else Min(L_[1], low);

}

else {

C_ = if BarNumber() <= 1 then open else close(period = timeFrame)[1];

H_ = if BarNumber() <= 1 then open else high(period = timeFrame)[1];

L_ = if BarNumber() <= 1 then open else low(period = timeFrame)[1];

}

def C ;

def H ;

def L ;

if timeFrame == timeFrame."YEAR"

then {

C = if IsNewYear then C_ else C[1];

H = if IsNewYear then H_[1] else H[1];

L = if IsNewYear then L_[1] else L[1];

}

else {

C = C_;

H = H_;

L = L_;

}

plot Cl;

plot Hi;

plot Lw;

if (showOnlyLast and !isExtention)

then {

Cl = Double.NaN;

Hi = Double.NaN;

Lw = Double.NaN;

}

else {

Cl = C;

Hi = H;

Lw = L;

}

Cl.SetDefaultColor(Color.gray);

Hi.SetDefaultColor(Color.gray);

Lw.SetDefaultColor(Color.gray);

Cl.SetLineWeight(1);

Cl.SetStyle(Curve.SHORT_DASH);

Hi.SetLineWeight(1);

Hi.SetStyle(Curve.SHORT_DASH);

Lw.SetLineWeight(1);

Lw.SetStyle(Curve.SHORT_DASH);

def cond = showBubble and IsNaN(close[ShiftBubble]) and !IsNaN(close[n1]) ;

AddChartBubble(cond, Cl, Concat("m cl: ", Round(Cl)), Color.white);

AddChartBubble(cond, Hi, Concat("m hi: ", Round(Hi)), Color.white);

AddChartBubble(cond, Lw, Concat("m lo: ", Round(Lw)), Color.white);

Cl.HideBubble();

Hi.HideBubble();

Lw.HideBubble();

Edited by SPT## Link to comment

## Share on other sites

## 9 answers to this question

## Recommended Posts

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.