TA CROSSOVER, TIME BASE CONDITION and BACKTEST STAT

 


1. TA CROSSOVER(emaShort, emaLong)


This is a bullish crossover condition. It checks if the short EMA has just crossed above the long EMA, which can be a signal that the price is starting an uptrend.


emaShort is the short-period exponential moving average.


emaLong is the long-period exponential moving average.


ta.crossover(a, b) returns true only on the bar when a crosses above b.



So, this part means:

➡️ "The short EMA just crossed above the long EMA."



---


2. rsi < rsiOverbought


This checks if the Relative Strength Index (RSI) is below the overbought level, which helps filter out overextended or "too late" buys.


rsi is the current RSI value based on your selected period (default 14).


rsiOverbought is a user-defined level, usually around 70.



So this condition ensures:

➡️ "We only enter a long trade if RSI is not too high (not overbought)."



---


3. Combined as:


longCondition = ta.crossover(emaShort, emaLong) and rsi < rsiOverbought


This entire line defines when your strategy should enter a long trade:


A bullish EMA crossover happens and


RSI is still below the overbought level.



This helps avoid buying into a market that's already overbought after the crossover.



---


If you're wondering about the shortCondition, it's the opposite:


shortCondition = ta.crossunder(emaShort, emaLong) and rsi > rsiOversold


Enters short when the short EMA crosses below the long EMA and RSI is above the oversold level (to avoid selling at the bottom).




---------------



TIME-BASED CONDITION in a trading strategy is a rule that allows or prevents trades based on the time of day, day of the week, or other time-related factors.



This is useful when you want your strategy to only run during specific trading hours — for example, avoiding low-liquidity times like late nights or weekends (for crypto), or focusing only on the opening/closing hours of a market.



---


🔹 Common time-based conditions in Pine Script


1. Time of day


Run your strategy only during a specific time window (e.g., 9:00 to 16:00):


startHour = 9

endHour = 16

inTradingHours = (hour >= startHour) and (hour < endHour)


Use it in your condition:


longCondition = ta.crossover(emaShort, emaLong) and rsi < rsiOverbought and inTradingHours


2. Specific day of the week


Example: Only trade on weekdays (exclude Saturday and Sunday):


notWeekend = (dayofweek != dayofweek.saturday) and (dayofweek != dayofweek.sunday)


Combine it:


longCondition = ta.crossover(emaShort, emaLong) and rsi < rsiOverbought and notWeekend


3. Full timestamp check


If you want very precise control, use time or time(timeframe.period, session).


Example: Only trade between 09:00 and 15:00 New York time:


inSession = time(timeframe.period, "0930-1500") != na



---


✅ Why use time-based conditions?


Avoid low-volume or high-spread hours


Only trade during high-volatility sessions (e.g., London or New York)


Filter out false signals during weekends or after-hours


Backtest your strategy during realistic times


----------



! A backtest stat (short for backtest statistic) refers to performance results you get when you run your trading strategy on historical data. It tells you how your strategy would have performed in the past — not just whether it worked, but how well it worked.



---


🔹 Key Backtest Stats (on TradingView or any platform)


Here are the most important ones:


1. Net Profit


Total money gained or lost by the strategy over time.


Example: $2,450 profit from all trades combined.



2. Total Closed Trades


How many trades the strategy completed.


More trades = more data to analyze.



3. Win Rate (%)


Percentage of trades that were profitable.


Example: 60% win rate means 6 out of every 10 trades were winners.



4. Profit Factor


Ratio of total profit to total loss.


A value >1 means the strategy is profitable overall.


Example: Profit factor = 1.8 → for every $1 lost, you made $1.80.



5. Max Drawdown


The largest % drop from a peak in equity.


Lower is better. A high drawdown is risky.



6. Average Trade


The average gain or loss per trade.


Important for assessing risk/reward.



7. Sharpe Ratio (or similar)


Risk-adjusted return measure.


Higher values are better; it accounts for volatility.




---


🔍 Where to See This in TradingView?


If you're using Pine Script in TradingView and you've written a strategy() script (like yours), just run the script on a chart, and then:


1. Click "Strategy Tester" at the bottom of the chart.



2. You'll see a summary tab with the stats above.



3. Click "Performance Summary" or "List of Trades" for detailed analysis.





---


✅ Why Backtest Stats Matter


They help you:


Decide if your strategy is worth using live


Compare multiple strategies


Adjust risk management (e.g. stop loss, position size)


Avoid overfitting or false optimism


Comments

Popular Posts