I have an algo that performs well in certain markets – let say for example bear markets.
Is there a function or code with PRT that will help me assess which trend we are currently in? clearly I assume this is a wide open question (how long is the trend etc). But in general, id like to say
If bear market then execute code
elseif
wait 🙂
any ideas?
thanks!
The most classic way is to compare the price against Sma200, but you may prefer different periods.
Another way is to compare the current price agains that of N periods ago.
The best way is trying to spot some Higher Highs and Higher Lows or some Lower Lows and Lower Highs.
Furthers methods can be coded.
Thanks Robert, much appreciated.
its the higher, high – lower, lows code that im really interested in. Was hoping that you or someone else had already done the legwork on this? Something perhaps that could be optimised to to try and find a “sweet spot”, while trying to avoid overfitting of course!
thanks!
The ROCnRoll Indicator gives an easily spotted change of direction at any / all Timeframes.
I have this code to spot the last 3 HH’s and 3 LL’s, but the main issues with this code are:
- validity of the definituion of HH and LL, I used to scan by a new HH o LL within the last N candles and consider it valid only if there is a reversal pattern (two differently coloured candles)
- lag, after three HH’s and LL’s the trend might be close to reversal
I would try another solution, ROCnRoll Indicator as suggested by GraHal or Sma200 or a combination of other indicators.
The choice of the TF may also affect the decision.
DEFPARAM DrawOnLastBarOnly = TRUE
//DEFPARAM CalculateOnLastBars = 1000
//
//ONCE LB = 5 //5 LookBack periods
LB = max(1,min(999,LB))
//
ONCE HH1 = 0 //previous Higher High
ONCE HHbar1 = 0
ONCE HH2 = 0 //previous Higher High
ONCE HHbar2 = 0
ONCE HH3 = 0 //current Higher High
ONCE HHbar3 = 0
//
ONCE LL1 = 0 //previous Lower Low
ONCE LLbar1 = 0
ONCE LL2 = 0 //previous Lower Low
ONCE LLbar2 = 0
ONCE LL3 = 0 //current Lower Low
ONCE LLbar3 = 0
//
ONCE MyTrend = 0
Bullish = close > open
Bearish = close < open
//
IF summation[2](high = highest[LB](high)) AND Bullish[1] AND Bearish THEN
HH1 = HH2
HHbar1 = HHbar2
HH2 = HH3
HHbar2 = HHbar3
HH3 = max(high,high[1])
HHbar3 = BarIndex
ELSIF summation[2](low = lowest[LB](low)) AND Bearish[1] AND Bullish THEN
LL1 = LL2
LLbar1 = LLbar2
LL2 = LL3
LLbar2 = LLbar3
LL3 = min(low,low[1])
LLbar3 = BarIndex
ENDIF
//
//MyTrend = 0
IF ((HH1 < HH2) AND (HH2 < HH3)) AND ((LL1 < LL2) AND (LL2 < LL3)) THEN
MyTrend = 1
ELSIF ((HH1 < HH2) AND (HH2 < HH3)) AND ((LL1 > LL2) OR (LL2 > LL3) OR (LL1 > LL3)) THEN
MyTrend = 0
ELSIF ((LL1 > LL2) AND (LL2 > LL3)) AND ((HH1 > HH2) AND (HH2 > HH3)) THEN
MyTrend = -1
ELSIF ((LL1 > LL2) AND (LL2 > LL3)) AND ((HH1 < HH2) OR (HH2 < HH3) OR (HH1 < HH3)) THEN
MyTrend = 0
ENDIF
//
DrawText("HH1",HHbar1,HH1 * 1.001)
DrawText("HH2",HHbar2,HH2 * 1.001)
DrawText("HH3",HHbar3,HH3 * 1.001)
//
DrawText("LL1",LLbar1,LL1 * 0.999)
DrawText("LL2",LLbar2,LL2 * 0.999)
DrawText("LL3",LLbar3,LL3 * 0.999)
//
RETURN MyTrend AS "Trend",0 AS "0"
Thank you both for the ideas – much appreciated – that is my weekend sorted now 🙂
Link to Roberto HH & LL code added as Log 289 here …
Snippet Link Library
Roberto, re. your code, pls correct me if I’m wrong but it seems to me that what you call lower lows “LLn” maybe should be called Higher Lows (HLn) , since each of them are higher than the previous one , arent they ?
I don’t want to tell Lower Lows from Higher Lows (and the other way round), as when I detect 3 LL’s or 3 HH’s I check if they are in the correct order, otherwise I’ll ignore them