I am writing a program that sums the open interest for three months, but no result is coming

//Create by Rajandran R
//Date : 31st July 2014

_SECTION_BEGIN("PCR OI");

//if( Status("actionScan") ==1 ) 
//{
VarSetText("Name()", "TEXT");
if( StrFind( Name(), "TEXT" ) )
{
   AddToComposite( OpenInt, "~niftyoice", "I" );
} 

if( StrFind( Name(), "PE" ) )
{
   AddToComposite( OpenInt, "~niftyoipe", "I" );
}

//} //endif

PCR = Foreign( "~niftyoipe", "I" ); 
Plot(PCR,"PCR",colorRed,styleLine);
Filter=1;
AddColumn(OI,"COI1");
AddColumn(PCR,"COI2");
// AddColumn(V31,"COI3");


_SECTION_END();

The code you have posted is syntactically wrong and also Logically wrong.

PCR or Put-Call-Ratio general variant is the Total Put Oi divided by Total Call OI
Where is this line of code?

If you have taken source from 3rd party, check what you have posted against the original.

These two lines don't add up

VarSetText("Name()", "TEXT");
if( StrFind( Name(), "TEXT" ) )

with this one
PCR = Foreign( "~niftyoipe", "I" );

Continuing the discussion from I am writing programme which sums the open interest for three months , but some issues, no result is coming:

in fact i was wrting based on that afl. i want to change the NAME()as text and then combine with I and second time II.

VarSetText("Name()", "TEXT");
if( StrFind( Name(), "TEXT" ) )
{
   AddToComposite( OpenInt, "~newname", "I" );
} 

//} //endif

PCR = Foreign( "~newname", "I" );
[quote="RaajeevKumar, post:1, topic:10054, full:true"]

//Create by Rajandran R
//Date : 31st July 2014

_SECTION_BEGIN("PCR OI");

//if( Status("actionScan") ==1 ) 
//{
VarSetText("Name()", "TEXT");
if( StrFind( Name(), "TEXT" ) )
{
   AddToComposite( OpenInt, "~niftyoice", "I" );
} 

if( StrFind( Name(), "PE" ) )
{
   AddToComposite( OpenInt, "~niftyoipe", "I" );
}

//} //endif

PCR = Foreign( "~niftyoipe", "I" ); 
Plot(PCR,"PCR",colorRed,styleLine);
Filter=1;
AddColumn(OI,"COI1");
AddColumn(PCR,"COI2");
// AddColumn(V31,"COI3");

List item

Plot(PCR,"PCR",colorRed,styleLine);
Filter=1;
AddColumn(OI,"COI1");
AddColumn(PCR,"COI2");

Why don't you start by posting the original code first, then take it from there.

You have mixed up a lot of things.

let m e explain my logic first i have the future of stock for three months like NIFTY-I,NIFTY-II,NIFTY-III. it has got DIFFERENT OPEN INTEREST . Now i am opening the chart of NIFTY-I, but if i plot the open interest, it plots for this month only. now basically I want to plot the sum of open interest of all three NIFTY-I,NIFTY-II,NIFTY-III.because all three are same stocks but different expiry. now i want to write an afl that when i open NIFTY-I, i convert the symbol into text and then concatenate with another I and agai with another II, and then use this name as NIFTY-II,NIFTY-III and use foreign to get open interest to sum up and then plot it. now i want to write like this.

_SECTION_BEGIN("Total OI");


VarSetText("Name()", "TEXT");

// HERE I WANT TO PICK NIFTY-I as a text to add another I and then again another IIto get the name of the next month future and far month future.
if( StrFind( Name(), "TEXT" ) )
{
   AddToComposite( OpenInt, "~newniftyname1", "I" );
   AddToComposite( OpenInt, "~newniftyname2", "II" );

} 

//i want now to sum the open interest
OI1=OI;
OI2=PCR = Foreign( "~newniftyname1", "I" ); 
OI3=PCR = Foreign( "~newniftyname2", "I" ); 
TotalOI=OI1+OI2+OI3;
Plot(TotalOI,"TotalOI",colorRed,styleLine);
Filter=1;
AddColumn(TotalOI,"TotalOI");


_SECTION_END();

RajeevKumar , This is what i would try

_SECTION_BEGIN("Total OI - 3 Symbols ");
//Source https://forum.amibroker.com/t/i-am-writing-a-program-that-sums-the-open-interest-for-three-months-but-no-result-is-coming/10054/5
// Open Interest of 3 months 
Symbol1OI_Vege =Foreign( "NIFTY-I", "I" );  // first symbol OI
Symbol2OI_Vege=  Foreign( "NIFTY-II", "I" );   // second symbol OI
Symbol3OI_Vege=  Foreign( "NIFTY-III", "I" );   /// Third Symbol OI 
CombinedOI_Vege =Symbol1OI_Vege +Symbol2OI_Vege+Symbol3OI_Vege;     //   3 symbols OI together 

Plot(Symbol1OI_Vege ," OI 1",colorYellow,styleLine);
Plot(CombinedOI_Vege ,"Total OI",colorRed,styleLine);

Filter=1;
AddColumn(Symbol1OI_Vege ,"Symb 1  OI");
AddColumn(CombinedOI_Vege ,"Total OI");
_SECTION_END();

2 Likes

Thanks amsai,
i want now to open the chart of any stock future say NIFTY-I. Then iwant to convert into NIFTY-IIand NIFTY-III. It may be any stock future of first month, then i take into afl convert into text and then concatenate with additional I in one and another additional II to convert into the next month future and far month future and then use your afl to find out the total OIof any stock future.

raajeev Kumar

Do you see the use of any of these?

VarSetText("Name()", "TEXT");     // <-- 1st bit of code
if( StrFind( Name(), "TEXT" ) )  // <-- 2nd line
{
   AddToComposite( OpenInt, "~niftyoice", "I" ); // <-- 3rd line
}

All 3 lines are there in your code and @amsai's code is completely different.
Just copying some random code and modifying it in your own way will just digress from your need,
and calling variable PCR among other things.

1 Like

Like @travick says , try to do your own way and post here .Someone may jump in to help you

I would try like this

Symbol1 =  Name () ; // Extracts Current symbol of the chart
Symbol2 =  Name () +"I" ; // Adds another"I" to your symbol to become next month symbol
Symbol3 =  Name () +"II" ;  // Adds  "II" to your symbol to become far month symbol
 

Now you have got all the 3 symbols . Using these symbol names , you extract open interest information to do the maths you want..
By the way i am not a coder . Just learned here with the help of others and there may be other efficient ways also

thanks amsai, but it is not giving any data. the code i had finished like that`
_SECTION_BEGIN("Total OI");

VarSetText("Name()", "TEXT");

// HERE I WANT TO PICK NIFTY-I as a text to add another I and then again another IIto get the name of the next month future and far month future./*

Symbol1 = Name () ; // Extracts Current symbol of the chart
Symbol2 = Name () +"I" ; // Adds another"I" to your symbol to become next month symbol
Symbol3 = Name () +"II" ; // Adds "II" to your symbol to become far month symbol
//i want now to sum the open interest
OI1=OI;
OI2=PCR = Foreign( "Symbol12", "I" );
OI3=PCR = Foreign( "Symbol13", "I" );
TotalOI=OI1+OI2+OI3;
Plot(TotalOI,"TotalOI",colorRed,styleLine);
Filter=1;
AddColumn(OI1,"OI");
AddColumn(TotalOI,"TotalOI");

_SECTION_END();`

1 Like

sorry the code whichi pu was like this, but it is not working:-


_SECTION_BEGIN("Total OI");


VarSetText("Name()", "TEXT");

// HERE I WANT TO PICK NIFTY-I as a text to add another I and then again another IIto get the name of the next month future and far month future./*

Symbol1 =  Name () ; // Extracts Current symbol of the chart
Symbol2 =  Name () +"I" ; // Adds another"I" to your symbol to become next month symbol
Symbol3 =  Name () +"II" ;  // Adds  "II" to your symbol to become far month symbol
//i want now to sum the open interest
OI1=OI;
OI2 = Foreign( Symbol2, "I" ); 
OI3 = Foreign( Symbol3, "II" ); 
TotalOI=OI1+OI2+OI3;
Plot(TotalOI,"TotalOI",colorRed,styleLine);
Filter=1;
AddColumn(OI1,"OI");
AddColumn(TotalOI,"TotalOI");


_SECTION_END();

sorry travick,
i am armature in amibroker, so you will pardon for small tings. i was trying to get the name() as text and then modifying it for my requirement to put it again as sumbol to get the total oi, but somehow it is not working.

No need to apologize, please.
Just do a little bit of homework and there will new many ready to help.

Code is working for me

image

//Check these 2 lines in your code and what they are trying to call  
OI2 = Foreign( Symbol2, "I" ); 
OI3 = Foreign( Symbol3, "II" );
1 Like

yes , that is the mistake, i have put now OI, both the places, but still i am not getting any value, it is null. can you post your afl here.

Did you read the docs
http://www.amibroker.com/f?foreign

If you did you would know that there is no such field as "II"

OI3 = Foreign( Symbol3, "II" ); // THIS IS INCORRECT, "II" is wrong

Again, did you read the docs http://www.amibroker.com/f?foreign ?

You are still using Foreign incorrectly. In the second sentence of foreign docs you can clearly read:

Allowable data fields: "O" (open), "H" (high), "L" (low), "C" (close), "V" (volume), "I" (open Interest), and for v5.29 and above: "1" (aux1), "2" (aux2)

The other thing is that you are not following forum rules and post codes without code tags How to use this site

i am putting the code in the code place only. any way i will go through the rules again. i did put I instead of OI but I am getting the result empty

@RaajeevKumar, Did you not see the below!

I will defenately take care in future. Thanks.