input price = close;
input fastLength = 10;
input slowLength = 450;
input averageType = AverageType.SIMPLE;
input targetProfitPoints = 3;
input stopLossPoints = 1; # You can adjust this value as needed
plot FastMA = MovingAverage(averageType, price, fastLength);
plot SlowMA = MovingAverage(averageType, price, slowLength);
FastMA.SetDefaultColor(GetColor(1));
SlowMA.SetDefaultColor(GetColor(2));
plot ArrowUp = if FastMA - 2 crosses above SlowMA
then low - 10
else Double.NaN;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowUp.SetLineWeight(3);
ArrowUp.SetDefaultColor(Color.GREEN);
plot ArrowDN = if FastMA + 2 crosses below SlowMA
then high + 10
else Double.NaN;
ArrowDN.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowDN.SetLineWeight(3);
ArrowDN.SetDefaultColor(Color.RED);
Alert(ArrowUp, " ", Alert.BAR, Sound.Chimes);
Alert(ArrowDN, " ", Alert.BAR, Sound.Bell);
DefineGlobalColor("Bullish", Color.YELLOW);
DefineGlobalColor("Bearish", Color.RED);
input seeClouds = yes;
AddCloud(If(seeClouds, FastMA, Double.NaN), SlowMA, GlobalColor("Bullish"), GlobalColor("Bearish"));
# Generate exit conditions for both buy and sell
def exitConditionBuy = close > EntryPrice() + targetProfitPoints;
def exitConditionSell = close < EntryPrice() - targetProfitPoints;
# Generate stop-loss conditions for both buy and sell
def stopLossBuy = close < EntryPrice() - stopLossPoints;
def stopLossSell = close > EntryPrice() + stopLossPoints;
# Add buy and sell orders
AddOrder(OrderType.BUY_AUTO, FastMA - 2 crosses above SlowMA);
AddOrder(OrderType.SELL_AUTO, FastMA + 2 crosses below SlowMA);
# Close the buy position when the exit condition is met
AddOrder(OrderType.SELL_TO_CLOSE, exitConditionBuy, open[-1], 1, Color.WHITE, Color.WHITE);
# Close the sell position when the exit condition is met
AddOrder(OrderType.BUY_TO_CLOSE, exitConditionSell, open[-1], 1, Color.YELLOW, Color.YELLOW);
# Add stop-loss orders
AddOrder(OrderType.SELL_TO_CLOSE, stopLossBuy, open[-1], 1, Color.RED, Color.RED);
AddOrder(OrderType.BUY_TO_CLOSE, stopLossSell, open[-1], 1, Color.GREEN, Color.GREEN);