- 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 is above the long period , and short positions are only placed if the short is bellow the long . 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.
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.
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.
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.
It's kinda ironic that this is strategy is so simple yet the code demands so much to get it working.
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.
Dalam semangat TradingView yang sebenar, penulis skrip ini telah menerbitkannya dengan menggunakan sumber terbuka supaya pedagang-pedagang dapat memahami dan mengesahkannya. Sorakan kepada penulis! Anda dapat menggunakannya secara percuma tetapi penggunaan semula kod ini dalam penerbitan adalah dikawalselia oleh Peraturan Dalaman. Anda boleh menyukainya untuk menggunakannya pada carta.
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.