Ahsan Tufail Precise MA Crossover Filter for Reliable Signals.pine
//@version=4
strategy(title="EMA Difference Mapping with Trades", shorttitle="EMA Diff Map", overlay=false)
// Inputs
emaLength = input(20, "EMA Length")
stdDevLength = input(2, "Standard Deviation Length")
priceSource = close
takeProfitPoints = input(1000, title="Take Profit (in Points)")
stopLossPoints = input(2500, title="Stop Loss (in Points)")
// Calculate EMA
ema = ema(priceSource, emaLength)
// Calculate Standard Deviation
stdDev = stdev(priceSource, stdDevLength)
// Calculate differences
diff1 = (ema + stdDev) - ema
diff2 = ema - (ema - stdDev)
// Calculate min and max differences from last year
lookbackPeriod = 504 // Number of trading days in a year
minDiff1 = lowest(diff1, lookbackPeriod)
maxDiff1 = highest(diff1, lookbackPeriod)
minDiff2 = lowest(diff2, lookbackPeriod)
maxDiff2 = highest(diff2, lookbackPeriod)
// Map differences based on requirements
mappedDiff1 = 50 + 50 * ((diff1 - minDiff1) / (maxDiff1 - minDiff1))
mappedDiff2 = 50 - 50 * ((diff2 - minDiff2) / (maxDiff2 - minDiff2))
// Combine mapped differences into a single line
mappedLine = if close > ema
mappedDiff1
else
mappedDiff2
// Plot 'mappedLine' in the main chart area conditionally
plot(mappedLine, title="EMA Difference Mapping", color=(close > ema ? color.blue : na), style=plot.style_line, linewidth=2)
// Calculate the 50EMA and 200SMA
ema50 = ema(close, 50)
sma200 = sma(close, 200)
// Plot the 50EMA and 200SMA on the main chart
plot(ema50, color=color.blue, title="50 SMA", linewidth=2)
plot(sma200, color=color.red, title="200 SMA", linewidth=2)
// Initialize trade variables
var bool waitingForBuy = na
var bool waitingForSell = na
var bool buyConditionMet = false
var bool sellConditionMet = false
if not sellConditionMet and crossunder(ema50, sma200)
sellConditionMet := true
waitingForBuy := false
if sellConditionMet
waitingForSell := true
sellConditionMet := false
if waitingForSell and close < sma200 and mappedLine > 75
strategy.entry("Sell", strategy.short)
strategy.exit("Sell Exit", "Sell", profit=takeProfitPoints, loss=stopLossPoints)
waitingForSell := false
// Define the strategy conditions and execute trades
if not buyConditionMet and crossover(ema50, sma200)
buyConditionMet := true
waitingForSell := false
if buyConditionMet
waitingForBuy := true
buyConditionMet := false
if waitingForBuy and close > sma200 and mappedLine < 25
strategy.entry("Buy", strategy.long)
strategy.exit("Buy Exit", "Buy", profit=takeProfitPoints, loss=stopLossPoints)
waitingForBuy := false
Expand (81 lines)
Overview
After the 50-period EMA crosses the 200-period SMA, it waits for price to stay on the crossover side and for the mapped line to pass 75 for shorts or 25 for longs. Entries use strategy.entry, and exits use point-based take profit and stop loss. Inputs change the EMA length, standard-deviation length, and both exit distances. The 50 EMA and 200 SMA are drawn in the same pane as the mapped line.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
EMA Length
int
20
emaLength
Standard Deviation Length
int
2
stdDevLength
Take Profit (in Points)
int
1000
takeProfitPoints
Stop Loss (in Points)
int
2500
stopLossPoints
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This strategy combines an EMA ribbon with MACD confirmation and plots in a separate pane. It enters when ribbon alignment, optional MACD zero or signal crosses, volume, smart-money, and multi-timeframe filters agree, then exits with percentage stop loss and ta
Kenny's Strategy combines multiple exponential moving averages to identify trend changes and generate entry signals. It calculates short, medium, and long EMAs from a user-selected source and checks for alignment within specific zones. A long-term EMA filter r
This strategy combines multiple technical indicator systems into a composite trading setup. It computes an Ichimoku Cloud, an ATR-based trailing stop system (nKRAL) with optional Heikin Ashi smoothing, Bollinger Bands, Parabolic SAR, and higher-timeframe Super
ETHBTC MTPI is a multi-indicator trend-following strategy designed for crypto pairs to determine relative market strength. It combines up to five toggleable components: Liquidity-Weighted Supertrend, dual exponential moving averages, DEMA Supertrend, DEMA AFR,
Sentiment 2 is a trend-following strategy that calculates a normalized composite market sentiment score ranging between 0 and 1. It combines exponential and Hull moving average slopes, high/low midpoints, Supertrend distances, and Parabolic SAR metrics. Plotte
This strategy template provides a modular foundation for building TradingView v6 backtests. It uses a placeholder Exponential Moving Average crossover signal combined with customizable filters for higher-timeframe trend alignment, volatility regime thresholds,