Trader4TOS
Member
Here is a stop-loss and take-profit tool. I added Fibonacci levels for the take profit guidance and the close of a candle for the stop loss. Also includes visual and audio alerts and all are customizable with the menu to fit your needs. Let me know what I should add or fix and as always. Do not solely rely on one tool or indicator for your plays. Do your own due diligence! Let this serve as a guide. Happy trading! : )
Ruby:
#SLTP Tool Version 1.0 created by Trader4TOS 06/25/2023
#Inputs:
#stopLossCandle: Allows you to specify the number of candles back to use for setting the stop loss level.
#takeProfitLevels: Determines the number of take profit levels to plot.
#fibLevel1, fibLevel2, fibLevel3: Fibonacci levels used to calculate the take profit prices.
#Plotting:
#Stop Loss: Plots a line representing the stop loss level based on the specified stopLossCandle. It is colored in red.
#Take Profit Levels: Plots lines representing the take profit levels based on the Fibonacci levels. The colors of the lines are customizable: tp1 is light green, tp2 is green, and tp3 is dark green.
#Alerting:
#The script includes alerts for specific conditions:
#Stop Loss Triggered: Alerts when the current close price falls below or equals the stop loss level.
#Take Profit 1 Reached: Alerts when the current close price exceeds or equals the first take profit level.
#Take Profit 2 Reached: Alerts when the current close price exceeds or equals the second take profit level.
#Take Profit 3 Reached: Alerts when the current close price exceeds or equals the third take profit level.
#Customization:
#Enable Alerts: Allows you to enable or disable the alerts by setting the enableAlerts input to "yes" or "no".
#Alert Sound: You can choose the alert sound from various options available in ThinkScript, such as Sound.Ring, Sound.Bell, etc.
#By using this script, you can plot the stop loss and take profit levels on your chart and receive audio alerts when the price reaches these levels or when the stop loss is triggered.
input stopLossCandle = 1;
input takeProfitLevels = 3;
input fibLevel1 = 0.382;
input fibLevel2 = 0.618;
input fibLevel3 = 1.0;
input enableAlerts = yes;
input alertSound = Sound.Ring;
def stopLossPrice = close[stopLossCandle];
def takeProfit1Price = close * fibLevel1;
def takeProfit2Price = close * fibLevel2;
def takeProfit3Price = close * fibLevel3;
# Plot Stop Loss
plot stopLoss = stopLossPrice;
stopLoss.SetDefaultColor(Color.RED);
stopLoss.SetLineWeight(2);
# Plot Take Profit Levels
def bullish = close > close[1];
def bearish = close < close[1];
plot tp1 = if bullish then takeProfit1Price else Double.NaN;
tp1.SetDefaultColor(Color.LIGHT_GREEN);
tp1.SetLineWeight(2);
plot tp2 = if bullish then takeProfit2Price else Double.NaN;
tp2.SetDefaultColor(Color.GREEN);
tp2.SetLineWeight(2);
plot tp3 = if bullish then takeProfit3Price else Double.NaN;
tp3.SetDefaultColor(Color.DARK_GREEN);
tp3.SetLineWeight(2);
# Alert Conditions
def alertCondition = close <= stopLossPrice;
def alertProfit1 = close >= takeProfit1Price;
def alertProfit2 = close >= takeProfit2Price;
def alertProfit3 = close >= takeProfit3Price;
def alertStopLoss = close <= stopLossPrice;
# Set alerts for conditions
Alert(enableAlerts and alertCondition, "Stop Loss Triggered", Alert.BAR, alertSound);
Alert(enableAlerts and alertProfit1, "Take Profit 1 Reached", Alert.BAR, alertSound);
Alert(enableAlerts and alertProfit2, "Take Profit 2 Reached", Alert.BAR, alertSound);
Alert(enableAlerts and alertProfit3, "Take Profit 3 Reached", Alert.BAR, alertSound);
Alert(enableAlerts and alertStopLoss, "Stop Loss Reached", Alert.BAR, alertSound);
Last edited by a moderator: