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

[amibroker] Re: Newbie - help to create an indicator



PureBytes Links

Trading Reference Links

I believe this will do what you want. Watch which log you use. Log
(14) in AFL gives 2.6391 not 1.1461. There is an AFL log10 and that 
is what you want to use. 

The other thing I see is that the calculations give a negative value. 
When the ATR14 is 18.65 the results of your formula gives -45.75. I 
can't see an error in the code but there may be one.

I was using TFH9 contract for testing. 

Barry

function fFindLargest()
{
	temp = H - L; 
	for(i = -13; i < 0; ++i)
	{
		diff = Ref(H, i) - Ref(L, i);
		temp = IIf(diff > temp, diff, temp);
	}
	return temp;
}

function fCvtStr(Val) { return NumToStr(Val, 1.4); }

		
fAtr = ATR(14); // calculate ATR
LargestBar = fFindLargest(); // find largest bar
range = fATR / LargestBar; // step 1, atr / largest bar
rangeLog = log(range);  // step 2, log of step 1
periodLog = log10(14.0); // step 3, log of ATR period 
logAll = rangeLog / periodLog ; // step 4 
logAll100 = logAll * 100; // step 5

// this prints the values in the interpretation window
printf("Atr=" + fCvtStr(fATR) + "\nLargestBar=" + fCvtStr(LargestBar) 
+ 
     "\nATR/Bar=" + fCvtStr(range) + 
     "\nrange Log=" + fCvtStr(rangeLog) + 
     "\nPeriod log=" + fCvtStr(periodLog ) );

// plot stuff
Plot(fATR, "ATR(14)", colorBlue, styleOwnScale);
Plot(logall100, "log all * 100", colorRed);
Plot(H-L, "Bar range", colorGreen, styleOwnScale); 
Plot(log(14), "log 14", colorBlack);


--- In amibroker@xxxxxxxxxxxxxxx, "srj3inc" <faltu0@xxx> wrote:
>
> I am new to Amibroker language, and not in touch with programming in
> general for some time now. I read about %C indicator in "Futures &
> Options Trader" magazine (issue Oct. 2008) Here is what is says:
> 
> =====================================
> The %C indicator uses true range
> to measure trend strength, as follows:
> 
> 1. Add each bar's true range in the 14-bar look-back period.
> 
> 2. Divide this running total by the largest one-day true range 
> value of that look-back period.
> 
> 3. Calculate the logarithm of the raw value from step 2.
> 
> 4. Divide the result by the logarithm of the look-back 
> period (14, in this case).
> 
> 5. Multiply by 100.
> 
> The following example uses 15-minute bars on the E-Mini Russell 2000
> futures. On Sept. 12 at noon, the running total of the E-Mini 
Russell
> 2000 futures' 14-bar true range was 47.3,and the largest one-bar
> true-range of the past 14 bars was 5. The %C reading would be:
> 
> 1. 47.3/5 = 9.46.
> 2. log(9.46) = 0.9758.
> 3. log(14) = 1.1461
> 4. 0.9758/1.1461 = .8514
> 5. 0.8514*100 = 85.14
> 
> Therefore, the %C indicator's value is 85.14. Logarithms are used
> calculation to make sure the extreme levels range from one to 99.
> ==============================================================
> 
> Can someone help to code this?
> 
> Thanks in advance,
> 
> - SRJ
>



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

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

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

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

For other support material please check also:
http://www.amibroker.com/support.html

*********************************
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/