指标和策略
Lokesh(bank nifty option buying) MA Crossover with RSI use it directly in bank nifty option chart for 5 minute time frame specialy for put buying
RSI Trading Strategy with EMA and ATR Profit __ahmad__razavi__
### Code Breakdown
1. **Strategy Declaration**:
```pinescript
//@version=6
strategy("RSI Trading Strategy with EMA and ATR Stop Loss/Take Profit", overlay=true)
```
- `//@version=6`: This specifies that the script uses version 6 of Pine Script.
- `strategy(...)`: This function defines the properties of the trading strategy, including its title and whether it overlays on the price chart (`overlay=true`).
2. **Input Parameters**:
```pinescript
length = input.int(14, minval=1, title="RSI Length")
src = input(close, title="Source")
rsi = ta.rsi(src, length)
```
- `length`: Input for the RSI length, defaulting to 14.
- `src`: Input for the source data (default is the closing price).
- `rsi`: Calculation of the RSI based on the specified source and length.
3. **Smoothing the RSI**:
```pinescript
smoothingLength = input.int(14, minval=1, title="Smoothing Length")
smoothedRsi = ta.ema(rsi, smoothingLength) // Using EMA to smooth RSI
```
- This section defines a smoothing length and calculates a smoothed version of the RSI using an Exponential Moving Average (EMA).
4. **ATR Calculation**:
```pinescript
atrLength = input.int(14, title="ATR Length")
atrMultiplier = input.float(1, title="ATR Multiplier")
atrValue = ta.atr(atrLength) // Calculate ATR
```
- `atrLength`: Input for the ATR calculation period.
- `atrMultiplier`: Input to set how many times the ATR will be used for stop-loss and take-profit levels.
- `atrValue`: Calculation of ATR based on the specified length.
5. **Trading Conditions**:
The following conditions define when to enter long or short positions based on RSI levels:
- **Long Entry Condition**:
```pinescript
if (ta.crossover(smoothedRsi, level2))
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit/Stop Loss", "Long", stop=close - atrMultiplier * atrValue, limit=close + atrMultiplier * atrValue, comment="")
crossCount := crossCount + 1
crossPrice := close
```
- A long position is entered when the smoothed RSI crosses above level 70 (`level2`).
- The exit conditions set a stop-loss and take-profit based on ATR.
- **Short Entry Condition**:
```pinescript
if (ta.crossunder(smoothedRsi, level2))
strategy.entry("Short", strategy.short)
strategy.exit("Take Profit/Stop Loss", "Short", stop=close + atrMultiplier * atrValue, limit=close - atrMultiplier * atrValue, comment="")
crossCount := crossCount + 1
crossPrice := close
```
- A short position is entered when the smoothed RSI crosses below level 70.
- Similar exit conditions apply as in long entries.
- **Additional Long and Short Conditions**:
The script also includes conditions for entering long positions when crossing above level 30 (`level1`) and short positions when crossing below level 30.
6. **Cross Count Table**:
```pinescript
if (not na(crossPrice))
table.cell(crossingTable, 0, crossCount % 5, text=str.tostring(crossCount), bgcolor=color.green)
table.cell(crossingTable, 1, crossCount % 5, text=str.tostring(crossPrice), bgcolor=color.green)
```
- A table is created to display the count of crosses and their prices.
- The table updates every time a crossover occurs.
7. **Plotting RSI and Levels**:
```pinescript
plot(smoothedRsi, title="Smoothed RSI", color=color.blue)
hline(level1, "Level 30", color=color.red)
hline(level2, "Level 70", color=color.green)
```
- The smoothed RSI is plotted in blue.
- Horizontal lines are drawn at levels 30 and 70 to indicate overbought and oversold conditions.
### Summary
This script provides a comprehensive trading strategy that utilizes both RSI and ATR to manage trades effectively. It allows traders to enter positions based on RSI movements while using ATR to set dynamic stop-loss and take-profit levels. Additionally, it keeps track of how many times the RSI has crossed specified levels and displays this information in a table on the chart.
Omega_galskyThe strategy uses three Exponential Moving Averages (EMAs) — EMA8, EMA21, and EMA89 — to decide when to open buy or sell trades. It also includes a mechanism to move the Stop Loss (SL) to the Break-Even (BE) point, which is the entry price, once the price reaches a Risk-to-Reward (R2R) ratio of 1:1.
Key Steps:
Calculating EMAs: The script computes the EMA values for the specified periods. These help identify market trends and potential entry points.
Buy Conditions:
EMA8 crosses above EMA21.
The candle that causes the crossover is green (closing price is higher than the opening price).
The closing price is above EMA89.
If all conditions are met, a buy order is executed.
Sell Conditions:
EMA8 crosses below EMA21.
The candle that causes the crossover is red (closing price is lower than the opening price).
The closing price is below EMA89.
If all conditions are met, a sell order is executed.
Stop Loss and Take Profit:
Initial Stop Loss and Take Profit levels are calculated based on the entry price and a percentage defined by the user.
These levels help protect against large losses and lock in profits.
Break-Even Logic:
When the price moves favorably to reach a 1:1 R2R ratio:
For a buy trade, the Stop Loss is moved to the entry price if the price increases sufficiently.
For a sell trade, the Stop Loss is moved to the entry price if the price decreases sufficiently.
This ensures the trade is risk-free after the price reaches the predefined level.
Visual Representation:
The EMAs are plotted on the chart for easy visualization of trends and crossovers.
Entry and exit points are also marked on the chart to track trades.
Purpose:
The strategy is designed to capitalize on EMA crossovers while minimizing risks using Break-Even logic and predefined Stop Loss/Take Profit levels. It automates decision-making for trend-following traders and ensures disciplined risk management.
EMA Crossover with RSI and DistanceEMA Crossover with RSI and Distance Strategy
This strategy combines Exponential Moving Averages (EMA) with Relative Strength Index (RSI) and distance-based conditions to generate buy, sell, and neutral signals. It is designed to help traders identify entry and exit points based on multiple technical indicators.
Key Components:
Exponential Moving Averages (EMA):
The strategy uses four EMAs: EMA 5, EMA 13, EMA 40, and EMA 55.
A buy signal (long) is triggered when EMA 5 crosses above EMA 13 and EMA 40 crosses above EMA 55.
A sell signal (short) is generated when EMA 55 crosses above EMA 40.
The distance between EMAs (5 and 13) is also important. If the current distance between EMA 5 and EMA 13 is smaller than the average distance over the last 5 candles, a neutral condition is triggered, preventing a signal even if all other conditions are met.
Relative Strength Index (RSI):
The 14-period RSI is used to determine market strength and direction.
The strategy requires RSI to be above 50 and greater than the average RSI (over the past 14 periods) for a buy signal.
If the RSI is above 60, a green signal is given, indicating a strong bullish condition, even if the EMA conditions are not fully met.
If the RSI is below 40, a red signal is given, indicating a strong bearish condition, regardless of the EMA crossover.
Distance Conditions:
The strategy calculates the distance between EMA 5 and EMA 13 on each candle and compares it to the average distance of the last 5 candles.
If the current distance between EMA 5 and EMA 13 is lower than the average of the last 5 candles, a neutral signal is triggered. This helps avoid entering a trade when the market is losing momentum.
Additionally, if the distance between EMA 40 and EMA 13 is greater than the previous distance, the previous signal is kept intact, ensuring that the trend is still strong enough for the signal to remain valid.
Signal Persistence:
Once a buy (green) or sell (red) signal is triggered, it remains intact as long as the price is closing above EMA 5 for long trades or below EMA 55 for short trades.
If the price moves below EMA 5 for long trades or above EMA 55 for short trades, the signal is recalculated based on the most recent conditions.
Signal Display:
Green Signals: Represent a strong buy signal and are shown below the candle when the RSI is above 60.
Red Signals: Represent a strong sell signal and are shown above the candle when the RSI is below 40.
Neutral Signals: Displayed when the conditions for entry are not met, specifically when the EMA distance condition is violated.
Long and Short Signals: Additional signals are shown based on the EMA crossovers and RSI conditions. These signals are plotted below the candle for long positions and above the candle for short positions.
Trade Logic:
Long Entry: Enter a long trade when EMA 5 crosses above EMA 13, EMA 40 crosses above EMA 55, and the RSI is above 50 and greater than the average RSI. Additionally, the current distance between EMA 5 and EMA 13 should be larger than the average distance of the last 5 candles.
Short Entry: Enter a short trade when EMA 55 crosses above EMA 40 and the RSI is below 40.
Neutral Condition: If the distance between EMA 5 and EMA 13 is smaller than the average distance over the last 5 candles, the strategy will not trigger a signal, even if other conditions are met.
VWAP RSI Strategy with Stop Loss and Fixed Buy Amountbuying in uptrend at the bottom band of vwap while rsi showing oversold. sellin hwhen price hits upper vwap band
MA + RSI Strategy//@version=5
strategy ("MA + RSI Strategy", overlay=true)
// Input Parameters
fastLength = input.int(9, title="Fast Moving Average Length")
slowLength = input.int(21, title="Slow Moving Average Length")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
// Moving Averages
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
// RSI
rsi = ta.rsi(close, rsiLength)
// Buy and Sell Conditions
longCondition = ta.crossover(fastMA, slowMA) and rsi < rsiOversold
shortCondition = ta.crossunder(fastMA, slowMA) and rsi > rsiOverbought
// Plotting Moving Averages
plot(fastMA, color=color.blue, title="Fast MA")
plot(slowMA, color=color.red, title="Slow MA")
// Signals
plotshape(series=longCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=shortCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Strategy Entry and Exit
if longCondition
strategy.entry("Buy", strategy.long)
if shortCondition
strategy.entry("Sell", strategy.short)
MA + RSI Strategy//@version=5
indicator("Buy and Sell Indicator", overlay=true)
// Input Parameters
fastLength = input.int(9, title="Fast Moving Average Length")
slowLength = input.int(21, title="Slow Moving Average Length")
rsiLength = input.int(14, title="RSI Length")
rsiOverbought = input.int(70, title="RSI Overbought Level")
rsiOversold = input.int(30, title="RSI Oversold Level")
// Calculations
fastMA = ta.sma(close, fastLength)
slowMA = ta.sma(close, slowLength)
rsi = ta.rsi(close, rsiLength)
// Buy and Sell Conditions
buyCondition = ta.crossover(fastMA, slowMA) and rsi < rsiOversold
sellCondition = ta.crossunder(fastMA, slowMA) and rsi > rsiOverbought
// Plot Buy and Sell Signals
plotshape(series=buyCondition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sellCondition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Plot Moving Averages
plot(fastMA, color=color.blue, title="Fast MA")
plot(slowMA, color=color.orange, title="Slow MA")
// Alerts
alertcondition(buyCondition, title="Buy Alert", message="Buy Signal Triggered!")
alertcondition(sellCondition, title="Sell Alert", message="Sell Signal Triggered!")
My strategy**Overview:**
This TradingView strategy implements a simple moving average (SMA) crossover system to identify potential buy and sell opportunities. It operates directly on the chart as an overlay, making it easy to visualize the entry points for both long and short positions.
---
**How It Works:**
1. **Long Condition:**
- A **long entry** is triggered when the 14-period SMA crosses above the 28-period SMA.
- This condition indicates a potential bullish trend where prices are gaining upward momentum.
2. **Short Condition:**
- A **short entry** is triggered when the 14-period SMA crosses below the 28-period SMA.
- This condition indicates a potential bearish trend where prices are losing upward momentum.
---
**Key Features:**
- **Overlay:** The strategy is applied directly to the chart, making it easy to align with price action.
- **Dynamic Entries:** Entry points for both long and short positions are based on SMA crossovers.
- **Fill Orders on Standard OHLC:** Ensures trades are executed using standard OHLC data for accuracy.
---
**Usage:**
- This strategy is ideal for traders who prefer straightforward technical analysis methods.
- It can be applied to various asset classes such as stocks, forex, and cryptocurrencies.
---
**Disclaimer:**
- This strategy is for educational purposes and is not financial advice. Test thoroughly in a simulated environment before using it in live trading.
ClosedLineOnlyOnly shows closed price on line chart
You need to hide the current price in line chart
This is helpful for avoiding false breakouts , focusing on only the closed price which is similar to what happens in backtesting , and many other things
It helps traders reduce psychological stress from continuously monitoring price and maintain discipline by viewing the chart only with closed price.
ClosedLineOnlyOnly shows closed price on line chart
You need to hide the current price in line chart
This is helpful for avoiding false breakouts , focusing on only the closed candles which is similar to what happens in backtesting , and many other things
It helps price action traders reduce psychological stress from continuously monitoring candles and maintain discipline by viewing the chart only with closed candles.
Bollinger Bands Strategy by NJBollinger Bands Strategy," leverages Bollinger Bands to make trading decisions. Bollinger Bands consist of three key components: a basis line (moving average), an upper band, and a lower band, which are calculated using the standard deviation of price movements.
Logic:
Entry Condition (Long): A long position is entered when the close price rises above the upper Bollinger Band, signaling a potential breakout or strong upward momentum.
Exit Condition: The long position is closed when the close price falls below the lower Bollinger Band, indicating potential downward pressure.
Features:
Users can adjust the moving average type, lookback length, and standard deviation multiplier to fit their trading style.
Trades are executed within a specified date range, which can be customized via inputs.
The strategy uses 100% of capital for each trade and incorporates commission and slippage into the performance calculation.
This strategy is suitable for trend-following traders looking to capture significant price movements using Bollinger Bands as the primary indicator.
5분봉 자동매매 전략 (최적화: 안정화)//@version=5
strategy("5분봉 자동매매 전략 (최적화: 안정화)", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// === PARAMETERS ===
// RSI
rsiPeriod = input.int(14, title="RSI Period", minval=1)
overbought = input.float(70.0, title="RSI Overbought Level", step=0.1)
oversold = input.float(30.0, title="RSI Oversold Level", step=0.1)
// 이동평균선
smaShort = input.int(50, title="Short SMA Length", minval=1)
smaLong = input.int(200, title="Long SMA Length", minval=1)
// 거래량 필터
volumeThreshold = input.float(1.2, title="Volume Multiplier", step=0.1)
// 리스크 관리
takeProfit = input.float(3.0, title="Take Profit %", step=0.1)
stopLoss = input.float(1.0, title="Stop Loss %", step=0.1)
trailOffset = input.float(0.5, title="Trailing Stop Offset (Points)", step=0.1)
// === INDICATORS ===
rsiValue = ta.rsi(close, rsiPeriod)
smaShortValue = ta.sma(close, smaShort)
smaLongValue = ta.sma(close, smaLong)
= ta.macd(close, 12, 26, 9)
= ta.bb(close, 20, 2)
avgVolume = ta.sma(volume, 20)
// 상위 시간대 RSI 필터
higherRSI = request.security(syminfo.tickerid, "15", ta.rsi(close, rsiPeriod), lookahead=barmerge.lookahead_on)
// === LONG ENTRY CONDITION ===
longCondition = (rsiValue < oversold) and
(smaShortValue > smaLongValue) and
(macdLine > signalLine) and
(close <= lowerBB) and
(volume > avgVolume * volumeThreshold) and
(higherRSI < 50)
// === SHORT ENTRY CONDITION ===
shortCondition = (rsiValue > overbought) and
(smaShortValue < smaLongValue) and
(macdLine < signalLine) and
(close >= upperBB) and
(volume > avgVolume * volumeThreshold) and
(higherRSI > 50)
// === POSITIONS ===
if (longCondition and strategy.position_size == 0)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", stop=strategy.position_avg_price * (1 - stopLoss / 100), limit=strategy.position_avg_price * (1 + takeProfit / 100), trail_points=trailOffset)
if (shortCondition and strategy.position_size == 0)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", stop=strategy.position_avg_price * (1 + stopLoss / 100), limit=strategy.position_avg_price * (1 - takeProfit / 100), trail_points=trailOffset)
// === 손절 신호 표시 ===
var bool stopLongShown = false
var bool stopShortShown = false
if (strategy.position_size > 0 and close <= strategy.position_avg_price * (1 - stopLoss / 100) and not stopLongShown)
label.new(bar_index, close, text="STOP_LONG", color=color.red, style=label.style_label_down, textcolor=color.white)
stopLongShown := true
if (strategy.position_size < 0 and close >= strategy.position_avg_price * (1 + stopLoss / 100) and not stopShortShown)
label.new(bar_index, close, text="STOP_SHORT", color=color.red, style=label.style_label_up, textcolor=color.white)
stopShortShown := true
if (strategy.position_size == 0)
stopLongShown := false
stopShortShown := false
// === VISUAL INDICATORS ===
plot(smaShortValue, title="SMA 50", color=color.blue)
plot(smaLongValue, title="SMA 200", color=color.red)
plot(upperBB, title="Upper BB", color=color.green)
plot(lowerBB, title="Lower BB", color=color.red)
plot(rsiValue, title="RSI", color=color.purple)
plot(longCondition ? close : na, title="Long Signal", style=plot.style_cross, color=color.green, linewidth=2)
plot(shortCondition ? close : na, title="Short Signal", style=plot.style_cross, color=color.red, linewidth=2)
itsmrk_Breakout Strategy_Testtest educational purpose test educational purpose test educational purpose test educational purpose test educational purpose
IU Higher Timeframe MA Cross StrategyIU Higher Timeframe MA Cross Strategy
The IU Higher Timeframe MA Cross Strategy is a versatile trading tool designed to identify trend by utilizing two customizable moving averages (MAs) across different timeframes and types. This strategy includes detailed entry and exit rules with fully configurable inputs, offering flexibility to suit various trading styles.
Key Features:
- Two moving averages (MA1 and MA2) with customizable types, lengths, sources, and timeframes.
- Both long and short trade setups based on MA crossovers.
- Integrated risk management with adjustable stop-loss and take-profit levels based on a user-defined risk-to-reward (RTR) ratio.
- Clear visualization of MAs, entry points, stop-loss, and take-profit zones.
Inputs:
1. Risk-to-Reward Ratio (RTR):
- Defines the take-profit level in relation to the stop-loss distance. Default is 2.
2. MA1 Settings:
- Source: Select the data source for calculating MA1 (e.g., close, open, high, low). Default is close.
- Timeframe: Specify the timeframe for MA1 calculation. Default is 60 (60-minute chart).
- Length: Set the lookback period for MA1 calculation. Default is 20.
- Type: Choose the type of moving average (options: SMA, EMA, SMMA, WMA, VWMA). Default is EMA.
- Smooth: Option to enable or disable smoothing of MA1 to merge gaps. Default is true.
3. MA2 Settings:
- Source: Select the data source for calculating MA2 (e.g., close, open, high, low). Default is close.
- Timeframe: Specify the timeframe for MA2 calculation. Default is 60 (60-minute chart).
- Length: Set the lookback period for MA2 calculation. Default is 50.
- Type: Choose the type of moving average (options: SMA, EMA, SMMA, WMA, VWMA). Default is EMA.
- Smooth: Option to enable or disable smoothing of MA2 to merge gaps. Default is true.
Entry Rules:
- Long Entry:
- Triggered when MA1 crosses above MA2 (crossover).
- Entry is confirmed only when the bar is closed and no existing position is active.
- Short Entry:
- Triggered when MA1 crosses below MA2 (crossunder).
- Entry is confirmed only when the bar is closed and no existing position is active.
Exit Rules:
- Stop-Loss:
- For long positions: Set at the low of the bar preceding the entry.
- For short positions: Set at the high of the bar preceding the entry.
- Take-Profit:
- For long positions: Calculated as (Entry Price - Stop-Loss) * RTR + Entry Price.
- For short positions: Calculated as Entry Price - (Stop-Loss - Entry Price) * RTR.
Visualization:
- Plots MA1 and MA2 on the chart with distinct colors for easy identification.
- Highlights stop-loss and take-profit levels using shaded zones for clear visual representation.
- Displays the entry level for active positions.
This strategy provides a robust framework for traders to identify and act on trend reversals while maintaining strict risk management. The flexibility of its inputs allows for seamless customization to adapt to various market conditions and trading preferences.
HOD/LOD/PMH/PML/PDH/PDL Strategy by @tradingbauhaus This script is a trading strategy @tradingbauhaus designed to trade based on key price levels, such as the High of Day (HOD), Low of Day (LOD), Premarket High (PMH), Premarket Low (PML), Previous Day High (PDH), and Previous Day Low (PDL). Below, I’ll explain in detail what the script does:
Core Functionality of the Script:
Calculates Key Price Levels:
HOD (High of Day): The highest price of the current day.
LOD (Low of Day): The lowest price of the current day.
PMH (Premarket High): The highest price during the premarket session (before the market opens).
PML (Premarket Low): The lowest price during the premarket session.
PDH (Previous Day High): The highest price of the previous day.
PDL (Previous Day Low): The lowest price of the previous day.
Draws Horizontal Lines on the Chart:
Plots horizontal lines on the chart for each key level (HOD, LOD, PMH, PML, PDH, PDL) with specific colors for easy visual identification.
Defines Entry and Exit Rules:
Long Entry (Buy): If the price crosses above the PMH (Premarket High) or the PDH (Previous Day High).
Short Entry (Sell): If the price crosses below the PML (Premarket Low) or the PDL (Previous Day Low).
Long Exit: If the price reaches the HOD (High of Day) during a long position.
Short Exit: If the price reaches the LOD (Low of Day) during a short position.
How the Script Works Step by Step:
Calculates Key Levels:
Uses the request.security function to fetch the HOD and LOD of the current day, as well as the highs and lows of the previous day (PDH and PDL).
Calculates the PMH and PML during the premarket session (before 9:30 AM).
Plots Levels on the Chart:
Uses the plot function to draw horizontal lines on the chart representing the key levels (HOD, LOD, PMH, PML, PDH, PDL).
Each level has a specific color for easy identification:
HOD: White.
LOD: Purple.
PDH: Orange.
PDL: Blue.
PMH: Green.
PML: Red.
Defines Trading Rules:
Uses conditions with ta.crossover and ta.crossunder to detect when the price crosses key levels.
Long Entry: If the price crosses above the PMH or PDH, a long position (buy) is opened.
Short Entry: If the price crosses below the PML or PDL, a short position (sell) is opened.
Long Exit: If the price reaches the HOD during a long position, the position is closed.
Short Exit: If the price reaches the LOD during a short position, the position is closed.
Executes Orders Automatically:
Uses the strategy.entry and strategy.close functions to open and close positions automatically based on the defined rules.
Advantages of This Strategy:
Based on Key Levels: Uses important price levels that often act as support and resistance.
Easy to Visualize: Horizontal lines on the chart make it easy to identify levels.
Automated: Entries and exits are executed automatically based on the defined rules.
Limitations of This Strategy:
Dependent on Volatility: Works best in markets with significant price movements.
False Crosses: There may be false crosses that generate incorrect signals.
No Advanced Risk Management: Does not include dynamic stop-loss or take-profit mechanisms.
How to Improve the Strategy:
Add Stop-Loss and Take-Profit: To limit losses and lock in profits.
Filter Signals with Indicators: Use RSI, MACD, or other indicators to confirm signals.
Optimize Levels: Adjust key levels based on the asset’s behavior.
In summary, this script is a trading strategy that operates based on key price levels, such as HOD, LOD, PMH, PML, PDH, and PDL. It is useful for traders who want to trade based on significant support and resistance levels.
Multi-Signal + ICT Concepts (HTF/FVG/Killzone/BOS)-CONSERVATIVEThis was made my chatgpt and my knowledgeable prompts
Multi-Signal + ICT Concepts (HTF/FVG/Killzone/BOS)-CONSERVATIVEThis was made my chatgpt and my knowledgeable prompts