shared_CumulativeTick:
shared_HorizontalTreshold_study:
Entire chart setup (as shown in screenshot)
https://tos.mx/3dD2VrT
Code:
#Ctick by @Dalebru 10/24/2015
#Cumulative tick.
#https://futures.io/thinkorswim/41392-cumulative-tick-script-2.html
#Can reset to start at beginning of Day, Week, Month, Year, Chart
#Thanks to futures.io @rmejia for similar code in VWAP_Bands
# interesting code fore rolling periods
#skynetgen: coloration and explicit signals
declare lower;
input TimeFrame = {default Day, Week, Month, Year, Chart};
input symbol = "$TICK";
def isInvalid = IsNan(hlc3(symbol));
def price = if (isInvalid, 0, hlc3(symbol));
def cap = GetAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.Day and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.Week and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
def yyyyMmDd = GetYYYYMMDD();
def year = GetYear();
def periodIndx;
switch (timeFrame)
{
case Chart:
periodIndx = 0;
case Day:
periodIndx = yyyyMmDd;
case Week:
periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case Month:
periodIndx = roundDown(yyyyMmDd / 100, 0);
case Year:
periodIndx = Floor(year - First(year));
}
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);
def cum;
if (isPeriodRolled)
{
cum = price;
}
else
{
cum = cum[1] + price;
}
plot CumTick = if isInvalid then Double.NaN else cum;
CumTick.SetPaintingStrategy(PaintingStrategy.Line);
#CumTick.SetLineWeight(3);
CumTick.DefineColor("PosAndUp", Color.Green);
CumTick.DefineColor("PosAndDn", Color.Orange);
CumTick.DefineColor("NegAndDn", Color.Red);
CumTick.DefineColor("NegAndUP", Color.orange);
CumTick.AssignValueColor(
if Cumtick>0 then
( if cumtick>cumtick[1] then CumTick.color("PosAndUp") else CumTick.color("PosAndDN"))
else
( if cumtick>cumtick[1] then CumTick.color("NegAndUp") else CumTick.color("NegAndDN")));
#CumTick.SetHiding(isInvalid);
plot zero = 0;
zero.AssignValueColor(GetColor(3)); zero.hidetitle();
plot avgtick=average(cumtick,3);
plot xup=if avgtick crosses above 0 then 0 else double.nan;
plot xdn=if avgtick crosses below 0 then 0 else double.nan;
xup.setpaintingStrategy(paintingStrategy.ARROW_UP);xup.hideTitle();
xdn.setpaintingStrategy(paintingStrategy.ARROW_DowN);xdn.hideTitle();
shared_HorizontalTreshold_study:
Code:
#for identicating close above/below horizontal threshold (like on $tick or $ADD)
input threshold=400;
input location=1000;
input price=close;
def above= price > threshold;
def below= price< -threshold;
plot pabove=if above then location else double.nan;
pabove.setPaintingStrategy(paintingStrategy.TRIANGLES); pabove.setdefaultcolor(color.green);
pabove.setLineWeight(5);
plot pbelow=if below then -location else double.nan;
pbelow.setPaintingStrategy(paintingStrategy.TRIANGLES); pbelow.setdefaultcolor(color.red);
pbelow.setLineWeight(5);
addcloud(threshold,-threshold,color.gray, color.gray);

Entire chart setup (as shown in screenshot)
https://tos.mx/3dD2VrT
Last edited by a moderator: