I think the problem may be with the first line
What happens if you change it to
Period = Param("Period" ,30,1,300, 1);
________________________________
From: droskill <[email protected]>
To: [email protected]
Sent: Sunday, September 6, 2009 11:53:13 AM
Subject: [amibroker] Re: Request afl code for choppy market index (pleaselook
here for tradestation
I looked at the Tradestation code and translated as follows - but it does not
return a value between 0 and 100 - not sure why it should based on the
calculation - but I may have it wrong:
Period = Param("Period" ,1,30,300, 1);
denom = HHV(High,Period) - LLV(Low,Period) ;
num = abs(Ref(Close, Period - 1) - Close);
Choppy = IIf(num != 0, (num/denom)* 100, 0);
Plot(Choppy, "ChoppyMarketsIn dex",colorBlue, styleLine) ;
--- In amibro...@yahoogrou ps.com, "rvlv" <r...@...> wrote:
>
> Hi afl experts,
>
>
> We often hear that a trader needs to avoid choppy markets.
> I find no formula in amibroker to deal with it as far as I know.
> If there is any,please let me know-thanks for the help.
>
> If any experienced afl coder can help, I request them please convert
> the following tradestation code into amibroker formula and blige!
> It will be great help.
>
> In metatrader there is a formula to this purpose called
> TRO_MM_CMI
> ------------ ----
> METRADER CODE
> }// if
> } // for
>
>
> for(int x=0;x<tfnumber; x++)
> {
>
> int hh = Highest(symbol, tframe[x] ,MODE_HIGH, periodLength+ 1,0);
> int ll = Lowest(symbol, tframe[x] ,MODE_LOW, periodLength+ 1,0);
>
> HH = iHigh(symbol, tframe[x] ,hh) ;
> LL = iLow(symbol, tframe[x] ,ll) ;
>
>
>
>
> close = iClose(symbol, tframe[x] ,0) ;
> pclose = iClose(symbol, tframe[x] ,periodLength- 1) ;
>
> denom = (HH - LL) / point ;
> num = (pclose - close) / point ;
> num = MathAbs(num) ;
> ChoppyMarketIndex = 0.0 ;
>
>
>
> if(denom > 0 )
> {
> ChoppyMarketIndex = 100 * (num / denom) ; // 100 * (num / denom)
> }
>
>
>
> CMI[x] = ChoppyMarketIndex;
>
>
> if (ChoppyMarketIndex > Trendy )
> {
> theArrowLONG[ x] = ArrowHeadUp ;
> theColorLONG[ x] = UpColor ;
> }
> else if (ChoppyMarketIndex < Choppy )
> {
> theArrowLONG[ x] = ArrowHeadDn ;
> theColorLONG[ x] = DownColor ;
> }
> else
> {
> theArrowLONG[ x] = ArrowHeadRt ;
> theColorLONG[ x] = FlatColor ;
> }
> ------------ --------- --------- --------- --------- ---------
>
> Tradestation code is here
> ------------ --------- --------- --------- --------- ---
> {Choppy Market Index Function
> This function returns a value from 0 to 100.
> A lower value denotes higher market indecisiveness (choppiness) ,
> whereas a higher value denotes a trending market.
> The only input is the number of bars that we look back.}
>
> Inputs: periodLength( Numeric);
> Vars: num(0),denom( 1);
> if(periodLength< >0) then
> begin
> denom = Highest(High, periodLength) – Lowest(Low,periodLe ngth);
> num = Close[periodLength- 1] – Close;
> num = AbsValue(num) ;
> ChoppyMarketIndex = 0.0;
> if(denom<>0) then ChoppyMarketIndex = num/demon*100;
> end;
>
> ------------ --------- --------- --------- --------- -----
> Did you notice how this function was made up of other functions (building
> blocks)? We calculated the denom (denominator) by using the Highest and
> Lowest functions. We calculated the num (numerator) by using AbsValue
> (returns the absolute value of a number) functions. The only confusing
> snippet of code in this function is probably:
>
>
> Code:
> Close[periodLength- 1] – Close
> You may be asking why we subtracted 1 from the periodLength.
> This is a great question. If you incorporate today's closing price into a
> calculation, then the closing price 30 days ago would be referenced by
> Close[29]. Remember that Close[1] is yesterday's closing price not today's.
> Since we want our index to flow between 0 and positive 100, we remove the
> negative sign of a down move in the market. We are only interested in
> absolute distances.
>
> Here is what I came up with, but not sure it is coded correctly:
>
> ------------ --------- --------- --------- --------
> Code:
> double ChoppyMarketIndex( int periodLength)
> {
> double num = 0;
> double denom = 0;
> if(periodLength != 0)
> {
> denom = High[iHighest( Symbol(), PERIOD_D1, MODE_HIGH, periodLength,
> 0)] - Low[iLowest( Symbol(), PERIOD_D1, MODE_LOW, periodLength, 0)];
> num = Close[periodLength- 1] - Close[1];
> num = MathAbs(num) ;
> }
> if(denom != 0)
> {
> return(NormalizeDou ble(num/denom* 100,0));
> }
> }
>
> ------------ --------- --------- --------- ------
>
> in anticipation of a quick help,
> thanks for your time and helping spirit,
> regards
> rvlv
>