Re: [amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Hi, I like really like this one. Something for the FED -) 12/01/2007,12/31/2010 Regards, Ton. - Original Message - From: notanaiqgenius To: amibroker@yahoogroups.com Sent: Wednesday, July 07, 2010 12:05 AM Subject: [amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS Hi BisTrader, No need to study it (unless you want to). It should work if you just do the following: 1) copy my code to new afl document. 2) create this directory: c:\abTestData\ 3) with Notepad copy and paste the following dates into a file and save it as a .csv file in that abTestData directory. Name the file recessions.csv 4) apply to afl document to chart and Enjoy. 09/01/1902,08/31/1904 05/01/1907,06/30/1908 01/01/1910,01/31/1912 01/01/1913,12/31/1914 08/01/1918,03/31/1919 01/01/1920,07/31/1921 05/01/1923,07/31/1924 10/01/1926,11/30/1927 08/01/1929,03/31/1933 05/01/1937,06/30/1938 02/01/1945,10/31/1945 11/01/1948,10/31/1949 07/01/1953,05/31/1954 08/01/1957,04/30/1958 04/01/1960,02/28/1961 12/01/1969,11/30/1970 11/01/1973,03/31/1975 01/01/1980,07/31/1980 07/01/1981,11/30/1982 07/01/1990,03/31/1991 03/01/2001,11/30/2001 12/01/2007,12/31/2010 --- In amibroker@yahoogroups.com, bistrader bistra...@... wrote: Wow. Need to study. More work than expected. Most is ready the csv file and converting to 1s and 0s it appears. Thanks for sharing. --- In amibroker@yahoogroups.com, notanaiqgenius notanaiqgenius@ wrote: Sebastian and bistrader, That is a very clean, fast, and simple solution, Sebastian. I actually prefer your method most of the time. However, I kind of got carried away and wrote it the hard way reading a csv file directly with the string functions. This code could be used to plot user-defined periods of any sort whose start and end dates are stored in two columns in a csv file. Please read the comments at the top of my code so you know how the begin and end recession dates should be formatted in the csv file. I wrote the dates for the recessions from then nber.org website from 1900 to now, and just guessed that the current recession would end at the end of this year. You can find them in a comment below the main code. I fully debugged this and it works. It basically parses the dates out of a csv file and then loops through to make a isRecession boolean array, which is then plotted on the chart in gray area, as bistrader originally requested. I hope you like this solution! -Paul CODE: /*Coded By: Paul D. ( notanaiqgenius@ ) Last Modified: 07/05/2010 using Amibroker 5.3 for Yahoo amibroker group message #150705 for bistrader NOTE #1: CSV file must be in following format: MM/DD/,MM/DD/ MM/DD/,MM/DD/ MM/DD/,MM/DD/ where the first column is the START Of the recession OR period AND the Second column is the END Of the recession OR period NOTE #2: be sure to feed the full folder AND file path with \\ slashs for folder/file separators; it should look like this path string: C:\\abTestData\\recessions.csv You will need to make a folder called abTestData and put the recessions.csv file in there if you want my code to work as-is NOTE #3: the Plot should be inserted as an OVERLAY. NOTE #4: dates before 1900 won't work i don't think because i used Easy Language style dates which are in the format of YYYMMDD like 1101231. 01/01/1900 would be 101, so can't go before 01/01/1900. Sorry didn't think about this beforehand. */ function GetRecessionDates(returnBeginOrEnd, fullPathAndFileName) { //if you want the BEGIN dates array to be returned, set returnBeginOrEnd to 0 //if you want the END dates array to be returned, set returnBeginOrEnd to 1 local recDateStr; local fh; recDateStr = ; fh = fopen(fullPathAndFileName,r); if (fh) { while(!feof(fh)) //get all text/string from csv file { recDateStr += fgets(fh); recDateStr += ,; } fclose(fh); //_TRACE(the string: + recDateStr); //parse string and put it into an numeric array that this function will return rDatesBEGINarr = 0; rDatesENDarr = 0; DateCntr = 0; rDatesBEGINcntr = 0; rDatesENDcntr = 0; slashCounter = 0; MonthNum = 0; DayNum = 0; YearNum = 0; tempDateNum = 0; i = 0; fp = 0; //fp = first position while(iStrLen(recDateStr)) { if(StrMid(recDateStr,i,1)==/) { switch(slashCounter) { case 0: MonthNum = StrToNum(StrMid(recDateStr,fp,i-fp));break; //save month case 1: DayNum = StrToNum(StrMid(recDateStr,fp,i-fp));break; //save day } slashCounter++; fp = i + 1; } //save year + entire datenum if(StrMid(recDateStr,i,1)==, StrMid(recDateStr,i-1,1
[amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Thanks again to both of you. I did study both. Must admit that I will have to study one that reads csv file a few more times to understand. I did apply and it works just fine. As a learning experience, I created the following. It does not read from a csv file which is what I wanted, but I totally understand it. Thanks again. // // Function for converting dates to numbers // function Date_To_Num(mmdd) { mm_= StrToNum(StrLeft (mmdd,2 )); dd_= StrToNum(StrMid (mmdd,3,2)); yy_= StrToNum(StrRight(mmdd,4 )); Date_Num = (1 * (yy_ - 1900)) + (100 * mm_) + dd_; RESULT = Date_Num; return RESULT; } // // Define Start Date (SD) and End Date (ED) for each Recession // // Used middle of month for start and end date // http://en.wikipedia.org/wiki/List_of_recessions_in_the_United_States SD1 = 09/15/1902; ED1 = 08/15/1904; // 1902 - 1904 Recession SD2 = 05/15/1907; ED2 = 06/15/1908; // Panic of 1907 SD3 = 01/15/1910; ED3 = 01/15/1912; // Panic of 1910 - 1911 SD4 = 01/15/1913; ED4 = 12/15/1914; // Recession of 1913 - 1914 SD5 = 08/15/1918; ED5 = 03/15/1919; // Post World War I Recession SD6 = 01/15/1920; ED6 = 07/15/1921; // Depression of 1920 - 1921 SD7 = 05/15/1923; ED7 = 07/15/1924; // 1923 - 1924 Recession SD8 = 10/15/1926; ED8 = 11/15/1927; // 1926 - 1927 Recession SD9 = 08/15/1929; ED9 = 03/15/1933; // Great Depression SD10 = 05/15/1937; ED10 = 06/15/1938; // Recession of 1937 SD11 = 02/15/1945; ED11 = 10/15/1945; // Recession of 1945 SD12 = 11/15/1948; ED12 = 10/15/1949; // Recession of 1949 SD13 = 07/15/1953; ED13 = 05/15/1954; // Recession of 1953 SD14 = 08/15/1957; ED14 = 04/15/1958; // Recession of 1958 SD15 = 04/15/1960; ED15 = 02/28/1961; // Recession of 1960 - 1961 SD16 = 12/15/1969; ED16 = 11/15/1970; // Recession of 1969 - 1970 SD17 = 11/15/1973; ED17 = 03/15/1975; // 1973 - 1975 Recession SD18 = 01/15/1980; ED18 = 07/15/1980; // 1980 Recession SD19 = 07/15/1981; ED19 = 11/15/1982; // Early 1980s Recession SD20 = 07/15/1990; ED20 = 03/15/1991; // Early 1900s Recession SD21 = 03/15/2001; ED21 = 11/15/2001; // Early 2000 Recession SD22 = 12/15/2007; ED22 = 07/15/2009; // Great Recession // // Set isRecession to 1 for each recession date // isRecession = (DateNum() = Date_To_Num(SD1) AND DateNum() = Date_To_Num(ED1)) OR (DateNum() = Date_To_Num(SD2) AND DateNum() = Date_To_Num(ED2)) OR (DateNum() = Date_To_Num(SD3) AND DateNum() = Date_To_Num(ED3)) OR (DateNum() = Date_To_Num(SD4) AND DateNum() = Date_To_Num(ED4)) OR (DateNum() = Date_To_Num(SD5) AND DateNum() = Date_To_Num(ED5)) OR (DateNum() = Date_To_Num(SD6) AND DateNum() = Date_To_Num(ED6)) OR (DateNum() = Date_To_Num(SD7) AND DateNum() = Date_To_Num(ED7)) OR (DateNum() = Date_To_Num(SD8) AND DateNum() = Date_To_Num(ED8)) OR (DateNum() = Date_To_Num(SD9) AND DateNum() = Date_To_Num(ED9)) OR (DateNum() = Date_To_Num(SD10) AND DateNum() = Date_To_Num(ED10)) OR (DateNum() = Date_To_Num(SD11) AND DateNum() = Date_To_Num(ED11)) OR (DateNum() = Date_To_Num(SD12) AND DateNum() = Date_To_Num(ED12)) OR (DateNum() = Date_To_Num(SD13) AND DateNum() = Date_To_Num(ED13)) OR (DateNum() = Date_To_Num(SD14) AND DateNum() = Date_To_Num(ED14)) OR (DateNum() = Date_To_Num(SD15) AND DateNum() = Date_To_Num(ED15)) OR (DateNum() = Date_To_Num(SD16) AND DateNum() = Date_To_Num(ED16)) OR (DateNum() = Date_To_Num(SD17) AND DateNum() = Date_To_Num(ED17)) OR (DateNum() = Date_To_Num(SD18) AND DateNum() = Date_To_Num(ED18)) OR (DateNum() = Date_To_Num(SD19) AND DateNum() = Date_To_Num(ED19)) OR (DateNum() = Date_To_Num(SD20) AND DateNum() = Date_To_Num(ED20)) OR (DateNum() = Date_To_Num(SD21) AND DateNum() = Date_To_Num(ED21)) OR (DateNum() = Date_To_Num(SD22) AND DateNum() = Date_To_Num(ED22)); // // Plot Overlay Recession Bands // Plot_RecessionBands = ParamToggle(Plot_RecessionBands, NO|YES, 0); //recBarColor = Param(RecessionColorNum, 25,16,55,1);
[amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Sebastian and bistrader, That is a very clean, fast, and simple solution, Sebastian. I actually prefer your method most of the time. However, I kind of got carried away and wrote it the hard way reading a csv file directly with the string functions. This code could be used to plot user-defined periods of any sort whose start and end dates are stored in two columns in a csv file. Please read the comments at the top of my code so you know how the begin and end recession dates should be formatted in the csv file. I wrote the dates for the recessions from then nber.org website from 1900 to now, and just guessed that the current recession would end at the end of this year. You can find them in a comment below the main code. I fully debugged this and it works. It basically parses the dates out of a csv file and then loops through to make a isRecession boolean array, which is then plotted on the chart in gray area, as bistrader originally requested. I hope you like this solution! -Paul CODE: /*Coded By: Paul D. ( notanaiqgen...@yahoo.com ) Last Modified: 07/05/2010 using Amibroker 5.3 for Yahoo amibroker group message #150705 for bistrader NOTE #1: CSV file must be in following format: MM/DD/,MM/DD/ MM/DD/,MM/DD/ MM/DD/,MM/DD/ where the first column is the START Of the recession OR period AND the Second column is the END Of the recession OR period NOTE #2: be sure to feed the full folder AND file path with \\ slashs for folder/file separators; it should look like this path string: C:\\abTestData\\recessions.csv You will need to make a folder called abTestData and put the recessions.csv file in there if you want my code to work as-is NOTE #3: the Plot should be inserted as an OVERLAY. NOTE #4: dates before 1900 won't work i don't think because i used Easy Language style dates which are in the format of YYYMMDD like 1101231. 01/01/1900 would be 101, so can't go before 01/01/1900. Sorry didn't think about this beforehand. */ function GetRecessionDates(returnBeginOrEnd, fullPathAndFileName) {//if you want the BEGIN dates array to be returned, set returnBeginOrEnd to 0 //if you want the END dates array to be returned, set returnBeginOrEnd to 1 local recDateStr; local fh; recDateStr = ; fh = fopen(fullPathAndFileName,r); if (fh) { while(!feof(fh)) //get all text/string from csv file { recDateStr += fgets(fh); recDateStr += ,; } fclose(fh); //_TRACE(the string: + recDateStr); //parse string and put it into an numeric array that this function will return rDatesBEGINarr = 0; rDatesENDarr = 0; DateCntr = 0; rDatesBEGINcntr = 0; rDatesENDcntr = 0; slashCounter = 0; MonthNum = 0; DayNum = 0; YearNum = 0; tempDateNum = 0; i = 0; fp = 0;//fp = first position while(iStrLen(recDateStr)) { if(StrMid(recDateStr,i,1)==/) { switch(slashCounter) { case 0: MonthNum = StrToNum(StrMid(recDateStr,fp,i-fp));break; //save month case 1: DayNum = StrToNum(StrMid(recDateStr,fp,i-fp));break; //save day } slashCounter++; fp = i + 1; } //save year + entire datenum if(StrMid(recDateStr,i,1)==, StrMid(recDateStr,i-1,1) != ,) { if(StrMid(recDateStr,i-1,1)==\n)//if previous char was newline char YearNum = StrToNum(StrMid(recDateStr,fp,i-fp-1)); else//else last char not newline char YearNum = StrToNum(StrMid(recDateStr,fp,i-fp)); tempDateNum = 1*(YearNum-1900) + 100*MonthNum + DayNum; if(DateCntr % 2 == 0) { rDatesBEGINarr[rDatesBEGINcntr] = tempDateNum; rDatesBEGINcntr++; } else { rDatesENDarr[rDatesENDcntr] = tempDateNum; rDatesENDcntr++; } DateCntr++; fp = i + 1; slashCounter = 0; } i++; } } if(returnBeginOrEnd==0) returnArr = rDatesBEGINarr; else returnArr = rDatesENDarr; return returnArr; } myFolderFilePath = C:\\abTestData\\recessions.csv;//remember \ is written as \\ rBegin = GetRecessionDates(0, myFolderFilePath); rEnd = GetRecessionDates(1, myFolderFilePath); /*tempStr = ; for(i=0;iBarCount;i++) { tempStr = StrFormat( rBegin[i]: %f +rEnd[i]: %f, rBegin[i],rEnd[i]); _TRACE(i: + i + tempStr); }*/ /*Now make isRecession amibroker array that will have 1 for recessions and 0 for no recession on that date*/ dn =
[amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Thanks. Appreciated! --- In amibroker@yahoogroups.com, sebastiandanconia sebastiandanco...@... wrote: Using a csv file was the way I solved this problem. The AB code is short and simple that way. I took the recession/expansion dates from: http://www.nber.org/cycles.html ...then created a csv file named ^Recession Ribbon (with the data,open,high,low,close,volume,open interest format) with 1s and 0s to denote expansions and recessions. This AB code will give you a yellow ribbon from the top to the bottom of a price chart during recessions. REC=Foreign(^Recession Ribbon,C)==0; Plot(REC, Recession, colorYellow,styleOwnScale|styleArea|styleNoLabel , 0,1); Sebastian --- In amibroker@yahoogroups.com, bistrader bistrader@ wrote: Paul, Thanks. Two items. First, I would like the overlay to extend from the top to the bottom of the chart. Is there a way to do this? I remember seeing a chart someplace that did this but can not find it. Second, I would like to place the state date and end date for each recession in a csv, but is there a way to read the start and end dates (from column A and B, respectively) into the arrays that you have? Thanks Bert --- In amibroker@yahoogroups.com, notanaiqgenius notanaiqgenius@ wrote: Hi, I made this indicator for you. Try applying as an overlay. Let me know if that works for you. Paul - //RD stands for recession date StartRD1 = 1050101; EndRD1 = 1050631; StartRD2 = 1000401; EndRD2 = 1030101; StartRD3 = 1070701; EndRD3 = 1090301; isRecession = (DateNum()=StartRD1 AND DateNum()=EndRD1) OR (DateNum()=StartRD2 AND DateNum()=EndRD2) OR (DateNum()=StartRD3 AND DateNum()=EndRD3); myATR = ATR(50); recBarColor = Param(RecessionColorNum, 25,16,55,1); rOpen = IIf(isRecession,Open,Open); rHigh = IIf(isRecession,High+5*myATR,High); rLow = IIf(isRecession,Low-5*myATR,Low); rClose = IIf(isRecession,Close,Close); PlotOHLC( rOpen, rHigh, rLow, rClose, RecessionOverlay, recBarColor, styleCandle); --- In amibroker@yahoogroups.com, bistrader bistrader@ wrote: I would like to create an overlay afl that has recession periods in a color that can be selected via parameter with default of light gray. I can come up with the beginning and ending dates for each period, but am not how to proceed. Getting lost on how to best define (i.e., maybe 1 if in recession and 0 otherwise) and how to best plot. Help appreciated.
[amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Wow. Need to study. More work than expected. Most is ready the csv file and converting to 1s and 0s it appears. Thanks for sharing. --- In amibroker@yahoogroups.com, notanaiqgenius notanaiqgen...@... wrote: Sebastian and bistrader, That is a very clean, fast, and simple solution, Sebastian. I actually prefer your method most of the time. However, I kind of got carried away and wrote it the hard way reading a csv file directly with the string functions. This code could be used to plot user-defined periods of any sort whose start and end dates are stored in two columns in a csv file. Please read the comments at the top of my code so you know how the begin and end recession dates should be formatted in the csv file. I wrote the dates for the recessions from then nber.org website from 1900 to now, and just guessed that the current recession would end at the end of this year. You can find them in a comment below the main code. I fully debugged this and it works. It basically parses the dates out of a csv file and then loops through to make a isRecession boolean array, which is then plotted on the chart in gray area, as bistrader originally requested. I hope you like this solution! -Paul CODE: /*Coded By: Paul D. ( notanaiqgen...@... ) Last Modified: 07/05/2010 using Amibroker 5.3 for Yahoo amibroker group message #150705 for bistrader NOTE #1: CSV file must be in following format: MM/DD/,MM/DD/ MM/DD/,MM/DD/ MM/DD/,MM/DD/ where the first column is the START Of the recession OR period AND the Second column is the END Of the recession OR period NOTE #2: be sure to feed the full folder AND file path with \\ slashs for folder/file separators; it should look like this path string: C:\\abTestData\\recessions.csv You will need to make a folder called abTestData and put the recessions.csv file in there if you want my code to work as-is NOTE #3: the Plot should be inserted as an OVERLAY. NOTE #4: dates before 1900 won't work i don't think because i used Easy Language style dates which are in the format of YYYMMDD like 1101231. 01/01/1900 would be 101, so can't go before 01/01/1900. Sorry didn't think about this beforehand. */ function GetRecessionDates(returnBeginOrEnd, fullPathAndFileName) {//if you want the BEGIN dates array to be returned, set returnBeginOrEnd to 0 //if you want the END dates array to be returned, set returnBeginOrEnd to 1 local recDateStr; local fh; recDateStr = ; fh = fopen(fullPathAndFileName,r); if (fh) { while(!feof(fh)) //get all text/string from csv file { recDateStr += fgets(fh); recDateStr += ,; } fclose(fh); //_TRACE(the string: + recDateStr); //parse string and put it into an numeric array that this function will return rDatesBEGINarr = 0; rDatesENDarr = 0; DateCntr = 0; rDatesBEGINcntr = 0; rDatesENDcntr = 0; slashCounter = 0; MonthNum = 0; DayNum = 0; YearNum = 0; tempDateNum = 0; i = 0; fp = 0;//fp = first position while(iStrLen(recDateStr)) { if(StrMid(recDateStr,i,1)==/) { switch(slashCounter) { case 0: MonthNum = StrToNum(StrMid(recDateStr,fp,i-fp));break; //save month case 1: DayNum = StrToNum(StrMid(recDateStr,fp,i-fp));break; //save day } slashCounter++; fp = i + 1; } //save year + entire datenum if(StrMid(recDateStr,i,1)==, StrMid(recDateStr,i-1,1) != ,) { if(StrMid(recDateStr,i-1,1)==\n)//if previous char was newline char YearNum = StrToNum(StrMid(recDateStr,fp,i-fp-1)); else//else last char not newline char YearNum = StrToNum(StrMid(recDateStr,fp,i-fp)); tempDateNum = 1*(YearNum-1900) + 100*MonthNum + DayNum; if(DateCntr % 2 == 0) { rDatesBEGINarr[rDatesBEGINcntr] = tempDateNum; rDatesBEGINcntr++; } else { rDatesENDarr[rDatesENDcntr] = tempDateNum; rDatesENDcntr++; } DateCntr++; fp = i + 1; slashCounter = 0; } i++; } } if(returnBeginOrEnd==0) returnArr = rDatesBEGINarr; else returnArr = rDatesENDarr; return returnArr; } myFolderFilePath = C:\\abTestData\\recessions.csv;//remember \ is written as \\ rBegin =
[amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Hi BisTrader, No need to study it (unless you want to). It should work if you just do the following: 1) copy my code to new afl document. 2) create this directory: c:\abTestData\ 3) with Notepad copy and paste the following dates into a file and save it as a .csv file in that abTestData directory. Name the file recessions.csv 4) apply to afl document to chart and Enjoy. 09/01/1902,08/31/1904 05/01/1907,06/30/1908 01/01/1910,01/31/1912 01/01/1913,12/31/1914 08/01/1918,03/31/1919 01/01/1920,07/31/1921 05/01/1923,07/31/1924 10/01/1926,11/30/1927 08/01/1929,03/31/1933 05/01/1937,06/30/1938 02/01/1945,10/31/1945 11/01/1948,10/31/1949 07/01/1953,05/31/1954 08/01/1957,04/30/1958 04/01/1960,02/28/1961 12/01/1969,11/30/1970 11/01/1973,03/31/1975 01/01/1980,07/31/1980 07/01/1981,11/30/1982 07/01/1990,03/31/1991 03/01/2001,11/30/2001 12/01/2007,12/31/2010 --- In amibroker@yahoogroups.com, bistrader bistra...@... wrote: Wow. Need to study. More work than expected. Most is ready the csv file and converting to 1s and 0s it appears. Thanks for sharing. --- In amibroker@yahoogroups.com, notanaiqgenius notanaiqgenius@ wrote: Sebastian and bistrader, That is a very clean, fast, and simple solution, Sebastian. I actually prefer your method most of the time. However, I kind of got carried away and wrote it the hard way reading a csv file directly with the string functions. This code could be used to plot user-defined periods of any sort whose start and end dates are stored in two columns in a csv file. Please read the comments at the top of my code so you know how the begin and end recession dates should be formatted in the csv file. I wrote the dates for the recessions from then nber.org website from 1900 to now, and just guessed that the current recession would end at the end of this year. You can find them in a comment below the main code. I fully debugged this and it works. It basically parses the dates out of a csv file and then loops through to make a isRecession boolean array, which is then plotted on the chart in gray area, as bistrader originally requested. I hope you like this solution! -Paul CODE: /*Coded By: Paul D. ( notanaiqgenius@ ) Last Modified: 07/05/2010 using Amibroker 5.3 for Yahoo amibroker group message #150705 for bistrader NOTE #1: CSV file must be in following format: MM/DD/,MM/DD/ MM/DD/,MM/DD/ MM/DD/,MM/DD/ where the first column is the START Of the recession OR period AND the Second column is the END Of the recession OR period NOTE #2: be sure to feed the full folder AND file path with \\ slashs for folder/file separators; it should look like this path string: C:\\abTestData\\recessions.csv You will need to make a folder called abTestData and put the recessions.csv file in there if you want my code to work as-is NOTE #3: the Plot should be inserted as an OVERLAY. NOTE #4: dates before 1900 won't work i don't think because i used Easy Language style dates which are in the format of YYYMMDD like 1101231. 01/01/1900 would be 101, so can't go before 01/01/1900. Sorry didn't think about this beforehand. */ function GetRecessionDates(returnBeginOrEnd, fullPathAndFileName) {//if you want the BEGIN dates array to be returned, set returnBeginOrEnd to 0 //if you want the END dates array to be returned, set returnBeginOrEnd to 1 local recDateStr; local fh; recDateStr = ; fh = fopen(fullPathAndFileName,r); if (fh) { while(!feof(fh)) //get all text/string from csv file { recDateStr += fgets(fh); recDateStr += ,; } fclose(fh); //_TRACE(the string: + recDateStr); //parse string and put it into an numeric array that this function will return rDatesBEGINarr = 0; rDatesENDarr = 0; DateCntr = 0; rDatesBEGINcntr = 0; rDatesENDcntr = 0; slashCounter = 0; MonthNum = 0; DayNum = 0; YearNum = 0; tempDateNum = 0; i = 0; fp = 0;//fp = first position while(iStrLen(recDateStr)) { if(StrMid(recDateStr,i,1)==/) { switch(slashCounter) { case 0: MonthNum = StrToNum(StrMid(recDateStr,fp,i-fp));break; //save month case 1: DayNum = StrToNum(StrMid(recDateStr,fp,i-fp));break; //save day } slashCounter++; fp = i + 1; } //save year + entire datenum if(StrMid(recDateStr,i,1)==, StrMid(recDateStr,i-1,1) != ,) { if(StrMid(recDateStr,i-1,1)==\n)//if previous char was newline char YearNum =
[amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Paul, Thanks. Two items. First, I would like the overlay to extend from the top to the bottom of the chart. Is there a way to do this? I remember seeing a chart someplace that did this but can not find it. Second, I would like to place the state date and end date for each recession in a csv, but is there a way to read the start and end dates (from column A and B, respectively) into the arrays that you have? Thanks Bert --- In amibroker@yahoogroups.com, notanaiqgenius notanaiqgen...@... wrote: Hi, I made this indicator for you. Try applying as an overlay. Let me know if that works for you. Paul - //RD stands for recession date StartRD1 = 1050101; EndRD1 = 1050631; StartRD2 = 1000401; EndRD2 = 1030101; StartRD3 = 1070701; EndRD3 = 1090301; isRecession = (DateNum()=StartRD1 AND DateNum()=EndRD1) OR (DateNum()=StartRD2 AND DateNum()=EndRD2) OR (DateNum()=StartRD3 AND DateNum()=EndRD3); myATR = ATR(50); recBarColor = Param(RecessionColorNum, 25,16,55,1); rOpen = IIf(isRecession,Open,Open); rHigh = IIf(isRecession,High+5*myATR,High); rLow = IIf(isRecession,Low-5*myATR,Low); rClose = IIf(isRecession,Close,Close); PlotOHLC( rOpen, rHigh, rLow, rClose, RecessionOverlay, recBarColor, styleCandle); --- In amibroker@yahoogroups.com, bistrader bistrader@ wrote: I would like to create an overlay afl that has recession periods in a color that can be selected via parameter with default of light gray. I can come up with the beginning and ending dates for each period, but am not how to proceed. Getting lost on how to best define (i.e., maybe 1 if in recession and 0 otherwise) and how to best plot. Help appreciated.
[amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Using a csv file was the way I solved this problem. The AB code is short and simple that way. I took the recession/expansion dates from: http://www.nber.org/cycles.html ...then created a csv file named ^Recession Ribbon (with the data,open,high,low,close,volume,open interest format) with 1s and 0s to denote expansions and recessions. This AB code will give you a yellow ribbon from the top to the bottom of a price chart during recessions. REC=Foreign(^Recession Ribbon,C)==0; Plot(REC, Recession, colorYellow,styleOwnScale|styleArea|styleNoLabel , 0,1); Sebastian --- In amibroker@yahoogroups.com, bistrader bistra...@... wrote: Paul, Thanks. Two items. First, I would like the overlay to extend from the top to the bottom of the chart. Is there a way to do this? I remember seeing a chart someplace that did this but can not find it. Second, I would like to place the state date and end date for each recession in a csv, but is there a way to read the start and end dates (from column A and B, respectively) into the arrays that you have? Thanks Bert --- In amibroker@yahoogroups.com, notanaiqgenius notanaiqgenius@ wrote: Hi, I made this indicator for you. Try applying as an overlay. Let me know if that works for you. Paul - //RD stands for recession date StartRD1 = 1050101; EndRD1 = 1050631; StartRD2 = 1000401; EndRD2 = 1030101; StartRD3 = 1070701; EndRD3 = 1090301; isRecession = (DateNum()=StartRD1 AND DateNum()=EndRD1) OR (DateNum()=StartRD2 AND DateNum()=EndRD2) OR (DateNum()=StartRD3 AND DateNum()=EndRD3); myATR = ATR(50); recBarColor = Param(RecessionColorNum, 25,16,55,1); rOpen = IIf(isRecession,Open,Open); rHigh = IIf(isRecession,High+5*myATR,High); rLow = IIf(isRecession,Low-5*myATR,Low); rClose = IIf(isRecession,Close,Close); PlotOHLC( rOpen, rHigh, rLow, rClose, RecessionOverlay, recBarColor, styleCandle); --- In amibroker@yahoogroups.com, bistrader bistrader@ wrote: I would like to create an overlay afl that has recession periods in a color that can be selected via parameter with default of light gray. I can come up with the beginning and ending dates for each period, but am not how to proceed. Getting lost on how to best define (i.e., maybe 1 if in recession and 0 otherwise) and how to best plot. Help appreciated.
[amibroker] Re: PLOT OVERLAY AFL FOR RECESSIONS
Hi, I made this indicator for you. Try applying as an overlay. Let me know if that works for you. Paul - //RD stands for recession date StartRD1 = 1050101; EndRD1 = 1050631; StartRD2 = 1000401; EndRD2 = 1030101; StartRD3 = 1070701; EndRD3 = 1090301; isRecession = (DateNum()=StartRD1 AND DateNum()=EndRD1) OR (DateNum()=StartRD2 AND DateNum()=EndRD2) OR (DateNum()=StartRD3 AND DateNum()=EndRD3); myATR = ATR(50); recBarColor = Param(RecessionColorNum, 25,16,55,1); rOpen = IIf(isRecession,Open,Open); rHigh = IIf(isRecession,High+5*myATR,High); rLow = IIf(isRecession,Low-5*myATR,Low); rClose = IIf(isRecession,Close,Close); PlotOHLC( rOpen, rHigh, rLow, rClose, RecessionOverlay, recBarColor, styleCandle); --- In amibroker@yahoogroups.com, bistrader bistra...@... wrote: I would like to create an overlay afl that has recession periods in a color that can be selected via parameter with default of light gray. I can come up with the beginning and ending dates for each period, but am not how to proceed. Getting lost on how to best define (i.e., maybe 1 if in recession and 0 otherwise) and how to best plot. Help appreciated.