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!