TradingView
MirNader_
2 Feb 2023 pukul 19.28

Price Swing Detection - Smart Money Concept 

EUR/USDOANDA

Huraian

Since my own style is Smart Money Concept and these days I have seen a lot of my friends who are having trouble identifying structures for their indicators and strategies. I wrote this code so they could use it in their strategy . In fact, this type of structure, as one of the strongest technical structures, can increase the success of your strategy according to your personalization.

The script detects swings (i.e. significant highs and lows) in a financial instrument's price action over a specified period. The user can set the lookback period (number of candles to consider) and the colors of the lines representing bullish and bearish trends.

The script has two functions: detectSwing and pivot high. The detectSwing function calculates the swing highs and lows for the specified number of candles. The function uses the ta.highest and ta.lowest functions to find the highest and lowest prices, respectively, over the lookback period. The function also determines the swing state (high or low) of the current candle and returns the calculated swing values.

The pivot high function calculates the pivot high, which is an important step in detecting bullish structures in the market. If a new top (i.e. swing high) is found, the script updates the pivot high values and creates a line from the recent top to the last bar. The script also updates the trailing maximum values, which are used to extend the top extension line.

For Strategy :
The variable "trendDirection" in the code is used to keep track of the trend state, either bullish (up trend) or bearish (down trend), in the market. The variable is initialized to 0 which represents a downtrend. The value of this variable is updated later in the code based on the calculations of swing highs and lows, pivot crosses, and the trailing maximum. If a bullish structure is detected, the value of "trendDirection" is set to 1, indicating an uptrend.

Nota Keluaran

Part of the code was related to the identification of low structure was difficult and fixed.
Also, in terms of writing, the code was updated to a clearer version.
Komen
bunulu
Simple, and good one
MirNader_
@bunulu, Thanks 🙏
bunulu
@MirNader_, found out what it calculates wrongly sometimes, for example price can be below lower line, which is super strange, i expect it to be shifted, with the candle low, or better to get price from a previous lower range
MirNader_
@bunulu, try with more than 50 candle look back , as you know in Smart Money we dont accept Structure with few candle , but thank you Mr
bunulu
@MirNader_, thx for the update, one small thing which i added manually, but might be good it you will add, line width, line style
MirNader_
@bunulu, Since you're a master and you know, I wrote this code just for use inside a strategy or an indicator of others, not for direct use of the indicator. But I'll make sure I add personalization to it.
Pro_RiskTaker
i rarely comment but i just wanted to share my gratitude this indicator is amazing, i have struggled with direction and this was the missing key to my strategy thanks!!!!!
MirNader_
@dthomas126, Your welcome Bro
ukmpits
@MirNader_ Sir, Is there any future Improvement? Thanks mate
ksufian10000
I have been back testing this on 1h but its amazing. the only draw back is that levels keep moving
Lebih