Last active
January 30, 2025 16:56
-
-
Save lucasalberto/eeb423f6540e75932c3c3f7e19bd8cac to your computer and use it in GitHub Desktop.
Trading General Strategy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ | |
// © By Lucas Alberto | |
// Apply this script to short time frames (e.g., 1-minute or 5-minute charts) | |
// The Buy label will appears when a bullish crossover (fast MA 1 crossing above fast MA 2) accompanied by high volume. | |
// The Sell label will appears when a bearish crossover (fast MA 1 crossing below fast MA 2) accompanied by high volume. | |
// Allso the take profit and stop loss lines will appears respectively. | |
//@version=6 | |
indicator("Sell Tag Label Bubble Strategy", overlay=true) | |
// Input parameters for fast moving averages | |
fastMaLength1 = input.int(3, title="EMA Length 1", minval=1) | |
fastMaLength2 = input.int(7, title="EMA Length 2", minval=1) | |
// Input for RSI filter (optional) | |
useRsiFilter = input.bool(true, title="Use RSI Filter") | |
rsiLength = input.int(14, title="RSI Length", minval=1) | |
rsiOverbought = input.int(70, title="RSI Overbought Level", minval=50) | |
rsiOversold = input.int(30, title="RSI Oversold Level", minval=0) | |
// Input for risk management | |
useStopLoss = input.bool(true, title="Use Stop-Loss") | |
stopLossPerc = input.float(1.0, title="Stop-Loss (%)", minval=0.1) | |
useTakeProfit = input.bool(true, title="Use Take-Profit") | |
takeProfitPerc = input.float(2.0, title="Take-Profit (%)", minval=0.1) | |
// Calculate fast exponential moving averages | |
fastMa1 = ta.ema(close, fastMaLength1) | |
fastMa2 = ta.ema(close, fastMaLength2) | |
// Calculate RSI | |
rsi = ta.rsi(close, rsiLength) | |
// Detect short-term trend changes | |
isBullishCross = ta.crossover(fastMa1, fastMa2) | |
isBearishCross = ta.crossunder(fastMa1, fastMa2) | |
// Volume analysis (optional) | |
useVolumeFilter = input.bool(true, title="Use Volume Filter") | |
volumeMaLength = input.int(20, title="Volume MA Length") | |
volumeMa = ta.sma(volume, volumeMaLength) | |
isHighVolume = volume > volumeMa | |
// Price action patterns | |
isBullishEngulfing = (close > open) and (close[1] < open[1]) and (close > open[1]) and (open < close[1]) | |
isDoubleBottom = (low[1] < low[2]) and (low < low[1]) and (close > open) | |
// Conditions for "Buy" label | |
isBuy = isBullishCross and (not useVolumeFilter or isHighVolume) and (not useRsiFilter or rsi < rsiOverbought) and (isBullishEngulfing or isDoubleBottom) | |
// Risk management: Stop-Loss and Take-Profit | |
var float entryPrice = na | |
var bool isActiveTrade = false | |
var float stopLossLevel = na | |
var float takeProfitLevel = na | |
if isBuy and not isActiveTrade | |
entryPrice := close | |
stopLossLevel := entryPrice * (1 - stopLossPerc / 100) | |
takeProfitLevel := entryPrice * (1 + takeProfitPerc / 100) | |
isActiveTrade := true | |
// Check if price hits stop-loss or take-profit | |
if isActiveTrade | |
if useStopLoss and close <= stopLossLevel | |
isActiveTrade := false | |
entryPrice := na | |
stopLossLevel := na | |
takeProfitLevel := na | |
if useTakeProfit and close >= takeProfitLevel | |
isActiveTrade := false | |
entryPrice := na | |
stopLossLevel := na | |
takeProfitLevel := na | |
// Final sell signal (only when stop-loss or take-profit is hit) | |
finalSellSignal = isActiveTrade and (close <= stopLossLevel or close >= takeProfitLevel) | |
// Plot Buy and Sell signals with label bubbles | |
plotshape(series=isBuy, location=location.belowbar, color=color.new(color.green, 50), style=shape.labelup, text="BUY", textcolor=color.white, size=size.small) | |
plotshape(series=finalSellSignal, location=location.abovebar, color=color.new(color.red, 50), style=shape.labeldown, text="SELL", textcolor=color.white, size=size.small) | |
// Optional: Plot stop-loss and take-profit levels | |
plot(stopLossLevel, color=color.red, title="Stop-Loss Level", linewidth=1, style=plot.style_linebr) | |
plot(takeProfitLevel, color=color.green, title="Take-Profit Level", linewidth=1, style=plot.style_linebr) | |
// Optional: Plot fast exponential moving averages for visualization | |
plot(fastMa1, color=color.new(color.blue, 0), title="EMA 1", linewidth=1) | |
plot(fastMa2, color=color.new(color.orange, 0), title="EMA 2", linewidth=1) | |
// Optional: Plot RSI for reference | |
hline(rsiOverbought, "Overbought", color=color.red, linestyle=hline.style_dotted) | |
hline(rsiOversold, "Oversold", color=color.green, linestyle=hline.style_dotted) | |
plot(rsi, title="RSI", color=color.purple, linewidth=1) |
Comments are disabled for this gist.