How to develop a simple Buy&Sell strategy using Pine Script
157
In this article, will explain how to develop a simple backtesting for a Buy&Sell trading strategy using Pine Script language and simple moving average (SMA).
Strategy description The strategy illustrated works on price movements around the 200-period simple moving average (SMA). Open long positions when the price crossing-down and moves below the average. Close position when the price crossing-up and moves above the average. A single trade is opened at a time, using 5% of the total capital.
Behind the code Now let's try to break down the logic behind the strategy to provide a method for properly organizing the source code. In this specific example, we can identify three main actions: 1) Data extrapolation 2) Researching condition and data filtering 3) Trading execution
1. GENERAL PARAMETERS OF THE STRATEGY First define the general parameters of the script.
2. DATA EXTRAPOLATION In this second step we extrapolate data from the historical series. Call the calculation of the simple moving average using close price and 200 period bars.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.