Need AFL for New High New Low Index , TRIN , NYSE TICK?

Hello,

I am new to amibroker & AFL.

I want to test some indicators like NYSE TICK , TRIN , New High New Low Index to the markets of India (where I live) as these are not available here.

I found a way by coding it through AFL but I dont know any coding.

Can anyone please provide AFLs for above three Indicators ASAP because my trial period is exhausting?

Thanks

@thonkey the calculations for those indicators are well known. If you plan on using AmiBroker you should at least start making attempts at coding. Once you have made some attempts to code this stuff, if you have any problems then post your code here on the forum and you will likely get members trying to help you.

There are many resources for learning, start reading and practicing what you find here for example

As for the TRIN, NYSE TICK, and New High New Low most of that data is automatically available (included) with data feeds. But if you need some formula's look at some of these web sites,
http://stockcharts.com/school/doku.php?id=chart_school:market_indicators:arms_index

http://stockcharts.com/school/doku.php?id=chart_school:index_symbols:52_week_high_low

And carefully review this AmiBroker knowledge base article and try to make it work on your data.
http://www.amibroker.com/kb/2007/07/30/how-to-display-the-indicators-based-on-advancesdeclines/

The NYSE TICK by the way requires a data feed that provides you with tick by tick data.

Good luck, I look forward to reviewing your codes.

Oh and I don't understand this,

Just buy or upgrade your AmiBroker like everyone else on this forum has.

4 Likes

I haven't purchased amibroker yet.
I want to check if those indicators can be built by amibroker which would be in line with NSE (stock exchange of India).
I want to build TICK index, TRIN & New High New Low for NSE (not for NYSE) , as they are not available in India.

@thonkey yes they can be calculated in AmiBroker. They are not complex at all.

For a quick example to get you started on your code writing

NewHigh = High > Ref(HHV(High, 250), -1); //  put a Param for the 250 and calculate any interval New High you like
NewLow = Low < Ref(LLV(Low, 250), -1);
NHNL_Diff = NewHigh - NewLow ;

As for getting you started on the TRIN, you've alreay seen a previous thread on this forum to get you started on Advances and Declines. Do the same for advancing volume and declining volume.

AmiBroker is awesome, purchase it and start having some fun!

3 Likes

@thonkey glad that you have purchased AmiBroker and instead of posting a PM answer I thought I would post here on the forum so other users could either benefit or correct my mistakes.

For the TRIN you can use AmiBroker to calculate it,
https://www.amibroker.com/guide/t_trin.html

https://www.amibroker.com/guide/afl/trin.html

Or using the index of your choice and the symbols that are appropriate to your data feed something like this,

// data-source dependent symbols 

SP500advn = Foreign( "#SPXADV", "C" );
SP500decl = Foreign( "#SPXDEC", "C" );

SP500upvol = Foreign( "#SPXADV", "V" );
SP500dnvol = Foreign( "#SPXDEC", "V" );

SP500ArmsIndex = ( SP500advn / SP500decl ) / ( SP500upvol / SP500dnvol ); // TRIN using my SP500 data symbols

Plot( SP500ArmsIndex, "SP500ArmsIndex", colorRed, styleLine|styleThick );

////////////////////////////////////////////////////////////////
// for a different Index, I would use different data
// and thus need different symbols
///////////////////////////////////////////////////////////////

Russell3000advn = Foreign( "#RUAADV", "C" );
Russell3000decl = Foreign( "#RUADEC", "C" );

Russell3000upvol = Foreign( "#RUAADV", "V" );
Russell3000dnvol = Foreign( "#RUADEC", "V" );

Russell300ArmsIndex = (Russell3000advn/Russell3000decl)/(Russell3000upvol/Russell3000dnvol); // TRIN using my Russell 3000 data 

Plot( Russell300ArmsIndex, "R3K TRIN", colorAqua, styleDashed );

I always thought the TRIN was a flawed indicator in the fact that it is asymmetric the way it is calculating overbought and oversold. Various methods of improving it have been made over the years but since this is an AmiBroker forum you can review one method here,

http://www.amibroker.com/members/traders/12-2005.html

1 Like

Thanks .

Can there be any substitute AFL code for AdvVolume Function , which can give output of total volume of Advancing issues of all securities listed in the exchange?

@thonkey, with AFL all things are possible.... Well most programming things anyway...

You can search on the forum for ideas, but essentially, if you can do it manually (or come up with the process to do it manually) it can be coded in AFL. Notice I did not say that you could do it. With you being so new to AmiBroker and AFL, you will probably have difficulty, but, if you try and post your code, there are many helpful members on the site that will help guide you.

So, your homework is learning about Explorations and how they can help you see what your code is doing. This is the General homework that will pay dividends in almost all of your AFL development moving forward.

Second, become familiar with the User's Guide or Manual. Look at the Functions that are available, and see what might be interesting and useful for you.

1 Like

@thonkey you need to do some homework or hire a programmer to do your work.

If you want to calculate the advancing volume in your data you can of course loop through the symbols in your data and do the calculations.

Think about it, it is not difficult to define what is and "advancing stock", what is a "declining stock"? Maybe something like this,

AdvIss = C > Ref( C, -1 );
DecIss = C < Ref( C, -1 );
UnchangedIss = C == Ref( C, -1 );

How do you figure out the "advancing volume" and the "declining volume" ? Maybe something like this,

UpVolume += IIf( advIss, V, 0 ); // sum up V for advancing issues
DownVolume += IIf( DecIss, V, 0 ); // sum up V for declining issue

Now good luck with your homework, it takes a lot of time and effort to learn how to code and to learn how to trade. You can't be spoon fed to success.

2 Likes

Manually finding Total Volume of all Advancing Stocks is possible through MS Excel. But AdvVolume is a composite function & will not give output for all the stocks listed in the exchange.

I have tried Sum Function & it is not working.

I don't know what to do now?

@thonkey, that is why I gave you the homework.

READ the list of Functions available in AFL. Then READ the ones that sound like they may help you. AddtoComposite would be ONE of MANY ways to move forward. Using a Global Variable and running through all the stocks and adding in the Advancing Volume is another way.

But PLEASE, seriously, READ the AFL Function Reference - Alphabetical and then again the Categorized. Trust me, it will help! Just seeing the names of the functions will help.

If you don't want to go through the AddtoComposite way, then look at variables. SEARCH this forum for Global Variables and there will be lots of information. Learn the Exploration and again it will help.

One word of warning, using Volume, the numbers could easily exceed the precision allowed in the computer format (IEEE) for representing numbers. (Again, search on the forum for more info... ) Prepare to scale down the Volume values.

1 Like

ok thanks. :slight_smile:
Let me Check

wlnum = GetOption( "FilterIncludeMarket" );
List = CategoryGetSymbols( categoryMarket, wlnum );


if( Status( "stocknum" ) == 0 )
{
    // cleanup variables created in previous runs (if any)
    StaticVarRemove( "~Advances1*" );
    StaticVarRemove( "~Declines1*" );
    StaticVarRemove( "~TotalCount1*" );

    for( n = 0; ( Symbol = StrExtract( List, n ) )  != "";  n++ )
    {

        SetForeign( symbol );

        AdvIss1 = Close > Open;
        DecIss1 = Open > Close;

        StaticVarAdd( "~Advances1", AdvIss1 );
        StaticVarAdd( "~Declines1", DecIss1 );
        StaticVarAdd( "~TotalCount1", 1 ); // I have not yet included Unchanged Issues

        RestorePriceArrays();

    }

}

svAdvances1 = StaticVarGet( "~Advances1" );
svDeclines1 = StaticVarGet( "~Declines1" );
AdvDecToday1 = ( svAdvances1 / svDeclines1 );


TotalSymbols = StaticVarGet( "~TotalCount" );

UpVolume = IIf( Close > Open, V, 0 )  ; // sum up V for advancing issues
DownVolume = IIf( Open > Close, V, 0 ); // sum up V for declining issue

//VolumeRatio = Upvolume / DownVolume ;(I am trying to get this in order to make TRIN for my exchange)
// TRIN = AdvDecToday1 / VolumeRatio ;

///////////////
// Explore
///////////////
Filter = Status( "stocknum" ) == 0;
SetOption( "NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );

AddColumn( svAdvances1 , "Advances", 1.0 );
AddColumn( svDeclines1, "Declines", 1.0 );
AddColumn( AdvDecToday1, "AdvDecToday", 1.0 );
AddColumn( TotalSymbols, "Total Symbols", 1.0, colorDefault, colorLightYellow );

AddColumn( UpVolume , "Total Adv Vol", 1.0 );
AddColumn( DownVolume, "Total Decline Vol", 1.0 );


///////////////
// Chart
///////////////
Plot( AdvDecToday1, "AdvanceDeclineRatio1", colorWhite, styleLine,0,0,0,0,1 );
//Plot( TRIN, "Indian TRIN", colorWhite, styleLine,0,0,0,0,1 );

getting wrong total advance & decline volumes.

wlnum = GetOption( "FilterIncludeMarket" );
List = CategoryGetSymbols( categoryMarket, wlnum );


if( Status( "stocknum" ) == 0 )
{
    // cleanup variables created in previous runs (if any)
    StaticVarRemove( "~Advances1*" );
    StaticVarRemove( "~Declines1*" );
    StaticVarRemove( "~TotalCount1*" );

    for( n = 0; ( Symbol = StrExtract( List, n ) )  != "";  n++ )
    {

        SetForeign( symbol );

        AdvIss1 = Close > Open;
        DecIss1 = Open > Close;

        StaticVarAdd( "~Advances1", AdvIss1 );
        StaticVarAdd( "~Declines1", DecIss1 );
        StaticVarAdd( "~TotalCount1", 1 ); // I have not yet included Unchanged Issues

        RestorePriceArrays();

    }

}

svAdvances1 = StaticVarGet( "~Advances1" );
svDeclines1 = StaticVarGet( "~Declines1" );
AdvDecToday1 = ( svAdvances1 / svDeclines1 );


TotalSymbols = StaticVarGet( "~TotalCount" );
UpVolume = 1;
DownVolume = 1.1;

UpVolume += IIf( Close > Open, V, 0 )  ; // sum up V for advancing issues
DownVolume += IIf( Open > Close, V, 0 ); // sum up V for declining issue

//VolumeRatio = Upvolume / DownVolume ;(I am trying to get this in order to make TRIN for my exchange)
// TRIN = AdvDecToday1 / VolumeRatio ;

///////////////
// Explore
///////////////
Filter = Status( "stocknum" ) == 0;
SetOption( "NoDefaultColumns", True );
AddColumn( DateTime(), "Date", formatDateTime );

AddColumn( svAdvances1 , "Advances", 1.0 );
AddColumn( svDeclines1, "Declines", 1.0 );
AddColumn( AdvDecToday1, "AdvDecToday", 1.0 );
AddColumn( TotalSymbols, "Total Symbols", 1.0, colorDefault, colorLightYellow );

AddColumn( UpVolume , "Total Adv Vol", 1.0 );
AddColumn( DownVolume, "Total Decline Vol", 1.0 );


///////////////
// Chart
///////////////
Plot( AdvDecToday1, "AdvanceDeclineRatio1", colorWhite, styleLine,0,0,0,0,1 );
//Plot( TRIN, "Indian TRIN", colorWhite, styleLine,0,0,0,0,1 );

sorry, forgot to assign values @snoopy.pa30

@thonkey, I don't have time to go through the code in detail now, but my quick run using a watchlist with 2 items showed me that only ONE issue has volume hitting the analysis.

Looking at the code, you have the volume calculation OUTSIDE your foreign loop.

So my guess is if you fix that up you will get some results.

My suggestion is to try it with a watchlist of 2 items and test out your logic using your exploration. When it works with 2 items, you can scale up your testing.

1 Like