I’m trying to turn the smoothed Heiken Ashi smoothed : Forum ProBuilder support – ProRealTime (prorealcode.com) from the blog into an equity strategy, which I still need to backtest. I think it is missing the price as I cannot get it to make a trade. Code is below. Happy to post backtest as a strategy once complete.
Stuart
DEFPARAM CumulateOrders = False // Cumulating positions deactivated
DEFPARAM FLATBEFORE = 093000
DEFPARAM FlatAfter = 154500
capital = 100000 + strategyprofit
Equity = capital / close
myCurrentProfit = STRATEGYPROFIT
// t and the deviation of the mean:
//t = 0 = average // Simple
//t = 1 = exponentialaverage
//t = 2 = weightedaverage
t = 3 = wilderaverage
//t = 4 = triangularaverage
//t = 5 = endpointaverage
//t = 6 = timeseriesaverage
P = 6
P1 = 2
T1 = WeightedAverage
if barindex > p + 1 then
mo = average[p,t](open)
mc = average[p,t](close)
ml = average[p,t](low)
mh = average[p,t](high)
//endif
once haopen=mo
haclose=(mo+mc+ml+mh)/4
haopen=(haopen[1]+haclose[1])/2
endif
HAopen1 = average[p1,t1](haopen)
HAclose1 = average[p1,t1](haclose)
// Draw indicator
Graph HAopen1 COLOURED(34,139,3) AS “Heiken Smoothed Cloud Open”
Graph HAclose1 COLOURED(225,0,0) AS “Heiken Smoothed Cloud Close”
// Conditions to enter long positions
IF NOT LongOnMarket AND HAopen1 Crosses Over HAclose1 THEN
BUY Equity SHARES AT MARKET
ENDIF
// Conditions to exit long positions
If LongOnMarket AND HAopen1 Crosses Under HAclose1 THEN
SELL AT MARKET
ENDIF
//
//Conditions to enter short positions
IF NOT ShortOnMarket AND HAopen1 Crosses Under HAclose1 THEN
Sellshort Equity SHARES AT MARKET
ENDIF
// Conditions to exit short positions
IF ShortOnMarket AND HAopen1 Crosses Over HAclose1 THEN
EXITSHORT AT MARKET
ENDIF
You know that you have to rem-out lines 37, 38 (//Graph…) before launching?
timeframe used should be maximum 5 minutes as you are using “FlatAfter = 154500″, if you want orders to close at this precise time!
change the T1 variable with:
T1 = 3
and it will work for sure.
Nicolas,
First, thank you. Second, I am probably displaying my ignorance below, but this is how we learn.
While that works, results are not the same as the indicator when using 3, 2 seems to be closer. I had surmised that T1 was a smoothing type and thus thought I could define the smoothing / averaging type, in this case WeightedAvergae? Using a number might also mean it is just using a number. How should I know which?
Flatafter / flatbefore did not influence the graphing, but point taken. I had understood form my reading that PRT will just sell at the defined time no matter what time frame for the strategy? Flat before will start at the defined time and wait for the next signal after defined start time.
Cheers, Stuart
Thank you all. I have made the changes and yes, it works. My questions now are:
- where is any documentation that define T, thus the averaging types ?
- Will PTR backtest the various types of averaging by adding as a variable T and 0-6?
Again, thank you all for your help. Il post backtest results once completed.
Stuart
https://www.prorealcode.com/documentation/average/
Yes you can run T as a variable, 0-6 in v10.3 or if you’re using v11 then it’s 0-8 as follows:
0 = SMA
1 = EMA
2 = WMA
3 = Wilder
4 = Triangular
5 = End point
6 = Time series
7 = Hull (PRT v11 only)
8 = ZeroLag (PRT v11 only)
Thanks Nonetheless. I did not realized PRT knows that it would be an average without having to define it first. I am on V 11 so I will add 7-8 to the back test. So far, it looks good in shorter time frames.
Cheers…
it knows insofar as the syntax is
average[p,t]
where p is the period and t is the type.
thanked this post
average[p,t] where p is the period and t is the type.
….and if no value for t is defined then it defaults to zero and returns a simple moving average.
Thanks for the explanation. Now I know.
Cheers.