How to write your own stock trading strategy / Indicator on TradingView
Being a trader working with Technical Analysis , we all look at multiple indictors like RSI , MACD , Moving Averages , Bollinger Bands … and the list goes on . In order to confirm our trades , we check these indicators , and combine it with other strategies like support, resistance, volume etc. When they all give a definite signal , we take position.
There is a way we can script(automate) this logic using TradingView’s PineScript. With Pinescript ->
- We can create a new strategy (combination of multiple indicators and logic)
- An indicator for that strategy
- Backtest it (test it against the previous time duration — past candles) — how well it could have performed .
And once the strategy gives us a signal , we can set alarms or in case you are making a trading bot , you can automate the process of taking positions as well.
Writing a simple strategy script (using sma crossover )
Let’s look at an easy example to get a better understanding. Suppose our strategy is -> we get confirmations from the values of SMA(Simple Moving Averages — SMA-9 and SMA-20) , whenever sma9 crosses up sma20 , we long or buy otherwise we sell or short when sma20…