ChatGPT, BARD, Other AI Scripts Which Can't Be Used In ThinkOrSwim

MerryDay

Administrative
Staff member
Staff
VIP
Lifetime
90% of the members attempting chatGPT scripting; do not provide good detailed specifications.

Members know what end result that they want but lack the ability to tell chatGPT, the step-by-step logic required to code a script to achieve that end result.
This results in chatGPT creating non-working garbage code.

Here is a video on how to successfully have chatGPT create functional scripts.

The above video, explains the basics of providing good specifications to AI which results in better scripts.
AOzhl05.png
 
Last edited:
How can I include coloring candles to this version ?
Code:
# Cumulative Volume Delta
# This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# © Ankit_1618 converted by Zlotko

declare upper;

# Calculate upper_wick, lower_wick, spread, and body_length
def upper_wick = if close > open then high - close else high - open;
def lower_wick = if close > open then open - low else close - low;
def spread = high - low;
def body_length = spread - (upper_wick + lower_wick);

# Calculate percent_upper_wick, percent_lower_wick, and percent_body_length
def percent_upper_wick = upper_wick / spread;
def percent_lower_wick = lower_wick / spread;
def percent_body_length = body_length / spread;

# Calculate buying_volume and selling_volume
def buying_volume = if close > open then (percent_body_length + (percent_upper_wick + percent_lower_wick) / 2) * volume else ((percent_upper_wick + percent_lower_wick) / 2) * volume;
def selling_volume = if close < open then (percent_body_length + (percent_upper_wick + percent_lower_wick) / 2) * volume else ((percent_upper_wick + percent_lower_wick) / 2) * volume;

# Input for cumulation_length
input cumulation_length = 14;

# Calculate cumulative_buying_volume and cumulative_selling_volume using EMA
def cumulative_buying_volume = ExpAverage(buying_volume, cumulation_length);
def cumulative_selling_volume = ExpAverage(selling_volume, cumulation_length);

# Calculate cumulative_volume_delta
def cumulative_volume_delta = cumulative_buying_volume - cumulative_selling_volume;

# Plot histograms to represent cumulative volume delta
plot hist = cumulative_volume_delta;
hist.AssignValueColor(if cumulative_volume_delta > 0 then color.green else color.red);
hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.SetLineWeight(1);
hist.SetDefaultColor(GetColor(1));
hist.SetStyle(Curve.FIRM);

# Calculate volume_strength_wave and plot its EMA
def volume_strength_wave = if cumulative_buying_volume > cumulative_selling_volume then cumulative_buying_volume else cumulative_selling_volume;
def ema_volume_strength_wave = ExpAverage(volume_strength_wave, cumulation_length);
#plot ema_volume_strength_wave(color = color.gray, transp = 80);
# 50%Line.SetDefaultColor(Color.GRAY);

#----Div-----------
input LookBackRight = 5; # "Pivot Lookback Right"
input LookBackLeft = 5; # "Pivot Lookback Left"
input MaxLookback = 60; # "Max of Lookback Range"
input MinLookback = 5; # "Min of Lookback Range"
input DivBull = yes; # "Plot Bullish"
input DivHiddenBull = no; # "Plot Hidden Bullish"
input DivBear = yes; # "Plot Bearish"
input DivHiddenBear = no; # "Plot Hidden Bearish"
def divSrc = cumulative_volume_delta;

def h = high;
def l = low;

script FindPivots {
input dat = close; # default data or study being evaluated
input HL = 0; # default high or low pivot designation, -1 low, +1 high
input lbL = 5; # default Pivot Lookback Left
input lbR = 1; # default Pivot Lookback Right
##############
def _nan; # used for non-number returns
def _BN; # the current barnumber
def _VStop; # confirms that the lookforward period continues the pivot trend
def _V; # the Value at the actual pivot point
##############
_BN = BarNumber();
_nan = Double.NaN;
_VStop = if !isNaN(dat) and lbr > 0 and lbl > 0 then
fold a = 1 to lbR + 1 with b=1 while b do
if HL > 0 then dat > GetValue(dat,-a) else dat < GetValue(dat,-a) else _nan;
if (HL > 0) {
_V = if _BN > lbL + 1 and dat == Highest(dat, lbL + 1) and _VStop
then dat else _nan;
} else {
_V = if _BN > lbL + 1 and dat == Lowest(dat, lbL + 1) and _VStop
then dat else _nan;
}
plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#_inRange(cond) =>
script _inRange {
input cond = yes;
input rangeUpper = 60;
input rangeLower = 5;
def bars = if cond then 0 else bars[1] + 1;
def inrange = (rangeLower <= bars) and (bars <= rangeUpper);
plot retrun = inRange;
}
def pl = findpivots(divSrc,-1, LookBackLeft, LookBackRight);
def ph = findpivots(divSrc, 1, LookBackLeft, LookBackRight);

def plFound = if !isNaN(pl) then 1 else 0;
def phFound = if !isNaN(ph) then 1 else 0;

def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1==0 then divSrc[1] else vlFound1;
def vlFound = if vlFound_!=vlFound_[1] then vlFound_[1] else vlFound[1];
#valuewhen(plFound, divSrc, MinLookback, MaxLookback, 1);
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1==0 then divSrc[1] else vhFound1;
def vhFound = if vhFound_!=vhFound_[1] then vhFound_[1] else vhFound[1];
#valuewhen(phFound, divSrc, MinLookback, MaxLookback, 1);
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1 == 0 then l[1] else plPrice1;
def plPrice = if plPrice_!=plPrice_[1] then plPrice_[1] else plPrice[1];
#valuewhen(plFound, l, MinLookback, MaxLookback, 1);
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1==0 then h[1] else phPrice1;
def phPrice = if phPrice_!=phPrice_[1] then phPrice_[1] else phPrice[1];
#valuewhen(phFound, h, MinLookback, MaxLookback, 1);

#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice;
def bullCond = DivBull and plFound and oscHL and priceLL;
#// Hidden Bullish
def oscLL = divSrc < vlFound and inRangePl;
def priceHL = l > plPrice;
def hiddenBullCond = DivHiddenBull and plFound and oscLL and priceHL;

#// Regular Bearish
def inRangePh = _inRange(phFound[1],MaxLookback,MinLookback);
def oscLH = divSrc < vhFound and inRangePh;
def priceHH = h > phPrice;
def bearCond = DivBear and phFound and oscLH and priceHH;
#// Hidden Bearish
def oscHH = divSrc > vhFound and inRangePh;
def priceLH = h < phPrice;
def hiddenBearCond = DivHiddenBear and phFound and oscHH and priceLH;

#------ Bubbles
addchartbubble(bullCond, divSrc, "R", color.GREEN, no);
addchartbubble(bearCond, divSrc, "R", CreateColor(156,39,176), yes);
addchartbubble(hiddenBullCond, divSrc, "H", color.DARK_green, no);
addchartbubble(hiddenBearCond, divSrc, "H", color.DARK_red, yes);


#----End
 
Last edited by a moderator:
How can I include coloring candles to this version ?

# Cumulative Volume Delta
# This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# © Ankit_1618 converted by Zlotko

declare upper;

# Calculate upper_wick, lower_wick, spread, and body_length
def upper_wick = if close > open then high - close else high - open;
def lower_wick = if close > open then open - low else close - low;
def spread = high - low;
def body_length = spread - (upper_wick + lower_wick);

# Calculate percent_upper_wick, percent_lower_wick, and percent_body_length
def percent_upper_wick = upper_wick / spread;
def percent_lower_wick = lower_wick / spread;
def percent_body_length = body_length / spread;

# Calculate buying_volume and selling_volume
def buying_volume = if close > open then (percent_body_length + (percent_upper_wick + percent_lower_wick) / 2) * volume else ((percent_upper_wick + percent_lower_wick) / 2) * volume;
def selling_volume = if close < open then (percent_body_length + (percent_upper_wick + percent_lower_wick) / 2) * volume else ((percent_upper_wick + percent_lower_wick) / 2) * volume;

# Input for cumulation_length
input cumulation_length = 14;

# Calculate cumulative_buying_volume and cumulative_selling_volume using EMA
def cumulative_buying_volume = ExpAverage(buying_volume, cumulation_length);
def cumulative_selling_volume = ExpAverage(selling_volume, cumulation_length);

# Calculate cumulative_volume_delta
def cumulative_volume_delta = cumulative_buying_volume - cumulative_selling_volume;

# Plot histograms to represent cumulative volume delta
plot hist = cumulative_volume_delta;
hist.AssignValueColor(if cumulative_volume_delta > 0 then color.green else color.red);
hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.SetLineWeight(1);
hist.SetDefaultColor(GetColor(1));
hist.SetStyle(Curve.FIRM);

# Calculate volume_strength_wave and plot its EMA
def volume_strength_wave = if cumulative_buying_volume > cumulative_selling_volume then cumulative_buying_volume else cumulative_selling_volume;
def ema_volume_strength_wave = ExpAverage(volume_strength_wave, cumulation_length);
#plot ema_volume_strength_wave(color = color.gray, transp = 80);
# 50%Line.SetDefaultColor(Color.GRAY);

#----Div-----------
input LookBackRight = 5; # "Pivot Lookback Right"
input LookBackLeft = 5; # "Pivot Lookback Left"
input MaxLookback = 60; # "Max of Lookback Range"
input MinLookback = 5; # "Min of Lookback Range"
input DivBull = yes; # "Plot Bullish"
input DivHiddenBull = no; # "Plot Hidden Bullish"
input DivBear = yes; # "Plot Bearish"
input DivHiddenBear = no; # "Plot Hidden Bearish"
def divSrc = cumulative_volume_delta;

def h = high;
def l = low;

script FindPivots {
input dat = close; # default data or study being evaluated
input HL = 0; # default high or low pivot designation, -1 low, +1 high
input lbL = 5; # default Pivot Lookback Left
input lbR = 1; # default Pivot Lookback Right
##############
def _nan; # used for non-number returns
def _BN; # the current barnumber
def _VStop; # confirms that the lookforward period continues the pivot trend
def _V; # the Value at the actual pivot point
##############
_BN = BarNumber();
_nan = Double.NaN;
_VStop = if !isNaN(dat) and lbr > 0 and lbl > 0 then
fold a = 1 to lbR + 1 with b=1 while b do
if HL > 0 then dat > GetValue(dat,-a) else dat < GetValue(dat,-a) else _nan;
if (HL > 0) {
_V = if _BN > lbL + 1 and dat == Highest(dat, lbL + 1) and _VStop
then dat else _nan;
} else {
_V = if _BN > lbL + 1 and dat == Lowest(dat, lbL + 1) and _VStop
then dat else _nan;
}
plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}
#_inRange(cond) =>
script _inRange {
input cond = yes;
input rangeUpper = 60;
input rangeLower = 5;
def bars = if cond then 0 else bars[1] + 1;
def inrange = (rangeLower <= bars) and (bars <= rangeUpper);
plot retrun = inRange;
}
def pl = findpivots(divSrc,-1, LookBackLeft, LookBackRight);
def ph = findpivots(divSrc, 1, LookBackLeft, LookBackRight);

def plFound = if !isNaN(pl) then 1 else 0;
def phFound = if !isNaN(ph) then 1 else 0;

def vlFound1 = if plFound then divSrc else vlFound1[1];
def vlFound_ = if vlFound1==0 then divSrc[1] else vlFound1;
def vlFound = if vlFound_!=vlFound_[1] then vlFound_[1] else vlFound[1];
#valuewhen(plFound, divSrc, MinLookback, MaxLookback, 1);
def vhFound1 = if phFound then divSrc else vhFound1[1];
def vhFound_ = if vhFound1==0 then divSrc[1] else vhFound1;
def vhFound = if vhFound_!=vhFound_[1] then vhFound_[1] else vhFound[1];
#valuewhen(phFound, divSrc, MinLookback, MaxLookback, 1);
def plPrice1 = if plFound then l else plPrice1[1];
def plPrice_ = if plPrice1 == 0 then l[1] else plPrice1;
def plPrice = if plPrice_!=plPrice_[1] then plPrice_[1] else plPrice[1];
#valuewhen(plFound, l, MinLookback, MaxLookback, 1);
def phPrice1 = if phFound then h else phPrice1[1];
def phPrice_ = if phPrice1==0 then h[1] else phPrice1;
def phPrice = if phPrice_!=phPrice_[1] then phPrice_[1] else phPrice[1];
#valuewhen(phFound, h, MinLookback, MaxLookback, 1);

#// Regular Bullish
def inRangePl = _inRange(plFound[1],MaxLookback,MinLookback);
def oscHL = divSrc > vlFound and inRangePl;
def priceLL = l < plPrice;
def bullCond = DivBull and plFound and oscHL and priceLL;
#// Hidden Bullish
def oscLL = divSrc < vlFound and inRangePl;
def priceHL = l > plPrice;
def hiddenBullCond = DivHiddenBull and plFound and oscLL and priceHL;

#// Regular Bearish
def inRangePh = _inRange(phFound[1],MaxLookback,MinLookback);
def oscLH = divSrc < vhFound and inRangePh;
def priceHH = h > phPrice;
def bearCond = DivBear and phFound and oscLH and priceHH;
#// Hidden Bearish
def oscHH = divSrc > vhFound and inRangePh;
def priceLH = h < phPrice;
def hiddenBearCond = DivHiddenBear and phFound and oscHH and priceLH;

#------ Bubbles
addchartbubble(bullCond, divSrc, "R", color.GREEN, no);
addchartbubble(bearCond, divSrc, "R", CreateColor(156,39,176), yes);
addchartbubble(hiddenBullCond, divSrc, "H", color.DARK_green, no);
addchartbubble(hiddenBearCond, divSrc, "H", color.DARK_red, yes);


#----End
reply to 381

coloring based on what?

use this
https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AssignPriceColor

edit your post and add a link from where that code came from
 
Last edited:
@samer800 Is it possible to add labels for London High and London Low and similarly for NY and Asia timezone?
To this script:
https://usethinkscript.com/threads/...bels-for-thinkorswim.15632/page-2#post-142808

If current session is not London, then label should show last london high/low from last session otherwise from current session. I attempted to write this but its not printing correctly.

Code:
# Track London session high and low values
def londonHigh = if inLondonSession and high > londonHigh[1] then high else londonHigh[1];
def londonLow = if inLondonSession and low < londonLow[1] then low else londonLow[1];

# Display label for London session high/low price
AddLabel(inLondonSession and !IsNaN(londonHigh), "London High: " + AsText(Round(londonHigh, 2)), Color.CYAN);
AddLabel(inLondonSession and !IsNaN(londonLow), "London Low: " + AsText(Round(londonLow, 2)), Color.CYAN);

# When it's not the London session, display the last session's high/low
def lastLondonHigh = if !inLondonSession and !IsNaN(londonHigh[1]) then londonHigh[1] else Double.NaN;
def lastLondonLow = if !inLondonSession and !IsNaN(londonLow[1]) then londonLow[1] else Double.NaN;

AddLabel(!inLondonSession and !IsNaN(lastLondonHigh), "Last London High: " + AsText(Round(lastLondonHigh, 2)), Color.CYAN);
AddLabel(!inLondonSession and !IsNaN(lastLondonLow), "Last London Low: " + AsText(Round(lastLondonLow, 2)), Color.CYAN);

Can you please help and fix above code?
 
Last edited by a moderator:
I am trying to modify the Volume Profile indicator so that it starts at market open on a chart that shows premarket activity (the chart setting is TODAY: 10m). I've added in a session start time input but I keep getting the development error that states "Unexpected error has happened. An unexpected error has occurred. If the problem persists, please contact tech support. You are advised to restart your application now." Here is the code I am using:
Code:
input customRowHeight = 1.0;
input timePerProfile = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 60;
input opacity = 20;
input sessionStartTime = 0930; # Custom session start time in HHMM format

# Calculate session start in seconds
def sessionStartHour = Floor(sessionStartTime / 100);
def sessionStartMinute = sessionStartTime % 100;
def sessionStartSeconds = (sessionStartHour * 3600) + (sessionStartMinute * 60);

# Adjusted time logic
def secondsSinceSessionStart = SecondsFromTime(sessionStartSeconds);
def isSessionActive = secondsSinceSessionStart >= 0;

# Calculate period based on the selected profile type
def yyyymmdd = GetYyyyMmDd();
def tradingDays = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd);
def period;
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = Floor(secondsSinceSessionStart / 60);
case HOUR:
period = Floor(secondsSinceSessionStart / 3600);
case DAY:
period = if isSessionActive then tradingDays - 1 else Double.NaN;
case WEEK:
period = Floor(DaysFromDate(First(yyyymmdd)) / 7);
case MONTH:
period = GetYear() * 12 + GetMonth() - First(GetYear() * 12 + GetMonth());
case "OPT EXP":
period = GetYear() * 12 + GetMonth() + (GetDayOfMonth(yyyymmdd) > 20);
case BAR:
period = BarNumber() - 1;
}

# Define conditions for starting a new profile
def count = CompoundValue(1, if period != period[1] then (count[1] + 1) % multiplier else count[1], 0);
def cond = count == 0;

# Determine price per row height
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}

# Volume profile
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def pc = vol.GetPointOfControl();
def hVA = vol.GetHighestValueArea();
def lVA = vol.GetLowestValueArea();

# Plots
plot POC = if !IsNaN(pc) then pc else Double.NaN;
plot VAHigh = if !IsNaN(hVA) then hVA else Double.NaN;
plot VALow = if !IsNaN(lVA) then lVA else Double.NaN;

DefineGlobalColor("Profile", GetColor(1));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));

POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
 
Last edited by a moderator:
@samer800 Is it possible to add labels for London High and London Low and similarly for NY and Asia timezone?
To this script:
https://usethinkscript.com/threads/...bels-for-thinkorswim.15632/page-2#post-142808

If current session is not London, then label should show last london high/low from last session otherwise from current session. I attempted to write this but its not printing correctly.

Code:
# Track London session high and low values
def londonHigh = if inLondonSession and high > londonHigh[1] then high else londonHigh[1];
def londonLow = if inLondonSession and low < londonLow[1] then low else londonLow[1];

# Display label for London session high/low price
AddLabel(inLondonSession and !IsNaN(londonHigh), "London High: " + AsText(Round(londonHigh, 2)), Color.CYAN);
AddLabel(inLondonSession and !IsNaN(londonLow), "London Low: " + AsText(Round(londonLow, 2)), Color.CYAN);

# When it's not the London session, display the last session's high/low
def lastLondonHigh = if !inLondonSession and !IsNaN(londonHigh[1]) then londonHigh[1] else Double.NaN;
def lastLondonLow = if !inLondonSession and !IsNaN(londonLow[1]) then londonLow[1] else Double.NaN;

AddLabel(!inLondonSession and !IsNaN(lastLondonHigh), "Last London High: " + AsText(Round(lastLondonHigh, 2)), Color.CYAN);
AddLabel(!inLondonSession and !IsNaN(lastLondonLow), "Last London Low: " + AsText(Round(lastLondonLow, 2)), Color.CYAN);

Can you please help and fix above code?

reply to 383

not sure what you are doing. i think you pasted the wrong link?
this variable doesn't exist in original?
inLondonSession
so not data is sent to labels

this variable doesn't exist?
londonHigh

if you want highs to always be shown, why have conditions for the label? just put a 1, to turn it on all the time
AddLabel(inLondonSession and !IsNaN(londonHigh), "London High: " + AsText(Round(londonHigh, 2)), Color.CYAN);


this shows 4 pairs of labels for the 4 sessions
if a session is active, the high/low labels are yellow. else gray

Code:
#session_labels_hilo

#https://usethinkscript.com/threads/chatgpt-bard-other-ai-scripts-which-cant-be-used-in-thinkorswim.13822/page-20#post-152307
#serendipity2020
#383

#https://usethinkscript.com/threads/ny-london-asian-markets-ict-time-labels-for-thinkorswim.15632/page-2#post-142808
#post21
#SleepyZ
#Jun 13, 2024
#21


declare hide_on_daily;

input display_last_zone = yes;
input display_count     = 2;
input Show_Cloud = no;
input Show_Cloud2 = no;
input Show_Vertical_Line = yes;

def Asian_DrawLine =
#GetLastDay() and
(
!SecondsFromTime(1800) [1]
);
#AddVerticalLine (DrawLine, "", Color.Dark_black,Curve.Long_DASH);



#input ShowTodayOnly = yes;
#def Today = if GetDay() == GetLastDay() then 0 else 1;
#def Today = if GetDay() == GetLastDay() then 1 else 0;
#def Show_last = if GetDay() >= GetLastDay() then 1 else 0;

###############################################
def midn = 0000;
def midnite = if (SecondsFromTime(midn) == 0) then 1 else 0;
###############################################


#############################################################################################################
#############################################################################################################

#Q1
def Asian_Q1_afterbegin = 1800;
#def Asian_Q1_afterend = 2359;
def Asian_Q1_aftermarket = SecondsFromTime(Asian_Q1_afterbegin[1]) >= 0 and (SecondsFromTime(midn) == 0) >= 0;
def Asian_Q1_bars = 2000;

#input Asian_Q1_pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input Asian_Q1_pricePerRowHeightMode = { TICKSIZE, default AUTOMATIC, CUSTOM};

def Asian_Q1_customRowHeight = 1.0;
input Asian_Q1_timePerProfile = {default BAR};
def Asian_Q1_onExpansion = no;
def Asian_Q1_profiles = 1000;

def Asian_Q1_period;

switch (Asian_Q1_timePerProfile) {
case BAR:
    Asian_Q1_period = BarNumber() - 1;
}


def Asian_Q1_count = CompoundValue(1, if Asian_Q1_aftermarket and Asian_Q1_period != Asian_Q1_period[1] then (Asian_Q1_count[1] + Asian_Q1_period - Asian_Q1_period[1]) % Asian_Q1_bars else Asian_Q1_count[1], 0);
def Asian_Q1_cond = Asian_Q1_count < Asian_Q1_count[1] + Asian_Q1_period - Asian_Q1_period[1];
def Asian_Q1_height;
switch (Asian_Q1_pricePerRowHeightMode) {
case AUTOMATIC:
    Asian_Q1_height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    Asian_Q1_height = PricePerRow.TICKSIZE;
case CUSTOM:
    Asian_Q1_height = Asian_Q1_customRowHeight;
}

profile Asian_Q1_vol = VolumeProfile("startNewProfile" = Asian_Q1_cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = Asian_Q1_height, "value area percent" = 0);

def Asian_Q1_con = CompoundValue(1, Asian_Q1_onExpansion, no);

def Asian_Q1_hProfile = if Asian_Q1_aftermarket and IsNaN(Asian_Q1_vol.GetHighest()) and Asian_Q1_con then Asian_Q1_hProfile[1] else Asian_Q1_vol.GetHighest();
def Asian_Q1_lProfile = if Asian_Q1_aftermarket and IsNaN(Asian_Q1_vol.GetLowest()) and Asian_Q1_con then Asian_Q1_lProfile[1] else Asian_Q1_vol.GetLowest();
def Asian_Q1_plotsDomain = IsNaN(close) == Asian_Q1_onExpansion;
def Asian_Q1_ProfileHigh = if Asian_Q1_aftermarket and Asian_Q1_plotsDomain then Asian_Q1_hProfile else Double.NaN;
def Asian_Q1_ProfileLow = if Asian_Q1_aftermarket and Asian_Q1_plotsDomain then Asian_Q1_lProfile else Double.NaN;

def basis      = if TickSize() > .01 then GetYYYYMMDD() else GetDay();
def asiancount = if basis != basis[1] then  asiancount[1] + 1 else asiancount[1];
def asiancond  = HighestAll(asiancount) - asiancount + 1;
AddVerticalLine (if Show_Vertical_Line  and asiancond <= display_count then Asian_DrawLine else Double.NaN, "Asian", CreateColor(204, 255, 204), Curve.FIRM);

plot Asian_Q1_hrange = if display_last_zone and asiancond > display_count then Double.NaN else Asian_Q1_ProfileHigh;
plot Asian_Q1_lrange = if display_last_zone and asiancond > display_count  then Double.NaN else Asian_Q1_ProfileLow;
Asian_Q1_hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Asian_Q1_lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Asian_Q1_hrange.SetDefaultColor(CreateColor(204, 255, 204));
Asian_Q1_lrange.SetDefaultColor(CreateColor(204, 255, 204));
Asian_Q1_hrange.SetLineWeight(1);
Asian_Q1_lrange.SetLineWeight(1);
#Asian_Q1_hrange.Hide();
#Asian_Q1_lrange.Hide();

def Asian_Q1_bubblemover = 0;
def Asian_Q1_b = Asian_Q1_bubblemover;
def Asian_Q1_b1 = Asian_Q1_b + 1;


input Asian_Q1_showbubbles = no;
AddChartBubble(Asian_Q1_showbubbles and (IsNaN(Asian_Q1_hrange[Asian_Q1_b1]) and Asian_Q1_hrange[Asian_Q1_b]) , Asian_Q1_hrange, AsText(Asian_Q1_hrange), Color.LIGHT_RED);

AddChartBubble(Asian_Q1_showbubbles and (IsNaN(Asian_Q1_hrange[Asian_Q1_b1]) and Asian_Q1_hrange[Asian_Q1_b]) , Asian_Q1_lrange, AsText(Asian_Q1_lrange), Color.LIGHT_GREEN, up = no);

input Asian_Q1_showverticalline = no;
AddVerticalLine(Asian_Q1_showverticalline and Asian_Q1_hrange != Asian_Q1_hrange[1], "", Color.BLUE, stroke = Curve.FIRM);


#Addcloud(hrange, lrange, createcolor(0, 51, 51), createcolor(0, 51, 51));
AddCloud(if Show_Cloud then Asian_Q1_hrange else Double.NaN, Asian_Q1_lrange, CreateColor(204, 255, 204), CreateColor(204, 255, 204));

AddCloud(if Show_Cloud2 then Asian_Q1_hrange else Double.NaN, Asian_Q1_lrange, Color.BLACK, Color.BLACK);

#Addcloud(Asian_Q1_hrange, Asian_Q1_lrange, color.black, color.black);


###############################################################
###############################################################
###############################################################
#LONDON



def London_Q2_afterbegin = midn;
def London_Q2_afterend = 0600;
def London_Q2_aftermarket = SecondsFromTime(London_Q2_afterbegin) >= 0 and SecondsTillTime(London_Q2_afterend) >= 0;
def London_Q2_bars = 2000;

def London_DrawLine =
!SecondsFromTime(0000)[1];


#input London_Q2_pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input London_Q2_pricePerRowHeightMode = { TICKSIZE, default AUTOMATIC, CUSTOM};

def London_Q2_customRowHeight = 1.0;
input London_Q2_timePerProfile = {default BAR};
def London_Q2_onExpansion = no;
def London_Q2_profiles = 1000;

def London_Q2_period;

switch (London_Q2_timePerProfile) {
case BAR:
    London_Q2_period = BarNumber() - 1;
}


def London_Q2_count = CompoundValue(1, if London_Q2_aftermarket and London_Q2_period != London_Q2_period[1] then (London_Q2_count[1] + London_Q2_period - London_Q2_period[1]) % London_Q2_bars else London_Q2_count[1], 0);
def London_Q2_cond = London_Q2_count < London_Q2_count[1] + London_Q2_period - London_Q2_period[1];
def London_Q2_height;
switch (London_Q2_pricePerRowHeightMode) {
case AUTOMATIC:
    London_Q2_height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    London_Q2_height = PricePerRow.TICKSIZE;
case CUSTOM:
    London_Q2_height = London_Q2_customRowHeight;
}

profile London_Q2_vol = VolumeProfile("startNewProfile" = London_Q2_cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = London_Q2_height, "value area percent" = 0);

def London_Q2_con = CompoundValue(1, London_Q2_onExpansion, no);

def London_Q2_hProfile = if London_Q2_aftermarket and IsNaN(London_Q2_vol.GetHighest()) and London_Q2_con then London_Q2_hProfile[1] else London_Q2_vol.GetHighest();
def London_Q2_lProfile = if London_Q2_aftermarket and IsNaN(London_Q2_vol.GetLowest()) and London_Q2_con then London_Q2_lProfile[1] else London_Q2_vol.GetLowest();
def London_Q2_plotsDomain = IsNaN(close) == London_Q2_onExpansion;
def London_Q2_ProfileHigh = if London_Q2_aftermarket and London_Q2_plotsDomain then London_Q2_hProfile else Double.NaN;
def London_Q2_ProfileLow = if London_Q2_aftermarket and London_Q2_plotsDomain then London_Q2_lProfile else Double.NaN;

def londoncount = if basis != basis[1] then  londoncount[1] + 1 else londoncount[1];
def londoncond  = HighestAll(londoncount) - londoncount + 1;
AddVerticalLine (if Show_Vertical_Line  and londoncond <= display_count then London_DrawLine else Double.NaN, "London", CreateColor(153, 153 , 255), Curve.FIRM);

plot London_Q2_hrange = if display_last_zone and londoncond > display_count then Double.NaN else London_Q2_ProfileHigh;
plot London_Q2_lrange = if display_last_zone and londoncond > display_count then Double.NaN else London_Q2_ProfileLow;
London_Q2_hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
London_Q2_lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
London_Q2_hrange.SetDefaultColor(CreateColor(153, 153 , 255));
London_Q2_lrange.SetDefaultColor(CreateColor(153, 153 , 255));
London_Q2_hrange.SetLineWeight(1);
London_Q2_lrange.SetLineWeight(1);
#London_Q2_hrange.Hide();
#London_Q2_lrange.Hide();

def London_Q2_bubblemover = 0;
def London_Q2_b = London_Q2_bubblemover;
def London_Q2_b1 = London_Q2_b + 1;


input London_Q2_showbubbles = no;
AddChartBubble(London_Q2_showbubbles and (IsNaN(London_Q2_hrange[London_Q2_b1]) and London_Q2_hrange[London_Q2_b]) , London_Q2_hrange, AsText(London_Q2_hrange), Color.LIGHT_RED);

AddChartBubble(London_Q2_showbubbles and (IsNaN(London_Q2_hrange[London_Q2_b1]) and London_Q2_hrange[London_Q2_b]) , London_Q2_lrange, AsText(London_Q2_lrange), Color.LIGHT_GREEN, up = no);

input London_Q2_showverticalline = yes;
AddVerticalLine(London_Q2_showverticalline and London_Q2_hrange != London_Q2_hrange[1], "London ", Color.BLUE, stroke = Curve.FIRM);

#Addcloud(hrange, lrange, createcolor(0, 51, 51), createcolor(0, 51, 51));
AddCloud(if Show_Cloud then London_Q2_hrange else Double.NaN, London_Q2_lrange, CreateColor(153, 153 , 255), CreateColor(153, 153 , 255));

AddCloud(if Show_Cloud2 then London_Q2_hrange else Double.NaN, London_Q2_lrange, Color.BLACK, Color.BLACK);


#Addcloud(London_Q2_hrange, London_Q2_lrange, color.black, color.black);

#############################################################################################################
#############################################################################################################

#############################################################################################################
#############################################################################################################
def NY_DrawLine =
#GetDay() == GetLastDay() and
(
!SecondsFromTime(0600)
);

#AddVerticalLine (DrawLine, "", Color.Dark_black,Curve.Long_DASH);


def Show_last = if GetDay() == GetLastDay() then 1 else 0;

#############################################################################################################
#############################################################################################################

#Q3
def NY_Q3_afterbegin = 0600;
def NY_Q3_afterend = 1200;
def NY_Q3_aftermarket = SecondsFromTime(NY_Q3_afterbegin) >= 0 and SecondsTillTime(NY_Q3_afterend) >= 0;
def NY_Q3_bars = 2000;

#input NY_Q3_pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input NY_Q3_pricePerRowHeightMode = { TICKSIZE, default AUTOMATIC, CUSTOM};

def NY_Q3_customRowHeight = 1.0;
input NY_Q3_timePerProfile = {default BAR};
def NY_Q3_onExpansion = no;
def NY_Q3_profiles = 1000;

def NY_Q3_period;

switch (NY_Q3_timePerProfile) {
case BAR:
    NY_Q3_period = BarNumber() - 1;
}


def NY_Q3_count = CompoundValue(1, if NY_Q3_aftermarket and NY_Q3_period != NY_Q3_period[1] then (NY_Q3_count[1] + NY_Q3_period - NY_Q3_period[1]) % NY_Q3_bars else NY_Q3_count[1], 0);
def NY_Q3_cond = NY_Q3_count < NY_Q3_count[1] + NY_Q3_period - NY_Q3_period[1];
def NY_Q3_height;
switch (NY_Q3_pricePerRowHeightMode) {
case AUTOMATIC:
    NY_Q3_height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    NY_Q3_height = PricePerRow.TICKSIZE;
case CUSTOM:
    NY_Q3_height = NY_Q3_customRowHeight;
}

profile NY_Q3_vol = VolumeProfile("startNewProfile" = NY_Q3_cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = NY_Q3_height, "value area percent" = 0);

def NY_Q3_con = CompoundValue(1, NY_Q3_onExpansion, no);

def NY_Q3_hProfile = if NY_Q3_aftermarket and IsNaN(NY_Q3_vol.GetHighest()) and NY_Q3_con then NY_Q3_hProfile[1] else NY_Q3_vol.GetHighest();
def NY_Q3_lProfile = if NY_Q3_aftermarket and IsNaN(NY_Q3_vol.GetLowest()) and NY_Q3_con then NY_Q3_lProfile[1] else NY_Q3_vol.GetLowest();
def NY_Q3_plotsDomain = IsNaN(close) == NY_Q3_onExpansion;
def NY_Q3_ProfileHigh = if NY_Q3_aftermarket and NY_Q3_plotsDomain then NY_Q3_hProfile else Double.NaN;
def NY_Q3_ProfileLow = if NY_Q3_aftermarket and NY_Q3_plotsDomain then NY_Q3_lProfile else Double.NaN;

def nyq3count = if basis != basis[1] then  nyq3count[1] + 1 else nyq3count[1];
def nyq3cond  = HighestAll(nyq3count) - nyq3count + 1;
AddVerticalLine (if Show_Vertical_Line and nyq3cond <= display_count then NY_DrawLine else Double.NaN, "NY AM", CreateColor(0, 153, 255), Curve.FIRM);

plot NY_Q3_hrange = if display_last_zone and nyq3cond > display_count then Double.NaN else NY_Q3_ProfileHigh;
plot NY_Q3_lrange = if display_last_zone and nyq3cond > display_count then Double.NaN else NY_Q3_ProfileLow;
NY_Q3_hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
NY_Q3_lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
NY_Q3_hrange.SetDefaultColor(CreateColor(0, 153, 255));
NY_Q3_lrange.SetDefaultColor(CreateColor(0, 153, 255));
NY_Q3_hrange.SetLineWeight(1);
NY_Q3_lrange.SetLineWeight(1);
#NY_Q3_hrange.Hide();
#NY_Q3_lrange.Hide();

def NY_Q3_bubblemover = 0;
def NY_Q3_b = NY_Q3_bubblemover;
def NY_Q3_b1 = NY_Q3_b + 1;


input NY_Q3_showbubbles = no;
AddChartBubble(NY_Q3_showbubbles and (IsNaN(NY_Q3_hrange[NY_Q3_b1]) and NY_Q3_hrange[NY_Q3_b]) , NY_Q3_hrange, AsText(NY_Q3_hrange), Color.LIGHT_RED);

AddChartBubble(NY_Q3_showbubbles and (IsNaN(NY_Q3_hrange[NY_Q3_b1]) and NY_Q3_hrange[NY_Q3_b]) , NY_Q3_lrange, AsText(NY_Q3_lrange), Color.LIGHT_GREEN, up = no);

input NY_Q3_showverticalline = no;
AddVerticalLine(NY_Q3_showverticalline and NY_Q3_hrange != NY_Q3_hrange[1], "", Color.BLUE, stroke = Curve.FIRM);

#Addcloud(hrange, lrange, createcolor(0, 51, 51), createcolor(0, 51, 51));
AddCloud(if Show_Cloud then NY_Q3_hrange else Double.NaN, NY_Q3_lrange, CreateColor(0, 153, 255), CreateColor(0, 153, 255));

AddCloud(if Show_Cloud2 then NY_Q3_hrange else Double.NaN, NY_Q3_lrange, Color.BLACK, Color.BLACK);

#Addcloud(NY_Q3_hrange, NY_Q3_lrange, color.black, color.black);

#############################################################################################################
#############################################################################################################

def NY_PM_DrawLine =
#GetDay() == GetLastDay() and
(
!SecondsFromTime(1200)
);

#AddVerticalLine (DrawLine, "", Color.Dark_black,Curve.Long_DASH);



#############################################################################################################
#############################################################################################################

#Q4
def NY_PM_Q4_afterbegin = 1200;
def NY_PM_Q4_afterend = 1800;
def NY_PM_Q4_aftermarket = SecondsFromTime(NY_PM_Q4_afterbegin) >= 0 and SecondsTillTime(NY_PM_Q4_afterend) >= 0;
def NY_PM_Q4_bars = 2000;

#input NY_PM_Q4_pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input NY_PM_Q4_pricePerRowHeightMode = { TICKSIZE, default AUTOMATIC, CUSTOM};

def NY_PM_Q4_customRowHeight = 1.0;
input NY_PM_Q4_timePerProfile = {default BAR};
def NY_PM_Q4_onExpansion = no;
def NY_PM_Q4_profiles = 1000;

def NY_PM_Q4_period;

switch (NY_PM_Q4_timePerProfile) {
case BAR:
    NY_PM_Q4_period = BarNumber() - 1;
}


def NY_PM_Q4_count = CompoundValue(1, if NY_PM_Q4_aftermarket and NY_PM_Q4_period != NY_PM_Q4_period[1] then (NY_PM_Q4_count[1] + NY_PM_Q4_period - NY_PM_Q4_period[1]) % NY_PM_Q4_bars else NY_PM_Q4_count[1], 0);
def NY_PM_Q4_cond = NY_PM_Q4_count < NY_PM_Q4_count[1] + NY_PM_Q4_period - NY_PM_Q4_period[1];
def NY_PM_Q4_height;
switch (NY_PM_Q4_pricePerRowHeightMode) {
case AUTOMATIC:
    NY_PM_Q4_height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    NY_PM_Q4_height = PricePerRow.TICKSIZE;
case CUSTOM:
    NY_PM_Q4_height = NY_PM_Q4_customRowHeight;
}

profile NY_PM_Q4_vol = VolumeProfile("startNewProfile" = NY_PM_Q4_cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = NY_PM_Q4_height, "value area percent" = 0);

def NY_PM_Q4_con = CompoundValue(1, NY_PM_Q4_onExpansion, no);

def NY_PM_Q4_hProfile = if NY_PM_Q4_aftermarket and IsNaN(NY_PM_Q4_vol.GetHighest()) and NY_PM_Q4_con then NY_PM_Q4_hProfile[1] else NY_PM_Q4_vol.GetHighest();
def NY_PM_Q4_lProfile = if NY_PM_Q4_aftermarket and IsNaN(NY_PM_Q4_vol.GetLowest()) and NY_PM_Q4_con then NY_PM_Q4_lProfile[1] else NY_PM_Q4_vol.GetLowest();
def NY_PM_Q4_plotsDomain = IsNaN(close) == NY_PM_Q4_onExpansion;
def NY_PM_Q4_ProfileHigh = if NY_PM_Q4_aftermarket and NY_PM_Q4_plotsDomain then NY_PM_Q4_hProfile else Double.NaN;
def NY_PM_Q4_ProfileLow = if NY_PM_Q4_aftermarket and NY_PM_Q4_plotsDomain then NY_PM_Q4_lProfile else Double.NaN;

def nyq4count = if basis != basis[1] then  nyq4count[1] + 1 else nyq4count[1];
def nyq4cond  = HighestAll(nyq4count) - nyq4count + 1;
AddVerticalLine (if Show_Vertical_Line and nyq4cond <= display_count then NY_PM_DrawLine else Double.NaN, "NY PM", CreateColor(255, 153, 102), Curve.FIRM);


plot NY_PM_Q4_hrange = if display_last_zone and nyq4cond > display_count then Double.NaN else NY_PM_Q4_ProfileHigh;
plot NY_PM_Q4_lrange = if display_last_zone and nyq4cond > display_count then Double.NaN else NY_PM_Q4_ProfileLow;
NY_PM_Q4_hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
NY_PM_Q4_lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
NY_PM_Q4_hrange.SetDefaultColor(CreateColor(255, 153, 102));
NY_PM_Q4_lrange.SetDefaultColor(CreateColor(255, 153, 102));
NY_PM_Q4_hrange.SetLineWeight(1);
NY_PM_Q4_lrange.SetLineWeight(1);
#NY_PM_Q4_hrange.Hide();
#NY_PM_Q4_lrange.Hide();

def NY_PM_Q4_bubblemover = 0;
def NY_PM_Q4_b = NY_PM_Q4_bubblemover;
def NY_PM_Q4_b1 = NY_PM_Q4_b + 1;


input NY_PM_Q4_showbubbles = no;
AddChartBubble(NY_PM_Q4_showbubbles and (IsNaN(NY_PM_Q4_hrange[NY_PM_Q4_b1]) and NY_PM_Q4_hrange[NY_PM_Q4_b]) , NY_PM_Q4_hrange, AsText(NY_PM_Q4_hrange), Color.LIGHT_RED);

AddChartBubble(NY_PM_Q4_showbubbles and (IsNaN(NY_PM_Q4_hrange[NY_PM_Q4_b1]) and NY_PM_Q4_hrange[NY_PM_Q4_b]) , NY_PM_Q4_lrange, AsText(NY_PM_Q4_lrange), Color.LIGHT_GREEN, up = no);

input NY_PM_Q4_showverticalline = no;
AddVerticalLine(NY_PM_Q4_showverticalline and NY_PM_Q4_hrange != NY_PM_Q4_hrange[1], "", Color.BLUE, stroke = Curve.FIRM);

#Addcloud(hrange, lrange, createcolor(0, 51, 51), createcolor(0, 51, 51));
AddCloud(if Show_Cloud then NY_PM_Q4_hrange else Double.NaN, NY_PM_Q4_lrange, CreateColor(255, 153, 102), CreateColor(255, 153, 102));

AddCloud(if Show_Cloud2 then NY_PM_Q4_hrange else Double.NaN, NY_PM_Q4_lrange, Color.BLACK, Color.BLACK);

#Addcloud(NY_PM_Q4_hrange, NY_PM_Q4_lrange, color.black, color.black);

#############################################################################################################
#############################################################################################################

#-----------------


addlabel(1, "  ", color.black);
# Asian_Q1_ProfileHigh 
# Asian_Q1_Profilelow
def asiahi = if isnan(Asian_Q1_ProfileHigh) then asiahi[1] else Asian_Q1_ProfileHigh;
def asialo = if isnan(Asian_Q1_Profilelow) then asialo[1] else Asian_Q1_Profilelow;
addlabel(1, "asia hi " + asiahi, (if isnan(Asian_Q1_ProfileHigh) then color.gray else color.yellow));
addlabel(1, "asia lo " + asialo, (if isnan(Asian_Q1_Profilelow) then color.gray else color.yellow));

addlabel(1, "  ", color.black);
#London_Q2_ProfileHigh
#London_Q2_Profilelow
def lonhi = if isnan(London_Q2_ProfileHigh) then lonhi[1] else London_Q2_ProfileHigh;
def lonlo = if isnan(London_Q2_Profilelow) then lonlo[1] else London_Q2_Profilelow;
addlabel(1, "london hi " + lonhi, (if isnan(London_Q2_ProfileHigh) then color.gray else color.yellow));
addlabel(1, "london lo " + lonlo, (if isnan(London_Q2_Profilelow) then color.gray else color.yellow));

addlabel(1, "  ", color.black);
#NY_Q3_ProfileHigh
#NY_Q3_Profilelow
def nyamhi = if isnan(NY_Q3_ProfileHigh) then nyamhi[1] else NY_Q3_ProfileHigh;
def nyamlo = if isnan(NY_Q3_Profilelow) then nyamlo[1] else NY_Q3_Profilelow;
addlabel(1, "NY am hi " + nyamhi, (if isnan(NY_Q3_ProfileHigh) then color.gray else color.yellow));
addlabel(1, "NY am lo " + nyamlo, (if isnan(NY_Q3_Profilelow) then color.gray else color.yellow));

addlabel(1, "  ", color.black);
#NY_PM_Q4_ProfileHigh
#NY_PM_Q4_Profilelow
def nypmhi = if isnan(NY_PM_Q4_ProfileHigh) then nypmhi[1] else NY_PM_Q4_ProfileHigh;
def nypmlo = if isnan(NY_PM_Q4_Profilelow) then nypmlo[1] else NY_PM_Q4_Profilelow;
addlabel(1, "NY pm hi " + nypmhi, (if isnan(NY_PM_Q4_ProfileHigh) then color.gray else color.yellow));
addlabel(1, "NY pm lo " + nypmlo, (if isnan(NY_PM_Q4_Profilelow) then color.gray else color.yellow));
addlabel(1, "  ", color.black);
#
 

Attachments

  • img1.JPG
    img1.JPG
    114.7 KB · Views: 52
I am trying to modify the Volume Profile indicator so that it starts at market open on a chart that shows premarket activity (the chart setting is TODAY: 10m). I've added in a session start time input but I keep getting the development error that states "Unexpected error has happened. An unexpected error has occurred. If the problem persists, please contact tech support. You are advised to restart your application now." Here is the code I am using:
Code:
input customRowHeight = 1.0;
input timePerProfile = {default CHART, MINUTE, HOUR, DAY, WEEK, MONTH, "OPT EXP", BAR};
input multiplier = 1;
input onExpansion = no;
input profiles = 1000;
input showPointOfControl = yes;
input showValueArea = yes;
input valueAreaPercent = 60;
input opacity = 20;
input sessionStartTime = 0930; # Custom session start time in HHMM format

# Calculate session start in seconds
def sessionStartHour = Floor(sessionStartTime / 100);
def sessionStartMinute = sessionStartTime % 100;
def sessionStartSeconds = (sessionStartHour * 3600) + (sessionStartMinute * 60);

# Adjusted time logic
def secondsSinceSessionStart = SecondsFromTime(sessionStartSeconds);
def isSessionActive = secondsSinceSessionStart >= 0;

# Calculate period based on the selected profile type
def yyyymmdd = GetYyyyMmDd();
def tradingDays = CountTradingDays(Min(First(yyyymmdd), yyyymmdd), yyyymmdd);
def period;
switch (timePerProfile) {
case CHART:
period = 0;
case MINUTE:
period = Floor(secondsSinceSessionStart / 60);
case HOUR:
period = Floor(secondsSinceSessionStart / 3600);
case DAY:
period = if isSessionActive then tradingDays - 1 else Double.NaN;
case WEEK:
period = Floor(DaysFromDate(First(yyyymmdd)) / 7);
case MONTH:
period = GetYear() * 12 + GetMonth() - First(GetYear() * 12 + GetMonth());
case "OPT EXP":
period = GetYear() * 12 + GetMonth() + (GetDayOfMonth(yyyymmdd) > 20);
case BAR:
period = BarNumber() - 1;
}

# Define conditions for starting a new profile
def count = CompoundValue(1, if period != period[1] then (count[1] + 1) % multiplier else count[1], 0);
def cond = count == 0;

# Determine price per row height
def height;
switch (pricePerRowHeightMode) {
case AUTOMATIC:
height = PricePerRow.AUTOMATIC;
case TICKSIZE:
height = PricePerRow.TICKSIZE;
case CUSTOM:
height = customRowHeight;
}

# Volume profile
profile vol = VolumeProfile("startNewProfile" = cond, "onExpansion" = onExpansion, "numberOfProfiles" = profiles, "pricePerRow" = height, "value area percent" = valueAreaPercent);
def pc = vol.GetPointOfControl();
def hVA = vol.GetHighestValueArea();
def lVA = vol.GetLowestValueArea();

# Plots
plot POC = if !IsNaN(pc) then pc else Double.NaN;
plot VAHigh = if !IsNaN(hVA) then hVA else Double.NaN;
plot VALow = if !IsNaN(lVA) then lVA else Double.NaN;

DefineGlobalColor("Profile", GetColor(1));
DefineGlobalColor("Point Of Control", GetColor(5));
DefineGlobalColor("Value Area", GetColor(8));

POC.SetDefaultColor(GlobalColor("Point Of Control"));
POC.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VAHigh.SetDefaultColor(GlobalColor("Value Area"));
VAHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VALow.SetDefaultColor(GlobalColor("Value Area"));
VALow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

reply to #384

@SleepyZ has posted many studies using profile. maybe he can take a look and answer this?
 
I am a newbie. How can we apply to future trading on TOS?
Code:
# Define Inputs
input coin = "CRV";
input direction = "LONG";
input leverage = 50;
input QFLVolumeMA = 6;
input deviationToBuyBelowBase = 0.005; # 0.5% expressed as a decimal
input deviationToOpen1stSafety = 0.005; # 0.5% expressed as a decimal
input TP = 0.01; # 1% take profit
input BO = 30; # Base order size
input SO = 60; # Safety order size
input SOVolume = 2; # Safety order volume multiplier
input SOStepScale = 2; # Step scale multiplier
input maxSafetyOrders = 6; # Max safety orders
input audibleAlertEnabled = yes; # Enable audible alerts

# Price Calculation
def price = close;

# Spread Calculation
def spread = high - low;

# Logic for Entry Conditions
def baseOrderCondition = price < price * (1 - deviationToBuyBelowBase);

# Safety Order Conditions
def safetyOrderCondition = price < price * (1 - deviationToOpen1stSafety);

# Take Profit Logic
def takeProfitCondition = price >= price * (1 + TP);

# Trigger Sell Conditional Order
def sellCondition = spread > spread[1]; # Example logic: Sell when spread increases

# Audible Alert
Alert(baseOrderCondition, "Base Order Condition Triggered", audibleAlertEnabled);
Alert(takeProfitCondition, "Take Profit Triggered", audibleAlertEnabled);
Alert(sellCondition, "Sell Condition Triggered", audibleAlertEnabled);

# Plot Base Order
plot baseOrder = if baseOrderCondition then price else Double.NaN;

# Plot Safety Orders
plot safetyOrders = if safetyOrderCondition then price else Double.NaN;

# Plot Exit Trade
plot exitTrade = if takeProfitCondition then price else Double.NaN;

# Plot Sell Conditional Order
plot sellOrder = if sellCondition then price else Double.NaN;
 
Last edited by a moderator:
reply to 383

not sure what you are doing. i think you pasted the wrong link?
this variable doesn't exist in original?
inLondonSession
so not data is sent to labels

this variable doesn't exist?
londonHigh

if you want highs to always be shown, why have conditions for the label? just put a 1, to turn it on all the time
AddLabel(inLondonSession and !IsNaN(londonHigh), "London High: " + AsText(Round(londonHigh, 2)), Color.CYAN);


this shows 4 pairs of labels for the 4 sessions
if a session is active, the high/low labels are yellow. else gray

Code:
#session_labels_hilo

#https://usethinkscript.com/threads/chatgpt-bard-other-ai-scripts-which-cant-be-used-in-thinkorswim.13822/page-20#post-152307
#serendipity2020
#383

#https://usethinkscript.com/threads/ny-london-asian-markets-ict-time-labels-for-thinkorswim.15632/page-2#post-142808
#post21
#SleepyZ
#Jun 13, 2024
#21


declare hide_on_daily;

input display_last_zone = yes;
input display_count     = 2;
input Show_Cloud = no;
input Show_Cloud2 = no;
input Show_Vertical_Line = yes;

def Asian_DrawLine =
#GetLastDay() and
(
!SecondsFromTime(1800) [1]
);
#AddVerticalLine (DrawLine, "", Color.Dark_black,Curve.Long_DASH);



#input ShowTodayOnly = yes;
#def Today = if GetDay() == GetLastDay() then 0 else 1;
#def Today = if GetDay() == GetLastDay() then 1 else 0;
#def Show_last = if GetDay() >= GetLastDay() then 1 else 0;

###############################################
def midn = 0000;
def midnite = if (SecondsFromTime(midn) == 0) then 1 else 0;
###############################################


#############################################################################################################
#############################################################################################################

#Q1
def Asian_Q1_afterbegin = 1800;
#def Asian_Q1_afterend = 2359;
def Asian_Q1_aftermarket = SecondsFromTime(Asian_Q1_afterbegin[1]) >= 0 and (SecondsFromTime(midn) == 0) >= 0;
def Asian_Q1_bars = 2000;

#input Asian_Q1_pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input Asian_Q1_pricePerRowHeightMode = { TICKSIZE, default AUTOMATIC, CUSTOM};

def Asian_Q1_customRowHeight = 1.0;
input Asian_Q1_timePerProfile = {default BAR};
def Asian_Q1_onExpansion = no;
def Asian_Q1_profiles = 1000;

def Asian_Q1_period;

switch (Asian_Q1_timePerProfile) {
case BAR:
    Asian_Q1_period = BarNumber() - 1;
}


def Asian_Q1_count = CompoundValue(1, if Asian_Q1_aftermarket and Asian_Q1_period != Asian_Q1_period[1] then (Asian_Q1_count[1] + Asian_Q1_period - Asian_Q1_period[1]) % Asian_Q1_bars else Asian_Q1_count[1], 0);
def Asian_Q1_cond = Asian_Q1_count < Asian_Q1_count[1] + Asian_Q1_period - Asian_Q1_period[1];
def Asian_Q1_height;
switch (Asian_Q1_pricePerRowHeightMode) {
case AUTOMATIC:
    Asian_Q1_height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    Asian_Q1_height = PricePerRow.TICKSIZE;
case CUSTOM:
    Asian_Q1_height = Asian_Q1_customRowHeight;
}

profile Asian_Q1_vol = VolumeProfile("startNewProfile" = Asian_Q1_cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = Asian_Q1_height, "value area percent" = 0);

def Asian_Q1_con = CompoundValue(1, Asian_Q1_onExpansion, no);

def Asian_Q1_hProfile = if Asian_Q1_aftermarket and IsNaN(Asian_Q1_vol.GetHighest()) and Asian_Q1_con then Asian_Q1_hProfile[1] else Asian_Q1_vol.GetHighest();
def Asian_Q1_lProfile = if Asian_Q1_aftermarket and IsNaN(Asian_Q1_vol.GetLowest()) and Asian_Q1_con then Asian_Q1_lProfile[1] else Asian_Q1_vol.GetLowest();
def Asian_Q1_plotsDomain = IsNaN(close) == Asian_Q1_onExpansion;
def Asian_Q1_ProfileHigh = if Asian_Q1_aftermarket and Asian_Q1_plotsDomain then Asian_Q1_hProfile else Double.NaN;
def Asian_Q1_ProfileLow = if Asian_Q1_aftermarket and Asian_Q1_plotsDomain then Asian_Q1_lProfile else Double.NaN;

def basis      = if TickSize() > .01 then GetYYYYMMDD() else GetDay();
def asiancount = if basis != basis[1] then  asiancount[1] + 1 else asiancount[1];
def asiancond  = HighestAll(asiancount) - asiancount + 1;
AddVerticalLine (if Show_Vertical_Line  and asiancond <= display_count then Asian_DrawLine else Double.NaN, "Asian", CreateColor(204, 255, 204), Curve.FIRM);

plot Asian_Q1_hrange = if display_last_zone and asiancond > display_count then Double.NaN else Asian_Q1_ProfileHigh;
plot Asian_Q1_lrange = if display_last_zone and asiancond > display_count  then Double.NaN else Asian_Q1_ProfileLow;
Asian_Q1_hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Asian_Q1_lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Asian_Q1_hrange.SetDefaultColor(CreateColor(204, 255, 204));
Asian_Q1_lrange.SetDefaultColor(CreateColor(204, 255, 204));
Asian_Q1_hrange.SetLineWeight(1);
Asian_Q1_lrange.SetLineWeight(1);
#Asian_Q1_hrange.Hide();
#Asian_Q1_lrange.Hide();

def Asian_Q1_bubblemover = 0;
def Asian_Q1_b = Asian_Q1_bubblemover;
def Asian_Q1_b1 = Asian_Q1_b + 1;


input Asian_Q1_showbubbles = no;
AddChartBubble(Asian_Q1_showbubbles and (IsNaN(Asian_Q1_hrange[Asian_Q1_b1]) and Asian_Q1_hrange[Asian_Q1_b]) , Asian_Q1_hrange, AsText(Asian_Q1_hrange), Color.LIGHT_RED);

AddChartBubble(Asian_Q1_showbubbles and (IsNaN(Asian_Q1_hrange[Asian_Q1_b1]) and Asian_Q1_hrange[Asian_Q1_b]) , Asian_Q1_lrange, AsText(Asian_Q1_lrange), Color.LIGHT_GREEN, up = no);

input Asian_Q1_showverticalline = no;
AddVerticalLine(Asian_Q1_showverticalline and Asian_Q1_hrange != Asian_Q1_hrange[1], "", Color.BLUE, stroke = Curve.FIRM);


#Addcloud(hrange, lrange, createcolor(0, 51, 51), createcolor(0, 51, 51));
AddCloud(if Show_Cloud then Asian_Q1_hrange else Double.NaN, Asian_Q1_lrange, CreateColor(204, 255, 204), CreateColor(204, 255, 204));

AddCloud(if Show_Cloud2 then Asian_Q1_hrange else Double.NaN, Asian_Q1_lrange, Color.BLACK, Color.BLACK);

#Addcloud(Asian_Q1_hrange, Asian_Q1_lrange, color.black, color.black);


###############################################################
###############################################################
###############################################################
#LONDON



def London_Q2_afterbegin = midn;
def London_Q2_afterend = 0600;
def London_Q2_aftermarket = SecondsFromTime(London_Q2_afterbegin) >= 0 and SecondsTillTime(London_Q2_afterend) >= 0;
def London_Q2_bars = 2000;

def London_DrawLine =
!SecondsFromTime(0000)[1];


#input London_Q2_pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input London_Q2_pricePerRowHeightMode = { TICKSIZE, default AUTOMATIC, CUSTOM};

def London_Q2_customRowHeight = 1.0;
input London_Q2_timePerProfile = {default BAR};
def London_Q2_onExpansion = no;
def London_Q2_profiles = 1000;

def London_Q2_period;

switch (London_Q2_timePerProfile) {
case BAR:
    London_Q2_period = BarNumber() - 1;
}


def London_Q2_count = CompoundValue(1, if London_Q2_aftermarket and London_Q2_period != London_Q2_period[1] then (London_Q2_count[1] + London_Q2_period - London_Q2_period[1]) % London_Q2_bars else London_Q2_count[1], 0);
def London_Q2_cond = London_Q2_count < London_Q2_count[1] + London_Q2_period - London_Q2_period[1];
def London_Q2_height;
switch (London_Q2_pricePerRowHeightMode) {
case AUTOMATIC:
    London_Q2_height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    London_Q2_height = PricePerRow.TICKSIZE;
case CUSTOM:
    London_Q2_height = London_Q2_customRowHeight;
}

profile London_Q2_vol = VolumeProfile("startNewProfile" = London_Q2_cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = London_Q2_height, "value area percent" = 0);

def London_Q2_con = CompoundValue(1, London_Q2_onExpansion, no);

def London_Q2_hProfile = if London_Q2_aftermarket and IsNaN(London_Q2_vol.GetHighest()) and London_Q2_con then London_Q2_hProfile[1] else London_Q2_vol.GetHighest();
def London_Q2_lProfile = if London_Q2_aftermarket and IsNaN(London_Q2_vol.GetLowest()) and London_Q2_con then London_Q2_lProfile[1] else London_Q2_vol.GetLowest();
def London_Q2_plotsDomain = IsNaN(close) == London_Q2_onExpansion;
def London_Q2_ProfileHigh = if London_Q2_aftermarket and London_Q2_plotsDomain then London_Q2_hProfile else Double.NaN;
def London_Q2_ProfileLow = if London_Q2_aftermarket and London_Q2_plotsDomain then London_Q2_lProfile else Double.NaN;

def londoncount = if basis != basis[1] then  londoncount[1] + 1 else londoncount[1];
def londoncond  = HighestAll(londoncount) - londoncount + 1;
AddVerticalLine (if Show_Vertical_Line  and londoncond <= display_count then London_DrawLine else Double.NaN, "London", CreateColor(153, 153 , 255), Curve.FIRM);

plot London_Q2_hrange = if display_last_zone and londoncond > display_count then Double.NaN else London_Q2_ProfileHigh;
plot London_Q2_lrange = if display_last_zone and londoncond > display_count then Double.NaN else London_Q2_ProfileLow;
London_Q2_hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
London_Q2_lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
London_Q2_hrange.SetDefaultColor(CreateColor(153, 153 , 255));
London_Q2_lrange.SetDefaultColor(CreateColor(153, 153 , 255));
London_Q2_hrange.SetLineWeight(1);
London_Q2_lrange.SetLineWeight(1);
#London_Q2_hrange.Hide();
#London_Q2_lrange.Hide();

def London_Q2_bubblemover = 0;
def London_Q2_b = London_Q2_bubblemover;
def London_Q2_b1 = London_Q2_b + 1;


input London_Q2_showbubbles = no;
AddChartBubble(London_Q2_showbubbles and (IsNaN(London_Q2_hrange[London_Q2_b1]) and London_Q2_hrange[London_Q2_b]) , London_Q2_hrange, AsText(London_Q2_hrange), Color.LIGHT_RED);

AddChartBubble(London_Q2_showbubbles and (IsNaN(London_Q2_hrange[London_Q2_b1]) and London_Q2_hrange[London_Q2_b]) , London_Q2_lrange, AsText(London_Q2_lrange), Color.LIGHT_GREEN, up = no);

input London_Q2_showverticalline = yes;
AddVerticalLine(London_Q2_showverticalline and London_Q2_hrange != London_Q2_hrange[1], "London ", Color.BLUE, stroke = Curve.FIRM);

#Addcloud(hrange, lrange, createcolor(0, 51, 51), createcolor(0, 51, 51));
AddCloud(if Show_Cloud then London_Q2_hrange else Double.NaN, London_Q2_lrange, CreateColor(153, 153 , 255), CreateColor(153, 153 , 255));

AddCloud(if Show_Cloud2 then London_Q2_hrange else Double.NaN, London_Q2_lrange, Color.BLACK, Color.BLACK);


#Addcloud(London_Q2_hrange, London_Q2_lrange, color.black, color.black);

#############################################################################################################
#############################################################################################################

#############################################################################################################
#############################################################################################################
def NY_DrawLine =
#GetDay() == GetLastDay() and
(
!SecondsFromTime(0600)
);

#AddVerticalLine (DrawLine, "", Color.Dark_black,Curve.Long_DASH);


def Show_last = if GetDay() == GetLastDay() then 1 else 0;

#############################################################################################################
#############################################################################################################

#Q3
def NY_Q3_afterbegin = 0600;
def NY_Q3_afterend = 1200;
def NY_Q3_aftermarket = SecondsFromTime(NY_Q3_afterbegin) >= 0 and SecondsTillTime(NY_Q3_afterend) >= 0;
def NY_Q3_bars = 2000;

#input NY_Q3_pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input NY_Q3_pricePerRowHeightMode = { TICKSIZE, default AUTOMATIC, CUSTOM};

def NY_Q3_customRowHeight = 1.0;
input NY_Q3_timePerProfile = {default BAR};
def NY_Q3_onExpansion = no;
def NY_Q3_profiles = 1000;

def NY_Q3_period;

switch (NY_Q3_timePerProfile) {
case BAR:
    NY_Q3_period = BarNumber() - 1;
}


def NY_Q3_count = CompoundValue(1, if NY_Q3_aftermarket and NY_Q3_period != NY_Q3_period[1] then (NY_Q3_count[1] + NY_Q3_period - NY_Q3_period[1]) % NY_Q3_bars else NY_Q3_count[1], 0);
def NY_Q3_cond = NY_Q3_count < NY_Q3_count[1] + NY_Q3_period - NY_Q3_period[1];
def NY_Q3_height;
switch (NY_Q3_pricePerRowHeightMode) {
case AUTOMATIC:
    NY_Q3_height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    NY_Q3_height = PricePerRow.TICKSIZE;
case CUSTOM:
    NY_Q3_height = NY_Q3_customRowHeight;
}

profile NY_Q3_vol = VolumeProfile("startNewProfile" = NY_Q3_cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = NY_Q3_height, "value area percent" = 0);

def NY_Q3_con = CompoundValue(1, NY_Q3_onExpansion, no);

def NY_Q3_hProfile = if NY_Q3_aftermarket and IsNaN(NY_Q3_vol.GetHighest()) and NY_Q3_con then NY_Q3_hProfile[1] else NY_Q3_vol.GetHighest();
def NY_Q3_lProfile = if NY_Q3_aftermarket and IsNaN(NY_Q3_vol.GetLowest()) and NY_Q3_con then NY_Q3_lProfile[1] else NY_Q3_vol.GetLowest();
def NY_Q3_plotsDomain = IsNaN(close) == NY_Q3_onExpansion;
def NY_Q3_ProfileHigh = if NY_Q3_aftermarket and NY_Q3_plotsDomain then NY_Q3_hProfile else Double.NaN;
def NY_Q3_ProfileLow = if NY_Q3_aftermarket and NY_Q3_plotsDomain then NY_Q3_lProfile else Double.NaN;

def nyq3count = if basis != basis[1] then  nyq3count[1] + 1 else nyq3count[1];
def nyq3cond  = HighestAll(nyq3count) - nyq3count + 1;
AddVerticalLine (if Show_Vertical_Line and nyq3cond <= display_count then NY_DrawLine else Double.NaN, "NY AM", CreateColor(0, 153, 255), Curve.FIRM);

plot NY_Q3_hrange = if display_last_zone and nyq3cond > display_count then Double.NaN else NY_Q3_ProfileHigh;
plot NY_Q3_lrange = if display_last_zone and nyq3cond > display_count then Double.NaN else NY_Q3_ProfileLow;
NY_Q3_hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
NY_Q3_lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
NY_Q3_hrange.SetDefaultColor(CreateColor(0, 153, 255));
NY_Q3_lrange.SetDefaultColor(CreateColor(0, 153, 255));
NY_Q3_hrange.SetLineWeight(1);
NY_Q3_lrange.SetLineWeight(1);
#NY_Q3_hrange.Hide();
#NY_Q3_lrange.Hide();

def NY_Q3_bubblemover = 0;
def NY_Q3_b = NY_Q3_bubblemover;
def NY_Q3_b1 = NY_Q3_b + 1;


input NY_Q3_showbubbles = no;
AddChartBubble(NY_Q3_showbubbles and (IsNaN(NY_Q3_hrange[NY_Q3_b1]) and NY_Q3_hrange[NY_Q3_b]) , NY_Q3_hrange, AsText(NY_Q3_hrange), Color.LIGHT_RED);

AddChartBubble(NY_Q3_showbubbles and (IsNaN(NY_Q3_hrange[NY_Q3_b1]) and NY_Q3_hrange[NY_Q3_b]) , NY_Q3_lrange, AsText(NY_Q3_lrange), Color.LIGHT_GREEN, up = no);

input NY_Q3_showverticalline = no;
AddVerticalLine(NY_Q3_showverticalline and NY_Q3_hrange != NY_Q3_hrange[1], "", Color.BLUE, stroke = Curve.FIRM);

#Addcloud(hrange, lrange, createcolor(0, 51, 51), createcolor(0, 51, 51));
AddCloud(if Show_Cloud then NY_Q3_hrange else Double.NaN, NY_Q3_lrange, CreateColor(0, 153, 255), CreateColor(0, 153, 255));

AddCloud(if Show_Cloud2 then NY_Q3_hrange else Double.NaN, NY_Q3_lrange, Color.BLACK, Color.BLACK);

#Addcloud(NY_Q3_hrange, NY_Q3_lrange, color.black, color.black);

#############################################################################################################
#############################################################################################################

def NY_PM_DrawLine =
#GetDay() == GetLastDay() and
(
!SecondsFromTime(1200)
);

#AddVerticalLine (DrawLine, "", Color.Dark_black,Curve.Long_DASH);



#############################################################################################################
#############################################################################################################

#Q4
def NY_PM_Q4_afterbegin = 1200;
def NY_PM_Q4_afterend = 1800;
def NY_PM_Q4_aftermarket = SecondsFromTime(NY_PM_Q4_afterbegin) >= 0 and SecondsTillTime(NY_PM_Q4_afterend) >= 0;
def NY_PM_Q4_bars = 2000;

#input NY_PM_Q4_pricePerRowHeightMode = { AUTOMATIC, default TICKSIZE, CUSTOM};
input NY_PM_Q4_pricePerRowHeightMode = { TICKSIZE, default AUTOMATIC, CUSTOM};

def NY_PM_Q4_customRowHeight = 1.0;
input NY_PM_Q4_timePerProfile = {default BAR};
def NY_PM_Q4_onExpansion = no;
def NY_PM_Q4_profiles = 1000;

def NY_PM_Q4_period;

switch (NY_PM_Q4_timePerProfile) {
case BAR:
    NY_PM_Q4_period = BarNumber() - 1;
}


def NY_PM_Q4_count = CompoundValue(1, if NY_PM_Q4_aftermarket and NY_PM_Q4_period != NY_PM_Q4_period[1] then (NY_PM_Q4_count[1] + NY_PM_Q4_period - NY_PM_Q4_period[1]) % NY_PM_Q4_bars else NY_PM_Q4_count[1], 0);
def NY_PM_Q4_cond = NY_PM_Q4_count < NY_PM_Q4_count[1] + NY_PM_Q4_period - NY_PM_Q4_period[1];
def NY_PM_Q4_height;
switch (NY_PM_Q4_pricePerRowHeightMode) {
case AUTOMATIC:
    NY_PM_Q4_height = PricePerRow.AUTOMATIC;
case TICKSIZE:
    NY_PM_Q4_height = PricePerRow.TICKSIZE;
case CUSTOM:
    NY_PM_Q4_height = NY_PM_Q4_customRowHeight;
}

profile NY_PM_Q4_vol = VolumeProfile("startNewProfile" = NY_PM_Q4_cond, "onExpansion" = no, "numberOfProfiles" = 1000, "pricePerRow" = NY_PM_Q4_height, "value area percent" = 0);

def NY_PM_Q4_con = CompoundValue(1, NY_PM_Q4_onExpansion, no);

def NY_PM_Q4_hProfile = if NY_PM_Q4_aftermarket and IsNaN(NY_PM_Q4_vol.GetHighest()) and NY_PM_Q4_con then NY_PM_Q4_hProfile[1] else NY_PM_Q4_vol.GetHighest();
def NY_PM_Q4_lProfile = if NY_PM_Q4_aftermarket and IsNaN(NY_PM_Q4_vol.GetLowest()) and NY_PM_Q4_con then NY_PM_Q4_lProfile[1] else NY_PM_Q4_vol.GetLowest();
def NY_PM_Q4_plotsDomain = IsNaN(close) == NY_PM_Q4_onExpansion;
def NY_PM_Q4_ProfileHigh = if NY_PM_Q4_aftermarket and NY_PM_Q4_plotsDomain then NY_PM_Q4_hProfile else Double.NaN;
def NY_PM_Q4_ProfileLow = if NY_PM_Q4_aftermarket and NY_PM_Q4_plotsDomain then NY_PM_Q4_lProfile else Double.NaN;

def nyq4count = if basis != basis[1] then  nyq4count[1] + 1 else nyq4count[1];
def nyq4cond  = HighestAll(nyq4count) - nyq4count + 1;
AddVerticalLine (if Show_Vertical_Line and nyq4cond <= display_count then NY_PM_DrawLine else Double.NaN, "NY PM", CreateColor(255, 153, 102), Curve.FIRM);


plot NY_PM_Q4_hrange = if display_last_zone and nyq4cond > display_count then Double.NaN else NY_PM_Q4_ProfileHigh;
plot NY_PM_Q4_lrange = if display_last_zone and nyq4cond > display_count then Double.NaN else NY_PM_Q4_ProfileLow;
NY_PM_Q4_hrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
NY_PM_Q4_lrange.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
NY_PM_Q4_hrange.SetDefaultColor(CreateColor(255, 153, 102));
NY_PM_Q4_lrange.SetDefaultColor(CreateColor(255, 153, 102));
NY_PM_Q4_hrange.SetLineWeight(1);
NY_PM_Q4_lrange.SetLineWeight(1);
#NY_PM_Q4_hrange.Hide();
#NY_PM_Q4_lrange.Hide();

def NY_PM_Q4_bubblemover = 0;
def NY_PM_Q4_b = NY_PM_Q4_bubblemover;
def NY_PM_Q4_b1 = NY_PM_Q4_b + 1;


input NY_PM_Q4_showbubbles = no;
AddChartBubble(NY_PM_Q4_showbubbles and (IsNaN(NY_PM_Q4_hrange[NY_PM_Q4_b1]) and NY_PM_Q4_hrange[NY_PM_Q4_b]) , NY_PM_Q4_hrange, AsText(NY_PM_Q4_hrange), Color.LIGHT_RED);

AddChartBubble(NY_PM_Q4_showbubbles and (IsNaN(NY_PM_Q4_hrange[NY_PM_Q4_b1]) and NY_PM_Q4_hrange[NY_PM_Q4_b]) , NY_PM_Q4_lrange, AsText(NY_PM_Q4_lrange), Color.LIGHT_GREEN, up = no);

input NY_PM_Q4_showverticalline = no;
AddVerticalLine(NY_PM_Q4_showverticalline and NY_PM_Q4_hrange != NY_PM_Q4_hrange[1], "", Color.BLUE, stroke = Curve.FIRM);

#Addcloud(hrange, lrange, createcolor(0, 51, 51), createcolor(0, 51, 51));
AddCloud(if Show_Cloud then NY_PM_Q4_hrange else Double.NaN, NY_PM_Q4_lrange, CreateColor(255, 153, 102), CreateColor(255, 153, 102));

AddCloud(if Show_Cloud2 then NY_PM_Q4_hrange else Double.NaN, NY_PM_Q4_lrange, Color.BLACK, Color.BLACK);

#Addcloud(NY_PM_Q4_hrange, NY_PM_Q4_lrange, color.black, color.black);

#############################################################################################################
#############################################################################################################

#-----------------


addlabel(1, "  ", color.black);
# Asian_Q1_ProfileHigh
# Asian_Q1_Profilelow
def asiahi = if isnan(Asian_Q1_ProfileHigh) then asiahi[1] else Asian_Q1_ProfileHigh;
def asialo = if isnan(Asian_Q1_Profilelow) then asialo[1] else Asian_Q1_Profilelow;
addlabel(1, "asia hi " + asiahi, (if isnan(Asian_Q1_ProfileHigh) then color.gray else color.yellow));
addlabel(1, "asia lo " + asialo, (if isnan(Asian_Q1_Profilelow) then color.gray else color.yellow));

addlabel(1, "  ", color.black);
#London_Q2_ProfileHigh
#London_Q2_Profilelow
def lonhi = if isnan(London_Q2_ProfileHigh) then lonhi[1] else London_Q2_ProfileHigh;
def lonlo = if isnan(London_Q2_Profilelow) then lonlo[1] else London_Q2_Profilelow;
addlabel(1, "london hi " + lonhi, (if isnan(London_Q2_ProfileHigh) then color.gray else color.yellow));
addlabel(1, "london lo " + lonlo, (if isnan(London_Q2_Profilelow) then color.gray else color.yellow));

addlabel(1, "  ", color.black);
#NY_Q3_ProfileHigh
#NY_Q3_Profilelow
def nyamhi = if isnan(NY_Q3_ProfileHigh) then nyamhi[1] else NY_Q3_ProfileHigh;
def nyamlo = if isnan(NY_Q3_Profilelow) then nyamlo[1] else NY_Q3_Profilelow;
addlabel(1, "NY am hi " + nyamhi, (if isnan(NY_Q3_ProfileHigh) then color.gray else color.yellow));
addlabel(1, "NY am lo " + nyamlo, (if isnan(NY_Q3_Profilelow) then color.gray else color.yellow));

addlabel(1, "  ", color.black);
#NY_PM_Q4_ProfileHigh
#NY_PM_Q4_Profilelow
def nypmhi = if isnan(NY_PM_Q4_ProfileHigh) then nypmhi[1] else NY_PM_Q4_ProfileHigh;
def nypmlo = if isnan(NY_PM_Q4_Profilelow) then nypmlo[1] else NY_PM_Q4_Profilelow;
addlabel(1, "NY pm hi " + nypmhi, (if isnan(NY_PM_Q4_ProfileHigh) then color.gray else color.yellow));
addlabel(1, "NY pm lo " + nypmlo, (if isnan(NY_PM_Q4_Profilelow) then color.gray else color.yellow));
addlabel(1, "  ", color.black);
#
This is exactly what I was looking for. Thanks! It would be good to have this code merged into original thread. I think I modified code with diff variables and hence it was not clear in my question. But this answer is PERFECT!
 
I am completely new at this and any help would be great. I would like to create a simple bollinger band indicator but that would show the 5min values in the 1 minute timeframe. my issue is that unable to correctly sum the candles without re-counting the closing prices of the already counted bars or leaving some out. I am unable to use the regular functions because they would recount the same bars already counted. Below is the equation for bollinger bands

# Bollinger Bands Calculation
def sDev = stdev(price, length);
def midLine = SimpleMovingAvg(price, length);
def upperBand = midLine + numDev * sDev;
def lowerBand = midLine - numDev * sDev;

This is my code so far.
# Define the length and standard deviation multiplier for Bollinger Bands
input length = 20;
input numDev = 2.0;

# Initialize variables for manual calculation
def price = close;
def count = 5; # Number of 1-minute bars in 5 minutes

# Manually aggregate the 5-minute closing prices
def fiveMinClose = if (SecondsFromTime(0) % (count * 60) == 0) then price else fiveMinClose[1];

# Manually calculate the 5-minute simple moving average
def sumClose = fold j = 0 to length - 1 with sum = 0 do sum + GetValue(fiveMinClose, j);
def fiveMinSMA = sumClose / length;

# Manually calculate the standard deviation
def sumSqDiff = fold k = 0 to length - 1 with sqSum = 0 do sqSum + Sqr(GetValue(fiveMinClose, k) - fiveMinSMA);
def fiveMinStdDev = Sqrt(sumSqDiff / length);

# Calculate the Bollinger Bands
def upperBand = fiveMinSMA + numDev * fiveMinStdDev;
def lowerBand = fiveMinSMA - numDev * fiveMinStdDev;

# Plot the Bollinger Bands on the 1-minute chart
plot UpperBand1 = upperBand;
plot LowerBand1 = lowerBand;
plot MiddleBand1 = fiveMinSMA;

# Customize the plot appearance
UpperBand1.SetDefaultColor(Color.RED);
LowerBand1.SetDefaultColor(Color.GREEN);
MiddleBand1.SetDefaultColor(Color.BLUE);
 
I am completely new at this and any help would be great. I would like to create a simple bollinger band indicator but that would show the 5min values in the 1 minute timeframe. my issue is that unable to correctly sum the candles without re-counting the closing prices of the already counted bars or leaving some out. I am unable to use the regular functions because they would recount the same bars already counted. Below is the equation for bollinger bands

# Bollinger Bands Calculation
def sDev = stdev(price, length);
def midLine = SimpleMovingAvg(price, length);
def upperBand = midLine + numDev * sDev;
def lowerBand = midLine - numDev * sDev;

This is my code so far.
# Define the length and standard deviation multiplier for Bollinger Bands
input length = 20;
input numDev = 2.0;

# Initialize variables for manual calculation
def price = close;
def count = 5; # Number of 1-minute bars in 5 minutes

# Manually aggregate the 5-minute closing prices
def fiveMinClose = if (SecondsFromTime(0) % (count * 60) == 0) then price else fiveMinClose[1];

# Manually calculate the 5-minute simple moving average
def sumClose = fold j = 0 to length - 1 with sum = 0 do sum + GetValue(fiveMinClose, j);
def fiveMinSMA = sumClose / length;

# Manually calculate the standard deviation
def sumSqDiff = fold k = 0 to length - 1 with sqSum = 0 do sqSum + Sqr(GetValue(fiveMinClose, k) - fiveMinSMA);
def fiveMinStdDev = Sqrt(sumSqDiff / length);

# Calculate the Bollinger Bands
def upperBand = fiveMinSMA + numDev * fiveMinStdDev;
def lowerBand = fiveMinSMA - numDev * fiveMinStdDev;

# Plot the Bollinger Bands on the 1-minute chart
plot UpperBand1 = upperBand;
plot LowerBand1 = lowerBand;
plot MiddleBand1 = fiveMinSMA;

# Customize the plot appearance
UpperBand1.SetDefaultColor(Color.RED);
LowerBand1.SetDefaultColor(Color.GREEN);
MiddleBand1.SetDefaultColor(Color.BLUE);

reply to 389

take a look at this
https://usethinkscript.com/threads/bollinger-bands-mtf-multi-time-frame-for-thinkorswim.259/
searched mtf bollinger
 
Trying to find trends of times when stocks go up. Not sure if this is working like it should. Here is the code:

input daysBack = 10;
input forwardMinutes = 30;
input probabilityThreshold = 0.6;
input dollarMove = 1.20; # Change this value to test for different dollar moves

# Define three times (in 24-hour format)
input hour1 = 6;
input minute1 = 30;
input hour2 = 8;
input minute2 = 0;
input hour3 = 11;
input minute3 = 45;

def barSize = 5; # set this to your chart resolution in minutes
def forwardBars = forwardMinutes / barSize;

# Time match helpers
def time1 = SecondsFromTime(hour1 * 100 + minute1);
def time2 = SecondsFromTime(hour2 * 100 + minute2);
def time3 = SecondsFromTime(hour3 * 100 + minute3);

def isTime1 = time1 == 0;
def isTime2 = time2 == 0;
def isTime3 = time3 == 0;

# Unique day counter
def isNewDay = GetDay() != GetDay()[1];
def dayCounter = if isNewDay then dayCounter[1] + 1 else dayCounter[1];
def isToday = dayCounter == HighestAll(dayCounter);

# Function-like logic for each time slot
# Check if the stock increased by at least $1 from the target time
def wentUp1 = if isTime1 and close[forwardBars] >= close + dollarMove then 1 else 0;
def wentUp2 = if isTime2 and close[forwardBars] >= close + dollarMove then 1 else 0;
def wentUp3 = if isTime3 and close[forwardBars] >= close + dollarMove then 1 else 0;

# Alternative check (checking 2 or 3 bars after the time) for more flexibility
def wentUp1Alt = if isTime1 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;
def wentUp2Alt = if isTime2 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;
def wentUp3Alt = if isTime3 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;

# Use either the original or alternative logic
def wentUp1Final = wentUp1 or wentUp1Alt;
def wentUp2Final = wentUp2 or wentUp2Alt;
def wentUp3Final = wentUp3 or wentUp3Alt;

# Count occurrences
def count1 = if isTime1 then 1 else 0;
def count2 = if isTime2 then 1 else 0;
def count3 = if isTime3 then 1 else 0;

# Cumulative totals
def upSum1 = TotalSum(wentUp1Final);
def total1 = TotalSum(count1);
def prob1 = if total1 > 0 then upSum1 / total1 else 0;

def upSum2 = TotalSum(wentUp2Final);
def total2 = TotalSum(count2);
def prob2 = if total2 > 0 then upSum2 / total2 else 0;

def upSum3 = TotalSum(wentUp3Final);
def total3 = TotalSum(count3);
def prob3 = if total3 > 0 then upSum3 / total3 else 0;

# Plot arrows only on today's matching time if probability is high enough
plot Arrow1 = if isToday and isTime1 and prob1 > probabilityThreshold then low else Double.NaN;
Arrow1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow1.SetDefaultColor(Color.GREEN);

plot Arrow2 = if isToday and isTime2 and prob2 > probabilityThreshold then low else Double.NaN;
Arrow2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow2.SetDefaultColor(Color.BLUE);

plot Arrow3 = if isToday and isTime3 and prob3 > probabilityThreshold then low else Double.NaN;
Arrow3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow3.SetDefaultColor(Color.ORANGE);

# Show probability in chart label
AddLabel(yes, "Approx 6:30 Prob Increase $1", if prob1 > probabilityThreshold then Color.GREEN else Color.GRAY);
AddLabel(yes, " Approx 8:00 Prob Increase $1: ", if prob2 > probabilityThreshold then Color.BLUE else Color.GRAY);
AddLabel(yes, "Approx 11:45 Prob Increase $1: ", if prob3 > probabilityThreshold then Color.ORANGE else Color.GRAY);
 
Hi all!

I'm trying to make a scan to find stocks that are in a squeeze within 20 cents of ORB levels (squeeze above the 30 minute high, squeeze below the 30 minute low).. with ChatGPT, I got this but it doesn't seem to work properly. Some stocks coming up ARE in the correct spot, but some are not. Attached is a photo of MRNA today, 4/7 on the 1 minute chart. This is the ideal setup I'm looking for (purple candles on the right). Any help would be greatly appreciated!

Screen Shot 2025-04-07 at 12.04.54 PM.png


Code:
def marketOpen = 0930;
def firstBar = SecondsFromTime(marketOpen * 100) < 1800;
def thirtyMinHigh = Highest(high, 30);
def thirtyMinLow = Lowest(low, 30);

def inSqueeze = TTM_Squeeze().SqueezeAlert == 0;

def withinHighRange = AbsValue(close - thirtyMinHigh) <= 0.20;
def withinLowRange = AbsValue(close - thirtyMinLow) <= 0.20;

plot scan = inSqueeze and (withinHighRange or withinLowRange);
 
Trying to find trends of times when stocks go up. Not sure if this is working like it should. Here is the code:

input daysBack = 10;
input forwardMinutes = 30;
input probabilityThreshold = 0.6;
input dollarMove = 1.20; # Change this value to test for different dollar moves

# Define three times (in 24-hour format)
input hour1 = 6;
input minute1 = 30;
input hour2 = 8;
input minute2 = 0;
input hour3 = 11;
input minute3 = 45;

def barSize = 5; # set this to your chart resolution in minutes
def forwardBars = forwardMinutes / barSize;

# Time match helpers
def time1 = SecondsFromTime(hour1 * 100 + minute1);
def time2 = SecondsFromTime(hour2 * 100 + minute2);
def time3 = SecondsFromTime(hour3 * 100 + minute3);

def isTime1 = time1 == 0;
def isTime2 = time2 == 0;
def isTime3 = time3 == 0;

# Unique day counter
def isNewDay = GetDay() != GetDay()[1];
def dayCounter = if isNewDay then dayCounter[1] + 1 else dayCounter[1];
def isToday = dayCounter == HighestAll(dayCounter);

# Function-like logic for each time slot
# Check if the stock increased by at least $1 from the target time
def wentUp1 = if isTime1 and close[forwardBars] >= close + dollarMove then 1 else 0;
def wentUp2 = if isTime2 and close[forwardBars] >= close + dollarMove then 1 else 0;
def wentUp3 = if isTime3 and close[forwardBars] >= close + dollarMove then 1 else 0;

# Alternative check (checking 2 or 3 bars after the time) for more flexibility
def wentUp1Alt = if isTime1 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;
def wentUp2Alt = if isTime2 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;
def wentUp3Alt = if isTime3 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;

# Use either the original or alternative logic
def wentUp1Final = wentUp1 or wentUp1Alt;
def wentUp2Final = wentUp2 or wentUp2Alt;
def wentUp3Final = wentUp3 or wentUp3Alt;

# Count occurrences
def count1 = if isTime1 then 1 else 0;
def count2 = if isTime2 then 1 else 0;
def count3 = if isTime3 then 1 else 0;

# Cumulative totals
def upSum1 = TotalSum(wentUp1Final);
def total1 = TotalSum(count1);
def prob1 = if total1 > 0 then upSum1 / total1 else 0;

def upSum2 = TotalSum(wentUp2Final);
def total2 = TotalSum(count2);
def prob2 = if total2 > 0 then upSum2 / total2 else 0;

def upSum3 = TotalSum(wentUp3Final);
def total3 = TotalSum(count3);
def prob3 = if total3 > 0 then upSum3 / total3 else 0;

# Plot arrows only on today's matching time if probability is high enough
plot Arrow1 = if isToday and isTime1 and prob1 > probabilityThreshold then low else Double.NaN;
Arrow1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow1.SetDefaultColor(Color.GREEN);

plot Arrow2 = if isToday and isTime2 and prob2 > probabilityThreshold then low else Double.NaN;
Arrow2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow2.SetDefaultColor(Color.BLUE);

plot Arrow3 = if isToday and isTime3 and prob3 > probabilityThreshold then low else Double.NaN;
Arrow3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow3.SetDefaultColor(Color.ORANGE);

# Show probability in chart label
AddLabel(yes, "Approx 6:30 Prob Increase $1", if prob1 > probabilityThreshold then Color.GREEN else Color.GRAY);
AddLabel(yes, " Approx 8:00 Prob Increase $1: ", if prob2 > probabilityThreshold then Color.BLUE else Color.GRAY);
AddLabel(yes, "Approx 11:45 Prob Increase $1: ", if prob3 > probabilityThreshold then Color.ORANGE else Color.GRAY);

reply to 391

i am not sure what you want.
i changed a couple things. replaced constants with variables.
add vertical lines

it draws arrows sometimes
the times should be adjusted for a different time zone

Code:
#chat391_find_trends
#https://usethinkscript.com/threads/chatgpt-bard-other-ai-scripts-which-cant-be-used-in-thinkorswim.13822/page-20#post-152298
#391
#Trying to find trends of times when stocks go up. Not sure if this is working like it should. Here is the code:


input daysBack = 10;
input forwardMinutes = 30;
input probabilityThreshold = 0.6;
input dollarMove = 1.20; # Change this value to test for different dollar moves

# Define three times (in 24-hour format)
input hour1 = 6;
input minute1 = 30;
input hour2 = 8;
input minute2 = 0;
input hour3 = 11;
input minute3 = 45;

#def barSize = 5; # set this to your chart resolution in minutes
# get chart minutes
#---------------------------------
# get chart agg time
def chartagg = getaggregationperiod();
def chartmin = chartagg/(1000*60);
#---------------------------------
def barSize = chartmin;
def forwardBars = forwardMinutes / barSize;


# Time match helpers
def time1 = SecondsFromTime(hour1 * 100 + minute1);
def time2 = SecondsFromTime(hour2 * 100 + minute2);
def time3 = SecondsFromTime(hour3 * 100 + minute3);

def isTime1 = time1 == 0;
def isTime2 = time2 == 0;
def isTime3 = time3 == 0;

# nearest bar
# def start = 0930;
# def x = SecondsFromTime(start)[1] < 0 and SecondsFromTime(start) >= 0;


addverticalline(istime1, "-", color.cyan);
addverticalline(istime2, "-", color.cyan);
addverticalline(istime3, "-", color.cyan);

addchartbubble(0, 235,
istime1 + "\n" +
istime2 + "\n" +
istime3 + "\n" 
, (if istime1 or istime2 or istime3 then color.yellow else color.gray),no);


# Unique day counter
def isNewDay = GetDay() != GetDay()[1];
#def dayCounter = if isNewDay then dayCounter[1] + 1 else dayCounter[1];
#def isToday = dayCounter == HighestAll(dayCounter);

# new formula. gets rid of highestall and complex icon
def istoday = GetDay() == GetlastDay();


# Function-like logic for each time slot
# Check if the stock increased by at least $1 from the target time
def wentUp1 = if isTime1 and close[forwardBars] >= close + dollarMove then 1 else 0;
def wentUp2 = if isTime2 and close[forwardBars] >= close + dollarMove then 1 else 0;
def wentUp3 = if isTime3 and close[forwardBars] >= close + dollarMove then 1 else 0;

# Alternative check (checking 2 or 3 bars after the time) for more flexibility
def wentUp1Alt = if isTime1 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;
def wentUp2Alt = if isTime2 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;
def wentUp3Alt = if isTime3 and (close[1] >= close + dollarMove or close[2] >= close + dollarMove) then 1 else 0;

# Use either the original or alternative logic
def wentUp1Final = wentUp1 or wentUp1Alt;
def wentUp2Final = wentUp2 or wentUp2Alt;
def wentUp3Final = wentUp3 or wentUp3Alt;

# Count occurrences
def count1 = if isTime1 then 1 else 0;
def count2 = if isTime2 then 1 else 0;
def count3 = if isTime3 then 1 else 0;

# Cumulative totals
def upSum1 = TotalSum(wentUp1Final);
def total1 = TotalSum(count1);
def prob1 = if total1 > 0 then upSum1 / total1 else 0;

def upSum2 = TotalSum(wentUp2Final);
def total2 = TotalSum(count2);
def prob2 = if total2 > 0 then upSum2 / total2 else 0;

def upSum3 = TotalSum(wentUp3Final);
def total3 = TotalSum(count3);
def prob3 = if total3 > 0 then upSum3 / total3 else 0;

# Plot arrows only on today's matching time if probability is high enough
plot Arrow1 = if isToday and isTime1 and prob1 > probabilityThreshold then low else Double.NaN;
Arrow1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow1.SetDefaultColor(Color.GREEN);
arrow1.setlineweight(3);

plot Arrow2 = if isToday and isTime2 and prob2 > probabilityThreshold then low else Double.NaN;
Arrow2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow2.SetDefaultColor(Color.BLUE);
arrow2.setlineweight(3);

plot Arrow3 = if isToday and isTime3 and prob3 > probabilityThreshold then low else Double.NaN;
Arrow3.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
Arrow3.SetDefaultColor(Color.ORANGE);
arrow3.setlineweight(3);

addlabel(1, " ", color.black);
# Show probability in chart label
#AddLabel(yes, "Approx 6:30 Prob Increase $1", if prob1 > probabilityThreshold then Color.GREEN else Color.GRAY);
#AddLabel(yes, " Approx 8:00 Prob Increase $1: ", if prob2 > probabilityThreshold then Color.BLUE else Color.GRAY);
#AddLabel(yes, "Approx 11:45 Prob Increase $1: ", if prob3 > probabilityThreshold then Color.ORANGE else Color.GRAY);
AddLabel(yes, "Approx " + (hour1 + ":" + minute1) + " Prob Increase $1", if prob1 > probabilityThreshold then Color.GREEN else Color.GRAY);
AddLabel(yes, " Approx " + (hour2 + ":" + minute2) + " Prob Increase $1: ", if prob2 > probabilityThreshold then Color.BLUE else Color.GRAY);
AddLabel(yes, "Approx " + (hour3 + ":" + minute3) + " Prob Increase $1: ", if prob3 > probabilityThreshold then Color.ORANGE else Color.GRAY);


input test1_prob_bubbles = no;
addchartbubble(test1_prob_bubbles, low*0.98,
 prob1 + "\n" +
 prob2 + "\n" +
 prob3 + "\n" +
 probabilityThreshold
, (if prob1 > probabilityThreshold then Color.GREEN else
  if prob2 > probabilityThreshold then Color.BLUE else
  if prob3 > probabilityThreshold then Color.ORANGE else Color.GRAY), no);
#
 
I am new to using ToS forum, so I am unsure if I am in the right place.

I am looking for help writing a script for the charts tab. I am trying to create a "Return on Investment" line that follows the price chart.
The code I am using makes the price chart go away, I don't know why. There are no errors.
This is the code I am using.

Code:
# Define the starting price
def startingPrice = open(period = AggregationPeriod.DAY); # You can replace this value with the actual starting price

# Calculate the ROI
def currentPrice = close;
def roi = ((currentPrice - startingPrice) / startingPrice) * 100;

# Plot the ROI on the chart
plot ROIs = roi;
ROIs.SetDefaultColor(Color.GREEN);
ROIs.SetLineWeight(2);

# Display the ROI value
AddLabel(yes, "ROI: " + AsPercent(ROIs / 100), Color.YELLOW);
 
Last edited by a moderator:
I am new to using ToS forum, so I am unsure if I am in the right place.

I am looking for help writing a script for the charts tab. I am trying to create a "Return on Investment" line that follows the price chart.
The code I am using makes the price chart go away, I don't know why. There are no errors.
This is the code I am using.

Code:
# Define the starting price
def startingPrice = open(period = AggregationPeriod.DAY); # You can replace this value with the actual starting price

# Calculate the ROI
def currentPrice = close;
def roi = ((currentPrice - startingPrice) / startingPrice) * 100;

# Plot the ROI on the chart
plot ROIs = roi;
ROIs.SetDefaultColor(Color.GREEN);
ROIs.SetLineWeight(2);

# Display the ROI value
AddLabel(yes, "ROI: " + AsPercent(ROIs / 100), Color.YELLOW);

Works fine on my 3D 3m Chart...
pXwZ34r.png
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
393 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top