ChatGPT Algo PRO For ThinkOrSwim

Coul someone look at his and find where I am going wrong?
This is my attempt to convert ChatGPT Algo PRO https://www.tradingview.com/script/5UyoWYVE-ChatGPT-Algo-PRO-Bitcoin/

# This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/# © Tradeiqofficialdeclare lower;# Input parametersinput len = 20;input src = close;input emaLength = 100;input atrLength = 14;input slMultiplier = 2.0;input tpMultiplier = 4.0;input thresholdHigh = 2.5;input thresholdMedium = 1;input volumeLength = 610;# Calculate SSL Channeldef smaHigh = SimpleMovingAvg(high, len);def smaLow = SimpleMovingAvg(low, len);def Hlv = if src > smaHigh then 1 else if src < smaLow then -1 else GetValue(Hlv, 1);def sslDown = if Hlv < 0 then smaHigh else smaLow;def sslUp = if Hlv < 0 then smaLow else smaHigh;# Calculate 200 EMAdef ema200 = ExpAverage(src, emaLength);# Calculate ATRdef atr = ATRTrailingStop(atrLength, atrLength, slMultiplier, tpMultiplier, no);# Calculate Heatmap Volumedef volumeMean = SimpleMovingAvg(volume, volumeLength);def volumeStd = StDev(volume, volumeLength);def stdBar = (volume - volumeMean) / volumeStd;# Define Volume Filterdef volumeFilter = stdBar > thresholdMedium or stdBar > thresholdHigh;# Define Buy and Sell conditionsdef bullishCross = Crosses(sslUp, sslDown) and src < ema200 and volumeFilter;def bearishCross = Crosses(sslDown, sslUp) and src > ema200 and volumeFilter;# Set SL and TP levelsdef longStopLoss = src - atr * slMultiplier;def longTakeProfit = src + atr * tpMultiplier;def shortStopLoss = src + atr * slMultiplier;def shortTakeProfit = src - atr * tpMultiplier;# Implement strategy.entry functions with SL and TPAddOrder(OrderType.BUY_TO_OPEN, bullishCross, close, 1, Color.GREEN, Color.BLACK, longStopLoss, longTakeProfit, "Buy");AddOrder(OrderType.SELL_TO_OPEN, bearishCross, close, 1, Color.RED, Color.BLACK, shortStopLoss, shortTakeProfit, "Sell");# Plot SSL Channel and 200 EMAplot sslDownLine = sslDown;plot sslUpLine = sslUp;plot ema200Line = ema200;sslDownLine.SetDefaultColor(Color.RED);sslUpLine.SetDefaultColor(Color.GREEN);ema200Line.SetDefaultColor(Color.ORANGE);# Plot long and short signalsplotshape(bullishCross, style = Shape.LABELUP, location = Location.BELOWBAR, text = "Buy", color = Color.GREEN, size = Size.NORMAL);plotshape(bearishCross, style = Shape.LABELDOWN, location = Location.ABOVEBAR, text = "Sell", color = Color.RED, size = Size.NORMAL);
use below code if you want it as Study:

CSS:
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Tradeiqofficial
#strategy("ChatGPT Algo Bitcoin", overlay=true)
# Converted by Sam4Cok@Samer800    - 08/2023
#// Input parameters
input smoothSslChannel = no;
input sslLength = 20;#, title="SSL Channel Length", minval=1)
input src = close;
input movAvgLength = 200;#, title="EMA Length", minval=1)
input MovAvgType = AverageType.EXPONENTIAL;
input atrLength = 14;#, title="ATR Length", minval=1)
input slMultiplier = 2.0;#, title="SL Multiplier", type=input.float)
input tpMultiplier = 4.0;#, title="TP Multiplier", type=input.float)
input thresholdHigh = 2.5;#, title="High Volume Threshold", type=input.float)
input thresholdMedium = 1.0;#, title="Medium Volume Threshold", type=input.float)
input volumeLength = 610;#, title="Volume MA Length", type=input.integer)

def na = Double.NaN;
#// Calculate SSL Channel
def avghh = ExpAverage(high,5);
def avgll = ExpAverage(low, 5);
def srcHi = if smoothSslChannel then avghh else high;
def srcLo = if smoothSslChannel then avgll else low;
def smaHigh = Average(srcHi, sslLength);
def smaLow  = Average(srcLo, sslLength);
def Hlv = if src > smaHigh then 1 else
          if src < smaLow then -1 else Hlv[1];
def sslDown = if Hlv < 0 then smaHigh else smaLow;
def sslUp = if Hlv < 0 then smaLow else smaHigh;

#// Calculate 200 EMA
def ema200 = MovingAverage(MovAvgType, src, movAvgLength);

#// Calculate ATR
def atr = ATR(LENGTH = atrLength);

#// Calculate Heatmap Volume
def volumeMean = Average(volume, volumeLength);
def volumeStd = stdev(volume, volumeLength);
def stdBar = (volume - volumeMean) / volumeStd;

#// Define Volume Filter
def volumeFilter = stdBar > thresholdMedium or stdBar > thresholdHigh;

#// Define Buy and Sell conditions
def crossUp      = (sslUp > sslDown) and (sslUp[1] <= sslDown[1]);
def crossDn      = (sslUp < sslDown) and (sslUp[1] >= sslDown[1]);
def bullishCross = crossUp and src < ema200 and volumeFilter;
def bearishCross = crossDn and src > ema200 and volumeFilter;

def buyCondition = bullishCross;
def sellCondition = bearishCross;

def LongEntry  = if buyCondition then src[-1] else if(LongEntry[1]==0, src[-1], LongEntry[1]);
def shortEntry = if sellCondition then src[-1] else if(shortEntry[1]==0, src[-1], shortEntry[1]);

#// Plot SSL Channel and 200 EMA
def sslDnBand = sslDown;    # "SSL Down"
def sslUpBand = sslUp;      # "SSL Up"
plot emaLine = ema200;      # "200 EMA"

emaLine.SetDefaultColor(Color.WHITE);

AddCloud(sslUp, sslDown, Color.DARK_GREEN, Color.DARK_RED, yes);

#-- END of CODE

and use the below if you want it as Strategy (Paste the code in the Strategy tab):

CSS:
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Tradeiqofficial
#strategy("ChatGPT Algo Bitcoin", overlay=true)
# Converted by Sam4Cok@Samer800    - 08/2023
#// Input parameters
input smoothSslChannel = no;
input sslLength = 20;#, title="SSL Channel Length", minval=1)
input src = close;
input movAvgLength = 200;#, title="EMA Length", minval=1)
input MovAvgType = AverageType.EXPONENTIAL;
input atrLength = 14;#, title="ATR Length", minval=1)
input slMultiplier = 2.0;#, title="SL Multiplier", type=input.float)
input tpMultiplier = 4.0;#, title="TP Multiplier", type=input.float)
input thresholdHigh = 2.5;#, title="High Volume Threshold", type=input.float)
input thresholdMedium = 1.0;#, title="Medium Volume Threshold", type=input.float)
input volumeLength = 610;#, title="Volume MA Length", type=input.integer)

def na = Double.NaN;
#// Calculate SSL Channel
def avghh = ExpAverage(high,5);
def avgll = ExpAverage(low, 5);
def srcHi = if smoothSslChannel then avghh else high;
def srcLo = if smoothSslChannel then avgll else low;
def smaHigh = Average(srcHi, sslLength);
def smaLow  = Average(srcLo, sslLength);
def Hlv = if src > smaHigh then 1 else
          if src < smaLow then -1 else Hlv[1];
def sslDown = if Hlv < 0 then smaHigh else smaLow;
def sslUp = if Hlv < 0 then smaLow else smaHigh;

#// Calculate 200 EMA
def ema200 = MovingAverage(MovAvgType, src, movAvgLength);

#// Calculate ATR
def atr = ATR(LENGTH = atrLength);

#// Calculate Heatmap Volume
def volumeMean = Average(volume, volumeLength);
def volumeStd = stdev(volume, volumeLength);
def stdBar = (volume - volumeMean) / volumeStd;

#// Define Volume Filter
def volumeFilter = stdBar > thresholdMedium or stdBar > thresholdHigh;

#// Define Buy and Sell conditions
def crossUp      = (sslUp > sslDown) and (sslUp[1] <= sslDown[1]);
def crossDn      = (sslUp < sslDown) and (sslUp[1] >= sslDown[1]);
def bullishCross = crossUp and src < ema200 and volumeFilter;
def bearishCross = crossDn and src > ema200 and volumeFilter;

def buyCondition = bullishCross;
def sellCondition = bearishCross;

def LongEntry  = if buyCondition then src[-1] else if(LongEntry[1]==0, src[-1], LongEntry[1]);
def shortEntry = if sellCondition then src[-1] else if(shortEntry[1]==0, src[-1], shortEntry[1]);

#// Plot SSL Channel and 200 EMA
def sslDnBand = sslDown;    # "SSL Down"
def sslUpBand = sslUp;      # "SSL Up"
plot emaLine = ema200;      # "200 EMA"

emaLine.SetDefaultColor(Color.WHITE);

AddCloud(sslUp, sslDown, Color.DARK_GREEN, Color.DARK_RED, yes);

#// Plot long and short signals
AddChartBubble(buyCondition, low, "Buy",color.green, no);
AddChartBubble(sellCondition, high, "Sell", color.red, yes);

#-- Strategy
#// Set SL and TP levels
def longTakeProfit  = LongEntry  >= (src + atr * tpMultiplier);
def shortTakeProfit = shortEntry <= (src - atr * tpMultiplier);
def longStopLoss    = LongEntry  <  (src - atr * slMultiplier);
def shortStopLoss   = shortEntry >  (src + atr * slMultiplier);

AddOrder(OrderType.BUY_TO_OPEN, if buyCondition then src[-1] else Double.NaN, tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Buy");

AddOrder(OrderType.SELL_TO_OPEN,if sellCondition then src[-1] else Double.NaN, tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "Sell");

AddOrder(OrderType.SELL_TO_CLOSE, longTakeProfit or longStopLoss, tickcolor = GetColor(4), arrowcolor = GetColor(4),
            name = if longTakeProfit then "Long_Loss" else "Long_WIN");
AddOrder(OrderType.BUY_TO_CLOSE, if (shortStopLoss or shortTakeProfit) then src else Double.NaN,tickcolor=GetColor(5), arrowcolor = GetColor(5),
            name = if shortTakeProfit then "Short_Loss" else "Short_Win");

#-- END of CODE
 
Please note if you want to test the strategy as described in the video, the EMA length is 100 not 200 as in post2 above. (No criticism of samer intended...he does awesome conversions!)
 

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
378 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