#chat232_ema_crossing
#https://usethinkscript.com/threads/chatgpt-bard-other-ai-scripts-which-cant-be-used-in-thinkorswim.13822/page-12#post-140802
def na = double.nan;
def bn = barnumber();
input len3 = 3;
input len8 = 8;
def EMA3 = ExpAverage(close, len3);
def EMA8 = ExpAverage(close, len8);
input show_emas = no;
plot z1 = if show_emas then ema3 else na;
plot z2 = if show_emas then ema8 else na;
# Define the crossover conditions
def buy = if EMA3 crosses above EMA8 then 1 else 0;
def sell = if EMA3 crosses below EMA8 then 1 else 0;
# Plot arrows on the chart where the conditions are met
plot BuySignal = if buy then low*0.999 else na;
BuySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
BuySignal.SetDefaultColor(Color.GREEN);
BuySignal.setlineweight(2);
BuySignal.hidebubble();
plot SellSignal = if sell then high*1.001 else na;
SellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
SellSignal.SetDefaultColor(Color.RED);
sellSignal.setlineweight(2);
sellSignal.hidebubble();
# variables used below but not defined
# Alerts
# Alert(SoundAlerts and h > al , "Up", Alert.BAR, Sound.Bell);
# Alert(SoundAlerts and l < bl, "Down", Alert.BAR, Sound.Ding);
#AddOrder(OrderType.BUY_to_open, Bl <> Bl[1], tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "Buy");
#AddOrder(OrderType.SELL_TO_CLOSE, Al <> Al[1], tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "Sell");
# AddOrder ( type, condition, price, tradeSize, tickColor, arrowColor, name);
input tradesize = 1;
AddOrder (
type = ordertype.BUY_TO_OPEN
, condition = buy
, price = open[-1]
, tradeSize = tradeSize
, tickColor = color.green
, arrowColor = color.green
, name = "buy"
);
AddOrder (
type = ordertype.sell_to_close
, condition = sell
, price = open[-1]
, tradeSize = tradeSize
, tickColor = color.red
, arrowColor = color.red
, name = "sell"
);
#