EduardoMattje

Reversal closing price

The reversal closing price ( RCP ) is a candlestick pattern which follows two simples rules:

  • the low price of current candle needs to be lower than the low price of the last 2 candles
  • the closing price of current candle needes to be higher than the closing price of the last candle

This generates a signal for a long position. For a short position, the conditions are inverted:

  • the high price of current candle needs to be higher than the high price of the last 2 candles
  • the closing price of current candle needes to be lower than the closing price of the last candle

Since RCP is a trend follower indicator, the strategy is programmed in such a way that long positions are only placed if the short period EMA is above the long period EMA , and short positions are only placed if the short EMA is bellow the long EMA . Both periods are configurable, and should be ajusted for each asset.

This strategy uses a fixed stop loss and take profit, and the it's ratio is configurable. The stop price is one tick lower than the lowest price of X candles prior to the order execution for long positions, while in short positions it's one tick higher than the higher price. The amount of candles to lookback (X) is configurable. Both stop and take profit prices are displayed, the first as a red line, and the second as a green line.

This is the setting that I've found to work best with TVC:SPX , but you may find a better setting. While the RCP is universal, it's placement depends on the trend and it's strenght, something that is very heterogeneous among assets.

I really wish that I was able to place images, but I don't have PRO, so text will have to do.

This strategy was designed by Alexandre Wolwacz, a.k.a. Stormer.
릴리즈 노트: This is an update to include different types of moving averages. You can choose if you want an EMA, a SMA, a HMA or a WMA. If you want another type of MA, please comment and I can add it.

I've also added an option for the orders to take place regardless of the trend. It is disabled by default because in 99% of the time you will want to trade in favor of the trend, not against it.

There are also two settings I forgot to mention on the original post:

If an RCP is generated, but the trade is not triggered, the order price will be retraced to the new candle price. This is done until the trade is taken. So if the RCP gives a signal at 10.61, but the high of the next candle is 10.58, the order's buy price will be retraced to 10.59 (remember, the high of the candle + 1 tick). If the max of the next candle is 10.56, the price will be retraced to 10.57. And so on, until the order is triggered. This can be disabled in the "Allow price retracing" check. Note that the same applies for short positions, but inverted.

If you are in a long position, but the moving average crosses downwards, signalling the beggining of a down trend, you can exit the current position if the "Close if EMA crosses in oposite direction" is checked. The same applies for short positions, but inverted.
릴리즈 노트: This is a very big update.

Firstly the strategy now calculates a fixed amount of risk. To get it working I had to do what we in Brazil call a "gambiarra". The first order is to get how many money are you willing to lose, and that money is going to be risk for every single order in the future. In other words, you will always gain the same amount, and always lose the same amount, the strategy will calculate the size of the order for that to happen, thus making a positive mathmatical expectation actually possible.

The stop loss orders are working better, since the calc_on_order_fill was enabled, thus allowing them to end on the same candle they opened. But as I said on the original post, you need to mind the gap. The stop loss won't save you if the gap is big.

Unfortunatelly, I couldn't get comments in the exit positions working, because Pine Script uses the last candle to calculate prices, not the one that actually closes the order. Maybe there is a way to do it, but I spent so many time trying to fix the stop loss orders that it just isn't worth it simply for comments. Luckly it isn't a big problem, since you can see the stop and take profit prices. Maybe in a future update the Trading View team is going to implement functions that should be basic. Really, you can't even place two exit orders at the same time, nor place one order with a fixed trigger price, a stop loss price and a take profit price. Sorry for the rant, but it just boggles me that Pine Script is in version 4 and it doesn't have a function that Backtr*der has, which is both free and open source.
릴리즈 노트: Fixed negative take profit values for short positions, something that happened in a stock like OIBR3. Also added an option to filter the trend with the stochastic oscillator, which is disabled by default.
릴리즈 노트: Fixed a price retracing bug.
릴리즈 노트: Added an option to place the stop loss at a bottom or a top. A bottom happens when the low of a candle is lower than the adjacent lows, so it makes a V shape. Similarly, a top is an ^ shape, with the high of the candle being higher than the it's adjacent highs. This is affected by the stop lookback parameter, it will take the lowest or highest price of the lookback period.

While this option is not necessary in a daily or weekly graph, it may be interesting in an intraday graph, since they have a low liquidity and the chance of false stops being higher.

Also fixed a silly bug that caused orders to be canceled for no reason because of price retracing.
릴리즈 노트: Now the bottom/top stoploss is actually working. I tought that by using a simple operator I could get the older values, but the operator is for bars, so I had to do another gambiarra and use arrays to get the prices instead.

It's kinda ironic that this is strategy is so simple yet the code demands so much to get it working.
릴리즈 노트: Added KAMA as an option for the MAs and now you can retrace the stop price if a new signal is given in the same direction. Orders are also canceled if you disabled price retracing, something that should have happened for a long time.
릴리즈 노트: Included different types of MA trends, as well as oscillators.
릴리즈 노트: Made some fixes to the take profit price.
릴리즈 노트: I made use of the new group and inline features in the input functions, hopefully it is less of a mess now.

I also changed how the stop and take profit works, so now it won't close the position at the high or low of a candle in the same candle it was opened, making the results more accurate. I wish I could use the := operator on a variable list, but PineScript doesn't allow me to do that (yet), which made the code WET in some parts. At least it still works.
오픈 소스 스크립트

진정한 TradingView의 정신에 따라, 이 스크립트의 작성자는 스크립트를 오픈소스로 게시했기에 거래자들이 이해하고 확인할 수 있습니다. 작가님께 건배! 스크립트를 무료로 사용할 수 있지만, 게시물에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 당신은 스크립트를 차트에 사용하기 위해 그것을 즐겨찾기 할 수 있습니다.

차트에 이 스크립트를 사용하시겠습니까?

코멘트

Top, vi teu comentário lá, mandou bem no inglês, Stormer é uma pessoa sensacional e admirável... Padrão bem top, mas é isso, sucesso aí meu amigo
응답
Nice one mate, your scripts are getting better and better :)
응답
Hi, nice strategy! Would you make the alert version?
응답
EduardoMattje kylejeon83
@kylejeon83, unfortunatelly I can't easily code alerts because TradingView doesn't allow them on strategys, and I can't code a study because all of the functions of the strategy, such as position size, direction, and retracing wouldn't be avalible. It's like what I said in the post: we're in version 4 of PineScript and it still lacks basic functionallity.

If you just want to receive alerts based on when a RCP is active, I can code that, but you need to keep in mind that the other things I mentioned wouldn't appear.
응답
kylejeon83 EduardoMattje
@EduardoMattje, Thank you for your reply. I understand your advice. have a nice day! :)
응답
This code is getting bigger than my payroll
응답
Very nice design, thanks for sharing.
응답
There are also other two settings I forgot to mention:

If an RCP is generated, but the trade is not triggered, the order price will be retraced to the new candle price. This is done until the trade is taken. So if the RCP gives a signal at 10.61, but the high of the next candle is 10.58, the order's buy price will be retraced to 10.59 (remember, the high of the candle + 1 tick). If the max of the next candle is 10.56, the price will be retraced to 10.57. And so on, until the order is triggered. This can be disabled in the "Allow price retracing" check. Note that the same applies for short positions, but inverted.

If you are in a long position, but the moving average crosses downwards, signalling the beggining of a down trend, you can exit the current position if the "Close if EMA crosses in oposite direction" is checked. The same applies for short positions, but inverted.
응답
홈으로 스탁 스크리너 포렉스 스크리너 크립토 스크리너 이코노믹 캘린더 정보 차트 특징 프라이싱 프렌드 리퍼하기 하우스룰(내부규정) 헬프 센터 웹사이트 & 브로커 솔루션 위젯 차팅 솔루션 라이트웨이트 차팅 라이브러리 블로그 & 뉴스 트위터