So the following code in Pine-script on TradingView uses the Heikin-Ashi candle-bar open
price instead of the actual real open in the strategy tester panel.
Is there a way to get the strategy tester to use the real price?
This link explains the issue further.
//@version=2
strategy("haup", overlay=true)
cci20 = cci(close, 20)
sma10 = sma(close, 10)
source = close
sourcea = open
haclose = (open + high + low + close) / 4
haopen = na(haopen[1]) ? (open + close) / 2 : (haopen[1] + haclose[1]) / 2
fromYear = year > 2016
toYear = year < 2019
longCondition = haopen < haclose
if (longCondition and fromYear and toYear)
strategy.entry("Long 1", strategy.long)
closeCondition = haopen > haclose
if (closeCondition)
strategy.close("Long 1")
Heikin-Ashi has a smoother look because it is essentially taking an average of the movement. There is a tendency with Heikin-Ashi for the candles to stay red during a downtrend and green during an uptrend, whereas normal candlesticks alternate color even if the price is moving dominantly in one direction.
The formula for their calculation is given below: Open = (Previous Open + Previous Close) / 2. In regular candles, the open level is at the close of the previous candle (if there is no gap in the market). In Heikin Ashi, a new candlestick opens at the middle level, between the opening and closing of the previous one.
Heikin Ashi candles are calculated this way: Open: (Open (previous candle) + Close (previous candle))/2. Close: (Open + Low + Close + High)/4. High: the same of the actual candle.
You can do this two ways:
So I suggest using option (1).
Use this code to pull open/close/high/low of HA candles for your indicator.
openHA = security(heikinashi(tickerid), period, open)
closeHA = security(heikinashi(tickerid), period, close)
highHA = security(heikinashi(tickerid), period, high)
lowHA = security(heikinashi(tickerid), period, low)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With