Professional Documents
Culture Documents
An Example Trading Strategy in PineScript That Uses The ETH - USDT Pair On A 30-Minute Chart.
An Example Trading Strategy in PineScript That Uses The ETH - USDT Pair On A 30-Minute Chart.
chart. This strategy is a simple trend-following strategy that uses the moving average
crossover as the signal to enter and exit trades.
```
//@version=4
if (long_signal)
strategy.entry("Long", strategy.long)
if (short_signal)
strategy.entry("Short", strategy.short)
if (short_signal)
if (long_signal)
```
In this strategy, we define two inputs, `fast_ma_len` and `slow_ma_len`, which are used
to define the lengths of the fast and slow moving averages, respectively. The moving
averages are then calculated using the `sma()` function.
We then define the long and short signals based on the crossover of the fast and slow
moving averages using the `crossover()` and `crossunder()` functions.
The strategy entry and exit conditions are defined using the `strategy.entry()` and
`strategy.exit()` functions. The `strategy.long` and `strategy.short` arguments are used
to define the direction of the trades.
Finally, we plot the fast and slow moving averages using the `plot()` function.