DominantPeriod,DominantPhase and HTTrendMode doubts...

Posted By: Mithrandir77

DominantPeriod,DominantPhase and HTTrendMode doubts... - 02/04/14 18:34

After reading some of John Ehler's books I started to do some tests to know if I had grasped some of his concepts.

But first I have some questions about some functions that I don't understand what the documentation means:

1)In DominantPeriod and DominantPhase where it says "Period gives the bar period of maximum sensibility" what does it mean by sensibility? Is it the most "likely" period a priori? Or is it some initial condition for the function?

2) In HTTrendMode, what should we use as data? I have used both the entire price series as well as the price series cut off by the dominant period/2 or should we use the LookBack as cutoff?

Concerning the concepts I tested, in a nutshell, one of them is that the market mode can be simplified as being in trend mode or in cycle mode. Then in market mode you go short on a peak of the cycle phase and long on a valley. I would like to identify whether the market is in trend mode or cycle mode so I made this script:

Code:
function run()
{	
  BarPeriod = 240;//240
  var LookBackPeriod = (1440/BarPeriod)*20;//20 days  
  LookBack = LookBackPeriod;
  StartDate = 2012;
  asset("EUR/USD");
  
  set(PLOTNOW);
  vars Price = series(price());
  plot("Price",Price[0],MAIN,BLACK);
  var sinDomPhase = sin(DominantPhase(Price,30));
  plot("Phase",sinDomPhase,NEW,BLACK);
  plot("Phase Lead",sin(DominantPhase(Price,30)+PI/4),0,RED);
  
  var domperiod = DominantPeriod(Price,30);
  plot("Dominant Period",domperiod,NEW,BLUE); 
  var market_mode = HTTrendMode(series(sinDomPhase,domperiod/2));
  if (market_mode)
    //plot 1 in blue for trend mode
    plot("MarketMode",1,NEW,BLUE);    
  else
    //plot 0 in red for cycle mode
    plot("MarketMode",0,LINE,BLUE);    
}



When I test it, I get a BADFREE2: SYS messagebox and I hit RETRY and it plots the graph, what does that error mean?

Anyway, it always plots the market as being in cycle mode when for instance from may to june 2012 there was a downtrend. What's wrong with the code? Thanks for any help!

Posted By: dusktrader

Re: DominantPeriod,DominantPhase and HTTrendMode doubts... - 02/04/14 21:50

I can't help you with the code part... but in my experience "BADFREE" usually means there is something wrong with LookBack (like not enough).

You can try commenting-out the LookBack and sometimes Zorro will assign it what it thinks it needs (that doesn't always work but worth a try).

Also LookBack should be an int, not var, I believe.
Posted By: jcl

Re: DominantPeriod,DominantPhase and HTTrendMode doubts... - 02/05/14 08:48

That is not the problem here, but a series must have a fixed number of elements. It can not change its number of elements from call to call, as you do with the series to HTTrendMode.

"Sensibility" means the bar period on which the DominantPhase function is most sensible. F.I when you only want to consider bar periods greater than 30 bars, give 40 or 50 here to make DominantPhase insensible for smaller bar periods.

I don't know in detail what HTTrendmode does, as we did not program this function. But I suppose you normally want to know the trend of the price, so you give a price series here.
Posted By: Mithrandir77

Re: DominantPeriod,DominantPhase and HTTrendMode doubts... - 02/05/14 22:46

Thanks dusktrader and jcl for your help! The problem with HTTrendMode is that it returns an int and I was assigning a var to the result thus when asking 1.0 == 1 it always returned false. My bad...I'm halway in my studies of computer engineering but it seems forex concepts are filling my head and I forgot the basics of programming wink This works:

Code:
int market_mode = HTTrendMode(series(price());



Originally Posted By: jcl

"Sensibility" means the bar period on which the DominantPhase function is most sensible. F.I when you only want to consider bar periods greater than 30 bars, give 40 or 50 here to make DominantPhase insensible for smaller bar periods.


jcl, your answer bring two more questions then:

1) So that period parameter is like a center of a
right-skewed bell shape of dominant periods? ie: If I set it to 40 it will find more likely dominant periods of 30-60 bars and more unlikely of less than 30?
Or is it like a minimum point from which it starts iterations (in ascending steps) to find the dominant period?

2) Anyway, if I want to find the dominant period as in Ehlers books, that is the dominant period of all periods how can I do it? According to what you said I should set Period to 1 to scan all periods greater than one bar. Is this correct?
Posted By: jcl

Re: DominantPeriod,DominantPhase and HTTrendMode doubts... - 02/06/14 15:44

You can see a similar shape in the "Highpass" filter curve in the "Filters" chapter. It's more a radish than a bell. Period 1 would probably pass too much noise and make the detection worthless - but you can experiment with different settings and see for yourself. Our systems normally use 20 or 30 for the period.
Posted By: Mithrandir77

Re: DominantPeriod,DominantPhase and HTTrendMode doubts... - 02/06/14 21:08

Originally Posted By: jcl
You can see a similar shape in the "Highpass" filter curve in the "Filters" chapter. It's more a radish than a bell. Period 1 would probably pass too much noise and make the detection worthless - but you can experiment with different settings and see for yourself. Our systems normally use 20 or 30 for the period.


Would it be ok to use optimize to find the best period or would it cause curve-fitting?
Posted By: Meini

Re: DominantPeriod,DominantPhase and HTTrendMode doubts... - 09/04/18 09:51

Quote:
"Sensibility" means the bar period on which the DominantPhase function is most sensible. F.I when you only want to consider bar periods greater than 30 bars, give 40 or 50 here to make DominantPhase insensible for smaller bar periods.

I know this is an old thread, but it's also still like that in the help file..
... do you mean sensitive as in responsive, or sensible as in realistic? I bet it's the first one....
© 2024 lite-C Forums