EduardoMattje

Reversal closing price

EduardoMattje 업데이트됨   
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 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.
릴리즈 노트:
I made the strategy more accurate and faster.
릴리즈 노트:
Added the ability of having two targets.
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

면책사항

이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

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