banner



some good trading view breakout strategies

Trend-following can be a very profitable trading method acting. But this draw near is erect to execute: win percentages are typically low and drawdowns excessive. Let's see and measure how ace of those trend-followers strategies performs in TradingView.

IN THIS ARTICLE:

# Slue following with the ATR Channel gaolbreak scheme for TradingView

In Way of the Turtle, Curtis Religion (2007) describes his lessons as one of the original Turtles. In the eighties Turtles were commonplace people trained by Richard Dennis, a identical successful trader. He taught them cardinal profitable slew-following strategies and, once they completed their training, gave them an bill of up to $2 one thousand thousand to trade. During his Capsize years Faith earned all over $30 one thousand thousand for Dennis.

Turtles were trend followers. Style followers try to benefit from large price movements that occur complete the span of several months (Faith, 2007). They buy when markets make historical highs and short when prices plumb. For that to ferment trend followers require monetary value impulse to sustain in the same centering. What makes trend following difficult is that drawdowns can be huge, win percentages low, and lacking a couple of big trades can deflower an entire year of trading (Organized religion, 2007).

One trend-following strategy that Faith (2007) shares in his book is the ATR Channel Breakout scheme. This strategy is a volatility-based system that uses the Fair True Ramble (ATR) every bit a measure for price fluctuations. For this we plot an upper and lower band settled on recent unpredictability. Those bands get in easier to name price movements that go game beyond the regular trading range and mark the start of a new slue, or so the underlying idea goes.

Let's see what trading rules that scheme has and how we plan information technology for TradingView.

# Trading rules of the ATR Channel break strategy

The ATR Channel gaolbreak scheme has the following trading rules (Faith, 2007):

  • Enter long rules:
    • Open a mindful position when the close is above the top side of the channel, which is computed arsenic follows: 350-day moving average + 7 x the 20-bar Average True Range (ATR).
  • Exit long rules:
    • Close the long position when prices cross down the stairs the 350-day blown average.
  • Enter short rules:
    • Open a short position when the close is under the bottom of the canalise, computed as follows: 350-day moving average - 3 x ATR.
  • Exit squat rules:
    • Cover the deficient lay out when prices cross in a higher place the 350-day moving average.
  • Lay out sizing:
    • For long and brief positions, determine the position size past dividing 0.5% of equity by the note value of the market's 20-bar Average True Range (ATR) in terms of dollars.

One thing this strategy lacks is a plosive speech sound-loss order. Still, there is an implicit halt: when prices move against the position, at about point they leave track the 350-day moving average. That testament then trigger the strategy's exit signal. This way losses are limited, merely not in the sense that there's a fixed stop-loss price that we know in advance.

Some other thing to note is that Faith (2007) didn't delimitate the type of moving average. Based on my interpretation of his book, I assume He uses a Simple Moving Average (SMA).

The profitable backtest that Faith (2007) performed was done on daily data and a wide range of futures markets. The backtested instruments included foreign telephone exchange (Australian dollar, British pound, Euro), commodities (gold, crude, fuzz, natural flatulence), spongy commodities (cotton, coffee, cattle, soybeans), and fixed-income futures (Treasury notes and bonds).

# Programing the ATR Channel prison-breaking trading strategy for TradingView

Now that we know the trading rules lease's code the strategy hand. A practical means to write strategies is to use a coding template. That breaks rising the large task of writing a scheme into smaller, easier-to-manage chunks of work. And it becomes less likely we neglect things. Plus it adds structure to our rational.

We'll use the following template to code the ATR Channel Breakout scheme:

                          //@version=3              // 1. Define strategy settings              // 2. Account strategy values              // 3. Output strategy information              // 4. Determine long trading conditions              // 5. Code short trading conditions              // 6. Submit entry orders              // 7. Submit expire orders                      

If you want to follow along with the article, make a new strategy script in TradingView's Yearn Editor and spread in the in a higher place template.

To get an idea of what the code we will write actually does, here's how the completed strategy looks connected the graph:

Example chart of TradingView's ATR Channel Breakout strategy

Now rent's start with steganography this strategy for TradingView.

# Step 1: Delineate strategy settings and input options

We first define the strategy's settings and its input options. For this we use the following code as our first abuse:

                          //@version=3              // 1. Define scheme settings              strategy(title=              "ATR Channel Breakout"              ,              overlay=              true              ,              pyramiding=              0              ,              initial_capital=              100000              ,              commission_type=              strategy.commission.cash_per_order              ,              commission_value=              4              ,              slippage=              2)  smaLength              =              input(title=              "SMA Duration"              ,              type=              integer              ,              defval=              350) atrLength              =              input(title=              "ATR Length"              ,              type=              integer              ,              defval=              20)  ubOffset              =              input(title=              "Upperband Offset"              ,              character=              float              ,              defval=              7              ,              stone's throw=              0.50) lbOffset              =              stimulant(title=              "Lowerband Offset"              ,              type=              float              ,              defval=              3              ,              pace=              0.50)  usePosSize              =              input signal(title=              "Exercise Office Size?"              ,              typewrite=              bool              ,              defval=              echt) riskPerc              =              stimulation(title=              "Risk of exposure %"              ,              type=              float              ,              defval=              0.5              ,              step=              0.25)                      

We set the handwriting's settings with the scheme() function. Besides the typical options we use pyramiding to switch off scaling into positions. With initial_capital we set the strategy's starting funds to 100,000. We determined the commission to 4 (commission_value) for to each one trade (commission_type). With the slippage argument set to 2, stop and commercialize orders are 2 ticks to a lesser extent favourable. (With the commission and slippage pessimistic the scheme really has to prove its worth.)

Side by side we add the strategy's input options. We do that with the input() function. The first two input options, 'SMA Length' and 'ATR Distance', are integer inputs we employment for the ATR channel. We establish these a default value of 350 and 20.

The adjacent deuce are unfixed-point input options: 'Upperband Offset' and 'Lowerband Offset'. These will determine how many ATR multiplies the upper and lower band are placed from the average. They get defaults of 7 and 3.

Next is a Boolean true/false stimulation option: 'Use Position Sizing?'. With this setting we pass easy to on-off switch the scheme's position size algorithm connected surgery off. We start with using that algorithm (defval=true), merely if we turn this setting off the strategy leave simply trade one contract for each trade.

The 'Risk %' is the last input selection. This indefinite defines how so much fairness the placement sizing code uses per trade. It starts with 0.5% risk as the default.

We store the value of each input option in a variable. That manner we seat reference the input option's current esteem later happening by simply using the variable.

# Step 2: Calculate trading strategy values

For the second step we calculate the scheme's values:

                          // 2. Estimate scheme values              smaValue              =              sma(close              ,              smaLength) atrValue              =              atr(atrLength)  upperBand              =              smaValue              +              (ubOffset              *              atrValue) lowerBand              =              smaValue              -              (lbOffset              *              atrValue)  riskEquity              =              (riskPerc              /              100)              *              scheme.fairness              atrCurrency              =              (atrValue              *              syminfo.pointvalue) posSize              =              usePosSize              ?              floor(riskEquity              /              atrCurrency)              :              1                      

First we see the SMA with TradingView's sma() function. We have that function keep going closing prices (hand-to-hand) for the number of parallel bars go under away the smaLength input unsettled. Then we calculate the ATR with the atr() function and the atrLength stimulant protean. We store these two computed values in the smaValue and atrValue variables.

Next we calculate the ATR channel's upper and lower band. For the upper band we increase the SMA with the ATR prize multiplied aside ubOffset, the stimulus variable we gave a nonpayment of 7. To arrive at the lower band's value we drop-off the SMA with lbOffset times the ATR. We hive away these band values in the upperBand and lowerBand variables.

Then we count on the position size of it. The algorithm that Faith (2007) uses has two components: a per centum of fairness and the ATR in currency rate. The first part has us water parting riskPerc with 100. That translates the percentage-supported input signal choice into a quantitative prize (so 0.5% becomes 0.005). Then we manifold with strategy.fairness, a variable that returns the strategy's current fairness (that is, first capital + congregate net benefit + open position profit) (TradingView, n.d.).

To determine the currency value of the ATR we breed atrValue with syminfo.pointvalue. That TradingView uncertain returns the point value for the current instrument (TradingView, n.d.). For example, for the E-mini Sdanamp;P this variable returns 50 since one point of price movement in ES is worth $50. For crude oil futures, which give birth an underlying of 1,000 barrels, syminfo.pointvalue returns 1,000.

The posSize variable we make next holds the strategy's position size of it. Here we possess the conditional operator (?:) check if the usePosSize input versatile is true. When it is, we divide the risk equity with the ATR currency value. Then we use the floor() function to round the position size low to the nearest full integer. Should that input variable be off-key, however, we simply set posSize to 1. That has us always trade one contract when the position sizing input is overturned off.

# Step 3: End product the strategy's information and visualise signals

To reach it easier to formalize the strategy, we plot its data on the chart next:

                          // 3. Output scheme data              plot(series=smaValue,              title=              "SMA"              ,              color=              orange)              plot(series=upperBand,              title=              "UB"              ,              color=              green              ,              linewidth=              2)              plot(serial publication=lowerBand,              entitle=              "LB"              ,              color=              red              ,              linewidth=              2)                      

We show the strategy's values happening the graph with TradingView's plat() part. The first plot() statement shows the 350-day fast-flying average (smaValue). We name that plat 'SMA' and colour it orange.

The next ii plot() function calls show the ATR channel's upper and lower band on the chart. We show upperBand values in the green colour and have lowerBand values show with the Red River colour value. With the linewidth arguin set to 2 these line plots are a morsel thicker than perpendicular.

# Step 4: Code the long trading rules

Next up are the conditions that determine when we open and exit long positions. From the trading rules above we know that the strategy goes long when the close breaks above the channel's upper band. And long positions are blocked when prices go below the simple moving norm.

Hera's how we understand that into code:

                          // 4. Watch polysyllabic trading conditions              enterLong              =              crossover(close              ,              upperBand) exitLong              =              crossunder(close              ,              smaValue)                      

The introductory Boolean variable we spend a penny here, enterLong, gets its true/faux value from crossover(). That improved-in function returns true when the evaluate of its first argument crossed to a higher place that of the second argument (TradingView, n.d.). Here we take in the function chip if the instrument's closing prices (close) cross above the ATR channel's upper banding (upperBand). This makes enterLong avowedly when prices break to a higher place the channel and false when they don't.

The exitLong Boolean variable gets its value with the crossunder() function. That function returns true when the value of its first argument dropped below that of the second argument (TradingView, n.d.). We run that function happening closing prices and the 350-bar SMA (smaValue). This manner exitLong is true when prices break to a higher place the self-propelling common. When that situation doesn't bechance on the contemporary bar, exitLong is spurious.

# Stone's throw 5: Computer programme the short trading conditions

Then we calculate the unforesightful conditions. As the trading rules mentioned, we go short when prices next below the lower ATR channel band. And we exit underdrawers when prices act above the SMA.

In code those conditions look like:

                          // 5. Code short trading conditions              enterShort              =              crossunder(close              ,              lowerBand) exitShort              =              crossover(close              ,              smaValue)                      

We set the enterShort Boolean changeable with crossunder(). Present we suffer the function check if closing prices (close) dropped below the ATR channelize (lowerBand). When they did, the variable is true. Otherwise, false is the variable's value.

We code the exitShort adaptable so that it monitors whether the closing prices get above the SMA (smaValue). When they do, the changeable is true and else its measure is false.

# Step 6: Open a trading situatio with entry orders

Next we utilise the true/false variables from the previous steps to open long-handled and short positions:

                          // 6. Submit entrance orders              if              (enterLong)              scheme.entry(id=              "EL"              ,              long=              true              ,              qty=posSize)              if              (enterShort)              strategy.entry(ID=              "ES"              ,              long=              false              ,              qty=posSize)                      

The first if statement checks whether enterLong is echt. When IT is, we feature the strategy.entryway() function open a lank position (long=true). We give that order the 'EL' identifier. And use the posSize variable to define the order's quantity. Given how we coded that variable earlier, it either holds an ATR-based risk of exposure of 0.5% equity or a default option position size of 1 contract.

The other if statement evaluates enterShort. When that variable is true during the current playscript calculation, strategy.entry() submits an enter short order (long=false). We public figure that ordering 'ES' and submit it for posSize contracts.

# Step 7: Close market positions with exit orders

Then we need to specify when the strategy should go out positions. We use this code for that:

                          // 7. Submit exit orders              strategy.close(id=              "EL"              ,              when=exitLong)              strategy.shut(id=              "Einsteinium"              ,              when=exitShort)                      

The first strategy.close() function call closes our enter daylong order (id="EL"). That function submits market orders. We have it take those orders when the exitLong variable is sure, which happens when the close drops below the billowing average out.

The second strategy.close() statement closes our short launching order (Idaho="ES") when the exitShort Boolean variable is true. That happens when prices cross above the SMA.

Incidentall, the strategy.close() mathematical function only comes into set up when there is an unconcealed gild with the specified ID (TradingView, n.d.). Say we're short and for whatever reason exitLong becomes true. In that case strategy.close() will not close our fugitive position; it exclusively exits based along exitLong when in that location's an open long order, not open short-range position.

Now that we coded all the strategy's parts, permit's take a quick position at the strategy's performance.

# Carrying into action of the ATR Channel Prisonbreak strategy for TradingView

Permit's start with the positive: the ATR Distribution channel Breakout strategy performs very comfortably during long-term trends. Here, for instance, the strategy traded a multi-year downtrend in crude oil futures when prices more than halved:

Profitable trade by the example TradingView strategy in crude oil futures

The strategy too has its weak points. When prices move sideways, the ATR Channel Breakout strategy gets caught up in the chop up and incurs losing trade after losing trade. This is, nonetheless, a feature article that many trend-chase strategies portion.

In this sideways market the strategy didn't take in a winning trade wind for several years:

Subpar performance of the ATR Channel Breakout strategy for TradingView

The table below shows the strategy's backtest performance on two instruments. These results are with position sizing disabled. When the strategy did size of it positions based on Faith's (2007) algorithm, trading would on some instruments stop before the end of the backtest (because of deficient capital). But the to a greater extent trades thither are in a backtest, the better we can trace conclusions of the strategy's operation. And so I performed the tests with position sizing off.

Operation metric Crude vegetable oil (Atomic number 17) Soybean (ZS)
First business deal 1984-08-30 1971-08-11
Last trade 2017-06-07 2018-01-22
Time frame 1 day 1 day
Last profit -$8,278 -$62,731
Crude profit $119,264 $91,564
Gross loss -$127,542 -$154,295
Max drawdown $64,000 $72,269
Turn a profit factor 0.935 0.593
Summate trades 41 68
Winning trades 12 17
Win percent 29% 25%
Avg merchandise -$201 -$922
Avg win trade $9,938 $5,386
Avg losing barter -$4,398 -$3,025
Win/loss ratio 2.26 1.78
Commission gainful $332 $548
Slippage per lodg 2 ticks 2 ticks

# Ideas to improve the ATR Channel Breakout scheme

Atomic number 3 the results above show, the performance of the ATR TV channel Breakout strategy terminate definitely use some improvement. Here are several ideas you might find valuable to experiment with:

  • The strategy experienced wild swings in equity, partly because of the long-run moving normal of 350 bars connected a time unit chart. Perhaps the strategy can reply quicker to (failed) trends on a lower time fles and/or with a moving average that doesn't enjoyment that many parallel bars.
  • Faith (2007) didn't discuss wherefore he choose the parameter settings that helium did. IT also isn't net why the top band is based on 7 multiplication the ATR while the frown band uses 3 multiplication the ATR. The strategy might perform better with other parameters, peculiarly when they suit the musical instrument and chart's time couc.
  • A course filter would definitely improve the strategy. That helps to not outdoors positions when the market moves sidelong, which in turn prevents a lot losing trades.
  • The strategy didn't manipulation stop-loss orders, only only an implicit stop: positions were closed when prices crossed the 350-bar moving mean. Merely the strategy probably doesn't deliver to wait until prices span that wriggly fair before information technology knows the location isn't going anywhere. Moreover, the scheme might bring more peacefulness when we know there's an actual stop-loss order in the market. So an experiment with stop-loss orders seems appropriate.
  • Perhaps the strategy likewise becomes better with risk of exposure direction. We can, e.g., limit the strategy's drawdown. Oregon place a cap along the position size. See the risk direction class for some other ideas.

# Complete code of the ATR Channel breakout strategy for TradingView

The glutted encrypt of the ATR Distribution channel Breakout scheme is below. Touch o to the discussion supra for details about specific parts.

                          //@reading=3              // 1. Define strategy settings              scheme(statute title=              "ATR Channel Prison-breaking"              ,              overlay=              true              ,              pyramiding=              0              ,              initial_capital=              100000              ,              commission_type=              strategy.commission.cash_per_order              ,              commission_value=              4              ,              slippage=              2)  smaLength              =              input(title=              "SMA Length"              ,              type=              integer              ,              defval=              350) atrLength              =              stimulation(title=              "ATR Length"              ,              type=              whole number              ,              defval=              20)  ubOffset              =              stimulation(title=              "Upperband Offset"              ,              type=              float              ,              defval=              7              ,              step=              0.50) lbOffset              =              input(claim=              "Lowerband Offset"              ,              type=              float              ,              defval=              3              ,              step=              0.50)  usePosSize              =              input(title of respect=              "Use Perspective Sizing?"              ,              typewrite=              bool              ,              defval=              right) riskPerc              =              input(title=              "Risk %"              ,              eccentric=              float              ,              defval=              0.5              ,              step=              0.25)              // 2. Calculate strategy values              smaValue              =              sma(close              ,              smaLength) atrValue              =              atr(atrLength)  upperBand              =              smaValue              +              (ubOffset              *              atrValue) lowerBand              =              smaValue              -              (lbOffset              *              atrValue)  riskEquity              =              (riskPerc              /              100)              *              strategy.equity              atrCurrency              =              (atrValue              *              syminfo.pointvalue) posSize              =              usePosSize              ?              floor(riskEquity              /              atrCurrency)              :              1              // 3. Output strategy data              plot(series=smaValue,              title=              "SMA"              ,              color=              orange)              plot(serial=upperBand,              title=              "UB"              ,              colour in=              green              ,              linewidth=              2)              plot(series=lowerBand,              title=              "LB"              ,              color=              red              ,              linewidth=              2)              // 4. Determine long-snouted trading conditions              enterLong              =              crossover(close              ,              upperBand) exitLong              =              crossunder(last              ,              smaValue)              // 5. Code short trading conditions              enterShort              =              crossunder(proximate              ,              lowerBand) exitShort              =              crossover(close              ,              smaValue)              // 6. Submit entry orders              if              (enterLong)              scheme.entryway(id=              "EL"              ,              long=              trustworthy              ,              qty=posSize)              if              (enterShort)              strategy.entry(id=              "ES"              ,              recollective=              sour              ,              qty=posSize)              // 7. Submit conk orders              strategy.close(id=              "EL"              ,              when=exitLong)              strategy.close(Idaho=              "ES"              ,              when=exitShort)                      

For more strategy ideas, browse all TradingView example strategies. There are also various TradingView example indicators here along Kodify.

References

Faith, C.M. (2007). Direction of the Turtle: The Secret Methods that Turned Ordinary People into Legendary Traders. New York, NY: McGraw-Hill.

TradingView (n.d.). Pine Script Language Quotation Manual. Retrieved on September 13, 2022, from https://web.tradingview.com/report-script-reference/

Last updated connected (publicized ).

« All TradingView example strategies articles

some good trading view breakout strategies

Source: https://kodify.net/tradingview/strategies/atr-channel-breakout/

Posted by: bishopsubbillson.blogspot.com

0 Response to "some good trading view breakout strategies"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel