write a strategy code for thinkorswim that incorporates supply and demand and volume profile
ChatGPT's reply :
As an AI language model, I can provide you with a sample code that incorporates both supply and demand and volume profile concepts for Thinkorswim. Please note that this is only an example code and you should always consult with a professional trader or financial advisor before implementing any trading strategies.
This code uses Thinkorswim's built-in functions for volume profile and supply and demand analysis to plot zones on the chart where price may experience support or resistance. The script also generates signals when the price crosses these zones, and can alert you when these signals occur. Keep in mind that this is only one possible implementation of supply and demand and volume profile concepts, and you should always backtest and adjust the strategy to fit your personal trading style and risk tolerance.
When I copied and pasted in strategies ,
I need help with this script Iget an error
input aggregationPeriod = AggregationPeriod.DAY;
input showVolume = yes;
input showOpenInterest = yes;
def o = open;
def h = high;
def l = low;
def c = close;
def v = volume;
def oi = open_interest;
def isPeriodRolled = CompoundValue(1, (GetAggregationPeriod() <> GetAggregationPeriod()[1]), yes);
def volumeSum;
def oiSum;
if (isPeriodRolled) {
volumeSum = v;
oiSum = oi;
} else {
volumeSum = volumeSum[1] + v;
oiSum = oiSum[1] + oi;
}
def label = "OI: " + oiSum + "\n";
label = label + "P/C: " + Round((PutVolume() / CallVolume()) * 100, 0) + "%\n";
label = label + "Vol: " + volumeSum;
AddLabel(yes, label, Color.WHITE);
plot openInterest = showOpenInterest;
openInterest.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
openInterest.SetDefaultColor(Color.ORANGE);
def pcRatio = showVolume(PutVolume() / CallVolume())/
Double.NaN;
def volume = showVolume; (volumesum); Double.NaN;
AddCloud(volume, pcRatio, Color.GREEN, Color.RED);
Hello.
Zero coding experience here, just fetching indicators from ChatGPT. I continue to run into this problem, and no matter how much ChatGPT troubleshoots itself, it cannot fix the issue. I am trying to create an indicator that plots a red down arrow on top of a candle when Polarized Fractal Efficiency is greater than 80, and RSI is less than 75.
It seems to have no problem coding the RSI part, but when I introduce the Polarized Fractal Efficiency part, it begins creating code with errors. Here is the transcript.
Me: Using thinkscript, create an indicator that places a down red arrow above the candle when RSI is less than 75
ChatGPT:
# Define input parameters
input length = 14;
input oversold = 30;
input overbought = 70;
# Calculate RSI
def NetChgAvg = MovingAverage(AverageType.EXPONENTIAL, close - close[1], length);
def TotChgAvg = MovingAverage(AverageType.EXPONENTIAL, AbsValue(close - close[1]), length);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
# Define conditions for arrow
def arrow_condition = RSI < 75;
# Plot arrow
plot Arrow = if arrow_condition then high + 1 else Double.NaN;
Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
Arrow.SetLineWeight(1);
Arrow.AssignValueColor(if arrow_condition then Color.RED else Color.GRAY);
This script first calculates the RSI based on the input length and overbought/oversold levels. It then defines a condition for when the arrow should be plotted (in this case, when RSI is less than 75). Finally, it plots a down red arrow above the candle when the condition is met. You can adjust the input parameters to customize the script to your liking.
Me: Now add to it, that Polarized Fractal Efficiency must be greater than 80
ChatGPT:
declare lower;
input length = 10;
def pfe = TotalSum((2 * length - 1) * AbsValue(close - close[1]) / (length * TotalSum(AbsValue(close - close[1]), length)), length) * 100;
plot RSI_condition = RSI() < 75;
plot PFE_condition = pfe > 80;
plot arrow = if RSI_condition and PFE_condition then high + 2 else Double.NaN;
arrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
arrow.SetLineWeight(3);
arrow.AssignValueColor(Color.RED);
Note that pfe is defined as a variable using the same formula as before. The RSI() function is used to check if the RSI is less than 75. Both conditions are then used to plot the arrow above the candle if they are met.
These are the errors that came up:
1 params expected but 2 found while calling totalsum at 7:97
1 params expected but 2 found while calling totalsum at 7:30
1 params expected but 2 found while calling totalsum at 7:97
1 params expected but 2 found while calling totalsum at 7:30
ChatGPT:
It seems like there is an issue with the TotalSum() function. The error message says that it is expecting only one parameter but it found two. This usually happens when the function is being passed more arguments than it should. Please double-check that the TotalSum() function is being passed only one argument.
Here's the updated script for the indicator:
declare lower;
input length = 10;
def rsi = reference RSI(length = 14);
plot arrow = if rsi < 75 and TotalSum((2 * length - 1) * AbsValue(close - close[1]) / (length * TotalSum(AbsValue(close - close[1]), length)), length) * 100 > 80 then high + 2 else Double.NaN;
arrow.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
arrow.SetLineWeight(3);
arrow.AssignValueColor(Color.RED);
This new code it generated also didn't work. It seems to have continuous trouble with that "TotalSum" line. Of course, I know nothing of what this means and would appreciate any help. Thanks guys!
#chat_totalsum_ver1
#https://usethinkscript.com/threads/chatgpt-and-totalsum-errors.15021/
#Me: Using thinkscript, create an indicator that,
# places a down red arrow above the candle,
# when RSI is less than 75
#ChatGPT:
# Define input parameters
# rsi----------------------------
input rsilen = 14;
input oversold = 30;
input overbought = 70;
def NetChgAvg = MovingAverage(AverageType.EXPONENTIAL, close - close[1], rsilen);
def TotChgAvg = MovingAverage(AverageType.EXPONENTIAL, AbsValue(close - close[1]), rsilen);
def ChgRatio = if TotChgAvg != 0 then NetChgAvg / TotChgAvg else 0;
def RSI = 50 * (ChgRatio + 1);
#--------------------------------
input rsinum = 75;
# Define conditions for arrow
def rsi_cond = RSI < rsinum;
# Plot arrow
#plot Arrow = if arrow_condition then high + 1 else Double.NaN;
#Arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#Arrow.SetLineWeight(1);
#Arrow.AssignValueColor(if arrow_condition then Color.RED else Color.GRAY);
#This script first calculates the RSI based on the input length and overbought/oversold levels. It then defines a condition for when the arrow should be plotted (in this case, when RSI is less than 75). Finally, it plots a down red arrow above the candle when the condition is met. You can adjust the input parameters to customize the script to your liking.
#Me: Now add to it, that Polarized Fractal Efficiency must be greater than 80
#ChatGPT:
#declare lower;
input pfelen = 10;
input pfenum = 80;
#def pfe = TotalSum((2 * pfelen - 1) * AbsValue(close - close[1]) / (pfelen * TotalSum(AbsValue(close - close[1]), length)), length) * 100;
def pfe = TotalSum((2 * pfelen - 1) * AbsValue(close - close[1]) / (pfelen * TotalSum(AbsValue(close - close[1]) ))) * 100;
def pfe_cond = pfe > pfenum;
plot arrow = if RSI_cond and PFE_cond then high * (1+0.002) else Double.NaN;
arrow.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
arrow.SetLineWeight(3);
arrow.AssignValueColor(Color.RED);
#Note that pfe is defined as a variable using the same formula as before. The RSI() function is used to check if the RSI is less than 75. Both conditions are then used to plot the arrow above the candle if they are met.
input test1 = no;
addchartbubble(test1,low,
round(rsi,0) + " rsi\n" +
round(pfe,0) + " pfe"
, color.yellow, no);
#
# Technical and Fundamental Breakout Scanner on Daily Bar
# Inputs
input technicalBreakoutThreshold = 2.0; # Technical breakout threshold
input fundamentalBreakoutThreshold = 5.0; # Fundamental breakout threshold
input technicalIndicators = {default "ADX", "ATR", "Bollinger Bands", "MACD", "RSI", "Stochastic", "Volume Average"}; # Technical indicators to use
input movingAverageType = {default Simple, Exponential}; # Moving average type
input movingAverageLength = 20; # Moving average length
input movingAveragePrice = {default close, high, low, open, median}; # Moving average price
# Technical indicators
def adx = DMI(14).ADX;
def atr = ATR(14);
def upperBB = BollingerBands().UpperBand;
def lowerBB = BollingerBands().LowerBand;
def macd = MACD();
def rsi = RSI();
def stochastic = StochasticFull();
def volumeAvg = Average(volume, 20);
# Fundamental indicators
def marketCap = Fundamental(FundamentalType.MARKETCAP);
def revenue = Fundamental(FundamentalType.REVENUE);
def grossProfitMargin = Fundamental(FundamentalType.GROSSPROFITMARGIN);
def netProfitMargin = Fundamental(FundamentalType.NETPROFITMARGIN);
def eps = Fundamental(FundamentalType.EARNINGS);
# Technical breakout criteria
def technicalBreakout =
if "ADX" in technicalIndicators and adx > technicalBreakoutThreshold then 1 else 0 +
if "ATR" in technicalIndicators and close > close[1] + (atr * technicalBreakoutThreshold) then 1 else 0 +
if "Bollinger Bands" in technicalIndicators and close > upperBB then 1 else if close < lowerBB then -1 else 0 +
if "MACD" in technicalIndicators and macd > 0 then 1 else if macd < 0 then -1 else 0 +
if "RSI" in technicalIndicators and rsi > 50 then 1 else if rsi < 50 then -1 else 0 +
if "Stochastic" in technicalIndicators and stochastic > 80 then 1 else if stochastic < 20 then -1 else 0 +
if "Volume Average" in technicalIndicators and volume > volumeAvg * technicalBreakoutThreshold then 1 else 0;
# Fundamental breakout criteria
def fundamentalBreakout =
if marketCap > 0 and revenue > 0 and grossProfitMargin > 0 and netProfitMargin > 0 and eps > 0 and
marketCap > marketCap[1] * fundamentalBreakoutThreshold and
revenue > revenue[1] * fundamentalBreakoutThreshold and
grossProfitMargin > grossProfitMargin[1] * fundamentalBreakoutThreshold and
netProfitMargin > netProfitMargin[1] * fundamentalBreakoutThreshold and
eps > eps[1] * fundamentalBreakoutThreshold then 1 else 0;
# Moving average criteria
def aboveMovingAverage = close > MovingAverage(movingAverageType, movingAverageLength, movingAveragePrice);
# Criteria for breakout
def breakoutCriteria = technicalBreakout + fundamentalBreakout + (aboveMovingAverage ? 1 : 0);
# Scan for stocks that meet the breakout criteria
def stocks =
if breakoutCriteria > 0 and close > 5 and volume > 500000 then 1 else 0;
# Filter
Need correct code
# Volume Profile Order Flow Cumulative Delta and Imbalance Indicator with Arrows
input vpRange = 10; # Volume Profile range
input imbalanceThreshold = 500; # Order flow imbalance threshold
def vp = VolumeProfile("startNewProfile" = yes, "onExpansion" = no, "numberOfProfiles" = vpRange);
def delta = close - close[1];
def cumDelta = Sum(delta, vpRange);
def imbalance = cumDelta > imbalanceThreshold ? 1 : cumDelta < -imbalanceThreshold ? -1 : 0;
# Draw arrows for potential reversal and breakout points
AddChartBubble(imbalance > 0 and close < vp.lowestPrice, vp.lowestPrice, "Buy", Color.Green, yes);
AddChartBubble(imbalance < 0 and close > vp.highestPrice, vp.highestPrice, "Sell", Color.Red, yes);
AddChartBubble(close[1] < vp.highestPrice and close > vp.highestPrice, vp.highestPrice, "Buy Breakout", Color.Green, no);
AddChartBubble(close[1] > vp.lowestPrice and close < vp.lowestPrice, vp.lowestPrice, "Sell Breakout", Color.Red, no);
# chat_profile1
# https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-122933
# post67
# Volume Profile Order Flow Cumulative Delta and Imbalance Indicator with Arrows
input vpRange = 10; # Volume Profile range
input imbalanceThreshold = 500; # Order flow imbalance threshold
#def vp = VolumeProfile("startNewProfile" = yes, "onExpansion" = no, "numberOfProfiles" = vpRange);
profile vp = VolumeProfile("startNewProfile" = yes, "onExpansion" = no, "numberOfProfiles" = vpRange);
def delta = close - close[1];
def cumDelta = Sum(delta, vpRange);
#def imbalance = cumDelta > imbalanceThreshold ? 1 : cumDelta < -imbalanceThreshold ? -1 : 0;
def imbalance = if cumDelta > imbalanceThreshold then 1 else if cumDelta < -imbalanceThreshold then -1 else 0;
def phi = if isnan(vp.gethighest()) then phi[1] else vp.gethighest();
def plo = if isnan(vp.getlowest()) then plo[1] else vp.getlowest();
#vp.show(globalColor("Profile"), if showPointOfControl then globalColor("Point Of Control") else color.current, if showValueArea then globalColor("Value Area") else color.current, opacity);
vp.show(globalColor("Profile"), color.current, color.current);
# Draw arrows for potential reversal and breakout points
AddChartBubble(imbalance > 0 and close < plo, plo, "Buy", Color.Green, yes);
AddChartBubble(imbalance < 0 and close > phi, phi, "Sell", Color.Red, yes);
AddChartBubble(close[1] < phi and close > phi, phi, "Buy Breakout", Color.Green, no);
AddChartBubble(close[1] > plo and close < plo, plo, "Sell Breakout", Color.Red, no);
#
This is the code ChatGPD gave me. It does not work though. I asked to do it many many times different ways but could not get it to work. Any help would be amazing! All of these versions gave errors
# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color;
if (close > lastPrice) {
color = uptickColor; } else if (close < lastPrice) {
color = downtickColor; } else {
color = neutralColor; }
AddLabel(yes, "Bid: " + Round(bid, 2), color);
Also this was a version..
# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);
# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color = if bidPrice > lastPrice then uptickColor else if bidPrice < lastPrice then downtickColor else neutralColor;
# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), if color == uptickColor then uptickColor else if color == downtickColor then downtickColor else neutralColor);
Also
# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);
# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color;
if bidPrice > lastPrice {
color = uptickColor;
} else if bidPrice < lastPrice {
color = downtickColor;
} else {
color = neutralColor;
}
# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), color);
"THINKORSWIM SCRIPT SUPPLY AND DEMAND"
"Here's an example script in ThinkScript that can help you identify areas of supply and demand:"
This script calculates and plots supply and demand zones on the chart based on the previous high and low prices within a certain length and deviation range. Supply zones are indicated by a magenta dashed line, while demand zones are indicated by a green dashed line.
You can customize the input length and deviation to fit your trading style and preferences. Additionally, you can combine this script with volume profile indicators to further refine your analysis of supply and demand zones.
# Supply and Demand Zone Indicator
#Created by ChatGBT by asking it "THINKORSWIM SCRIPT SUPPLY AND DEMAND."
input length = 10;
input deviation = 1.5;
def priceHigh = high;
def priceLow = low;
def priceMedian = (priceHigh + priceLow) / 2;
def priceDeviation = deviation * stdev(priceMedian, length);
def supplyZone = if priceHigh[1] >= highest(priceHigh, length)[1] and
priceLow[1] >= highest(priceLow, length)[1] - priceDeviation[1]
then 1 else 0;
def demandZone = if priceLow[1] <= lowest(priceLow, length)[1] and
priceHigh[1] <= lowest(priceHigh, length)[1] + priceDeviation[1]
then 1 else 0;
plot supplyZoneLine = if supplyZone then highest(priceLow, length) - priceDeviation else Double.NaN;
supplyZoneLine.SetStyle(curve.short_DASH);
supplyZoneLine.SetLineWeight(2);
supplyZoneLine.SetDefaultColor(Color.MAGENTA);
plot demandZoneLine = if demandZone then lowest(priceHigh, length) + priceDeviation else Double.NaN;
demandZoneLine.SetStyle(curve.short_DASH);
demandZoneLine.SetLineWeight(2);
demandZoneLine.SetDefaultColor(Color.GREEN);
Hello,
Here are the words used to generate the ChatGBT script:
And here is ChatGBT's response to the above words:
Maybe this might help develop a better more concise script for supply and demand...
Code:# Supply and Demand Zone Indicator #Created by ChatGBT by asking it "THINKORSWIM SCRIPT SUPPLY AND DEMAND." input length = 10; input deviation = 1.5; def priceHigh = high; def priceLow = low; def priceMedian = (priceHigh + priceLow) / 2; def priceDeviation = deviation * stdev(priceMedian, length); def supplyZone = if priceHigh[1] >= highest(priceHigh, length)[1] and priceLow[1] >= highest(priceLow, length)[1] - priceDeviation[1] then 1 else 0; def demandZone = if priceLow[1] <= lowest(priceLow, length)[1] and priceHigh[1] <= lowest(priceHigh, length)[1] + priceDeviation[1] then 1 else 0; plot supplyZoneLine = if supplyZone then highest(priceLow, length) - priceDeviation else Double.NaN; supplyZoneLine.SetStyle(curve.short_DASH); supplyZoneLine.SetLineWeight(2); supplyZoneLine.SetDefaultColor(Color.MAGENTA); plot demandZoneLine = if demandZone then lowest(priceHigh, length) + priceDeviation else Double.NaN; demandZoneLine.SetStyle(curve.short_DASH); demandZoneLine.SetLineWeight(2); demandZoneLine.SetDefaultColor(Color.GREEN);
# chat72_supply_demand_01
# https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-124012
#post72
def na = double.nan;
def bn = barnumber();
input length = 10;
input deviation = 1.5;
def priceHigh = high;
def priceLow = low;
def priceMedian = (priceHigh + priceLow) / 2;
def priceDeviation = deviation * stdev(priceMedian, length);
def supplyZone = if priceHigh[1] >= highest(priceHigh, length)[1] and
priceLow[1] >= highest(priceLow, length)[1] - priceDeviation[1]
then 1 else 0;
def demandZone = if priceLow[1] <= lowest(priceLow, length)[1] and
priceHigh[1] <= lowest(priceHigh, length)[1] + priceDeviation[1]
then 1 else 0;
def sz = highest(priceLow, length) - priceDeviation;
def dz = lowest(priceHigh, length) + priceDeviation;
plot supplyZoneLine = if supplyZone then sz else Double.NaN;
supplyZoneLine.SetStyle(curve.short_DASH);
supplyZoneLine.SetLineWeight(2);
supplyZoneLine.SetDefaultColor(Color.MAGENTA);
plot demandZoneLine = if demandZone then dz else Double.NaN;
demandZoneLine.SetStyle(curve.short_DASH);
demandZoneLine.SetLineWeight(2);
demandZoneLine.SetDefaultColor(Color.GREEN);
#---------------------------------
# supply zones
def big = 99999;
def w = 50;
def supplytop;
def supplybot;
if bn == 1 then {
supplytop = 0;
supplybot = 0;
} else if !supplyzone[1] and supplyzone[0] and supplyzone[-1] then {
# first supplyzone of several...
supplytop = fold i1 = 0 to w
with p1
while getvalue(supplyzone, -i1)
do max(p1, getvalue(sz, -i1));
supplybot = fold i2 = 0 to w
with p2 = big
while getvalue(supplyzone, -i2)
do min(p2, getvalue(sz, -i2));
} else {
supplytop = supplytop[1];
supplybot = supplybot[1];
}
plot zstop = if isnan(close) or supplytop == 0 then na else if supplytop > 0 then supplytop else na;
zstop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zstop.SetDefaultColor(Color.gray);
zstop.setlineweight(1);
zstop.hidebubble();
plot zsbot = if isnan(close) or supplybot == 0 then na else if supplybot > 0 then supplybot else na;
zsbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zsbot.SetDefaultColor(Color.gray);
zsbot.setlineweight(1);
zsbot.hidebubble();
def stop = if isnan(close) then na else if bn >= 1 then zstop else 0;
def sbot = if isnan(close) then na else if bn >= 1 then zsbot else 0;
addcloud(stop, sbot , color.magenta);
#---------------------------------
# demand zones
#def big = 99999;
#def w = 50;
def demandtop;
def demandbot;
if bn == 1 then {
demandtop = 0;
demandbot = 0;
} else if !demandzone[1] and demandzone[0] and demandzone[-1] then {
# first demandzone of several...
demandtop = fold i3 = 0 to w
with p3
while getvalue(demandzone, -i3)
do max(p3, getvalue(dz, -i3));
demandbot = fold i4 = 0 to w
with p4 = big
while getvalue(demandzone, -i4)
do min(p4, getvalue(dz, -i4));
} else {
demandtop = demandtop[1];
demandbot = demandbot[1];
}
plot zdtop = if isnan(close) or demandtop == 0 then na else if demandtop > 0 then demandtop else na;
zdtop.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdtop.SetDefaultColor(Color.gray);
zdtop.setlineweight(1);
zdtop.hidebubble();
plot zdbot = if isnan(close) or demandbot == 0 then na else if demandbot > 0 then demandbot else na;
zdbot.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zdbot.SetDefaultColor(Color.gray);
zdbot.setlineweight(1);
zdbot.hidebubble();
def dtop = if isnan(close) then na else if bn >= 1 then zdtop else 0;
def dbot = if isnan(close) then na else if bn >= 1 then zdbot else 0;
addcloud(dtop, dbot , color.green);
#---------------------------------
# test stuff
addchartbubble(0, low,
supplytop + "\n" +
supplybot + "\n" +
demandtop + "\n" +
demandbot
, color.yellow, no);
# supplyzone demandzone
# find values of 1 , 2+ more in a row
addchartbubble(0, low*0.99,
supplyzone + "\n" +
demandzone
, color.yellow, no);
#
This is the code ChatGPD gave me. It does not work though. I asked to do it many many times different ways but could not get it to work. Any help would be amazing! All of these versions gave errors
# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color;
if (close > lastPrice) {
color = uptickColor; } else if (close < lastPrice) {
color = downtickColor; } else {
color = neutralColor; }
AddLabel(yes, "Bid: " + Round(bid, 2), color);
Also this was a version..
# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);
# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color = if bidPrice > lastPrice then uptickColor else if bidPrice < lastPrice then downtickColor else neutralColor;
# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), if color == uptickColor then uptickColor else if color == downtickColor then downtickColor else neutralColor);
Also
# declare variables
input priceDisplay = 2;
def bidPrice = close("Bid");
def priceRounded = Round(bidPrice, priceDisplay);
# set the color of the price display
def uptickColor = Color.GREEN;
def downtickColor = Color.RED;
def neutralColor = Color.GRAY;
def lastPrice = close[1];
def color;
if bidPrice > lastPrice {
color = uptickColor;
} else if bidPrice < lastPrice {
color = downtickColor;
} else {
color = neutralColor;
}
# set the format and color of the watchlist columns
AddLabel(yes, "$" + AsText(priceRounded, NumberFormat.TWO_DECIMAL_PLACES), color);
def lastPrice = close[1];
AddLabel(yes, "last price: " + Round(lastprice, 2),
(if (close > lastPrice) then Color.GREEN
else if (close < lastPrice) then Color.RED
else Color.GRAY));
#
# TOS Indicator for Stochastic and Moving Average Clouds
input length = 14;
input kPeriod = 3;
input dPeriod = 3;
input overbought = 80;
input oversold = 20;
input cloudExtension = 20;
def StochasticD = StochasticFullD(length, kPeriod, dPeriod);
def ma50 = ExpAverage(close, 50);
def ma200 = ExpAverage(close, 200);
def isOverbought = StochasticD > overbought and ma200 < ma50;
def isOversold = StochasticD < oversold and ma50 < ma200;
plot OB = if isOverbought then ma200 else Double.NaN;
plot OS = if isOversold then ma50 else Double.NaN;
OB.SetDefaultColor(Color.LIGHT_RED);
OS.SetDefaultColor(Color.LIGHT_GREEN);
AddCloud(if isOverbought then ma200 else Double.NaN, ma200, Color.LIGHT_RED, Color.LIGHT_RED).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_RED).SetHiding(cloudExtension, cloudExtension);
AddCloud(if isOversold then ma50 else Double.NaN, ma50, Color.LIGHT_GREEN, Color.LIGHT_GREEN).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_GREEN).SetHiding(cloudExtension, cloudExtension);
AssignPriceColor(if isOverbought then Color.LIGHT_RED else if isOversold then Color.LIGHT_GREEN else Color.CURRENT);
I am trying to create an indicator that will place clouds at a price level when the stochastic D period is oversold/overbought and the 50 EMA is above or below the 200 EMA. I keep getting an invalid statement error. I used ChatGpt to write this as I do not know how to code. Can one of you genius coders help me to fix the code? Thanks in advance.
Invalid statement: AddCloud at 24:1
Invalid statement: AddCloud at 25:1
Code:# TOS Indicator for Stochastic and Moving Average Clouds input length = 14; input kPeriod = 3; input dPeriod = 3; input overbought = 80; input oversold = 20; input cloudExtension = 20; def StochasticD = StochasticFullD(length, kPeriod, dPeriod); def ma50 = ExpAverage(close, 50); def ma200 = ExpAverage(close, 200); def isOverbought = StochasticD > overbought and ma200 < ma50; def isOversold = StochasticD < oversold and ma50 < ma200; plot OB = if isOverbought then ma200 else Double.NaN; plot OS = if isOversold then ma50 else Double.NaN; OB.SetDefaultColor(Color.LIGHT_RED); OS.SetDefaultColor(Color.LIGHT_GREEN); AddCloud(if isOverbought then ma200 else Double.NaN, ma200, Color.LIGHT_RED, Color.LIGHT_RED).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_RED).SetHiding(cloudExtension, cloudExtension); AddCloud(if isOversold then ma50 else Double.NaN, ma50, Color.LIGHT_GREEN, Color.LIGHT_GREEN).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_GREEN).SetHiding(cloudExtension, cloudExtension); AssignPriceColor(if isOverbought then Color.LIGHT_RED else if isOversold then Color.LIGHT_GREEN else Color.CURRENT);
# chat76_stoch_00
#https://usethinkscript.com/threads/chatgpt-for-thinkorswim.13822/page-4#post-123384
#Bob007 #76
#I am trying to create an indicator that will place clouds at a price level when the stochastic D period is oversold/overbought and the 50 EMA is above or below the 200 EMA. I keep getting an invalid statement error. I used ChatGpt to write this as I do not know how to code. Can one of you genius coders help me to fix the code? Thanks in advance.
# TOS Indicator for Stochastic and Moving Average Clouds
input length = 14;
input kPeriod = 3;
input dPeriod = 3;
input overbought = 80;
input oversold = 20;
input cloudExtension = 20;
#def StochasticD = StochasticFullD(length, kPeriod, dPeriod);
def StochasticD = StochasticFull(length, kPeriod, dPeriod).fulld;
def ma50 = ExpAverage(close, 50);
def ma200 = ExpAverage(close, 200);
def isOverbought = StochasticD > overbought and ma200 < ma50;
def isOversold = StochasticD < oversold and ma50 < ma200;
#plot OB = if isOverbought then ma200 else Double.NaN;
#plot OS = if isOversold then ma50 else Double.NaN;
#OB.SetDefaultColor(Color.LIGHT_RED);
#OS.SetDefaultColor(Color.LIGHT_GREEN);
# change it so all of average lines are drawn
plot OB = ma200;
plot OS = ma50;
ob.AssignValueColor(if isOverbought then color.magenta else color.dark_gray);
os.AssignValueColor(if isOversold then color.green else color.dark_gray);
ob.setlineweight(2);
os.setlineweight(2);
#AddCloud(if isOverbought then ma200 else Double.NaN, ma200, Color.LIGHT_RED, Color.LIGHT_RED).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_RED).SetHiding(cloudExtension, cloudExtension);
#AddCloud(if isOversold then ma50 else Double.NaN, ma50, Color.LIGHT_GREEN, Color.LIGHT_GREEN).SetPaintingStrategy(PaintingStrategy.HORIZONTAL).SetDefaultColor(Color.LIGHT_GREEN).SetHiding(cloudExtension, cloudExtension);
AddCloud((if isOverbought then ma200 else Double.NaN), ma50, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud((if isOversold then ma50 else Double.NaN), ma200, Color.LIGHT_GREEN, color.LIGHT_GREEN);
#AssignPriceColor(if isOverbought then Color.LIGHT_RED else if isOversold then Color.LIGHT_GREEN else Color.CURRENT);
AssignPriceColor(if isOverbought then Color.LIGHT_RED else if isOversold then Color.LIGHT_GREEN else Color.gray);
#
I'm trying to fix the errors I get but unfortunately I failed. Thank you!!!
input length = 233;
input showLevels = yes;
input showLabels = yes;
def wave = ElliottWave(length);
# Plot waves and labels
plot waveCount = wave;
def wave = if !IsNaN(close) then
if !IsNaN(wave[-1]) and wave[-1] != 0 then
if wave[-1] > 0 and close < low[-1] then wave[-1] + 1
else if wave[-1] < 0 and close > high[-1] then wave[-1] - 1
else wave[-1]
else 0
else Double.NaN;
plot waveCount = if !IsNaN(wave) and showLabels then wave else Double.NaN;
if showLabels then {
if wave > wave[1] then {
waveCount.SetDefaultColor(Color.GREEN);
} else {
waveCount.SetDefaultColor(Color.RED);
}
AddLabel(yes, "Wave " + wave, if wave > wave[1] then Color.GREEN else Color.RED);
}
def lowValue = Lowest(low, length);
def highValue = Highest(high, length);
def retracementLevels = (highValue - lowValue) *
(0.236, 0.382, 0.5, 0.618, 0.786, 1.0, 1.236, 1.382, 1.618);
plot retracement = if showLevels then retracementLevels else Double.NaN;
if showLevels then {
retracement.SetDefaultColor(Color.LIGHT_GRAY);
AddChartBubble(high, 0.236, "23.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.382, "38.2%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.5, "50%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.618, "61.8%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 0.786, "78.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.0, "100%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.236, "123.6%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.382, "138.2%", Color.LIGHT_GRAY, no);
AddChartBubble(high, 1.618, "161.8%", Color.LIGHT_GRAY, no);
}
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Start a new thread and receive assistance from our community.
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.
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.