[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Request afl code for choppy market index (pleaselook here for tradestation code


  • To: amibroker@xxxxxxxxxxxxxxx
  • Subject: [amibroker] Request afl code for choppy market index (pleaselook here for tradestation code
  • From: "rvlv" <rvlv@xxxxxxxxx>
  • Date: Sun, 06 Sep 2009 04:18:07 -0000

PureBytes Links

Trading Reference Links

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,periodLength);
       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(NormalizeDouble(num/denom*100,0));
         }
   }

---------------------------------------------

in anticipation of a quick help,
thanks for your time and helping spirit,
regards
rvlv



------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/