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

[amibroker] Re: Slope in radians? question for Math geniuses



PureBytes Links

Trading Reference Links

Found the reason,  The Ref function is iterating from Bar 0 onward. And so, The Array also needs to be iterated from Bar 0 onward. Not Lastbar backward as it was in the original code........... Also, does anyone know why I have to Store the Array in Reverse??? (BC-BCL) ie Array[0] is ending up as Array[LastBar] in the composite................... KR         Michael. SCAN CODE: // Create Trend Direction Composite V1.1 (Daily Only) // //      This is to be run in SCAN mode. // Note - This scan can be slow, Don't run on "All Stocks"! // Setup // Use Zig 7. (Default) // Filter = Current Stock (eg. Index) // n = 1 Buy = 1; // To Satisfy scan (Create Composite) //Scan: CompName = Name() + "~Trend"; BC = (BarCount-1);  //Arrays size is same (Shortcut) adjz = Param("Zig",7,0,15,0.1); for( BCL = (BarCount-1); BCL >= 0; BCL-- )         {         CAdj = Ref(Close,-BCL);         LTB = TroughBars(CAdj,adjz,1);         LPB = PeakBars(CAdj,adjz,1);         for( i = (adjz*10); i > -1; i-- )                 {         adjz2 = i/10;         LTB2 = TroughBars(CAdj,adjz2);         LPB2 = PeakBars(CAdj,adjz2);         if ((LTB[BC] != LTB2[BC]) OR (LPB[BC] != LPB2[BC])) {i=0;}                 }         // Create Unique Primary & Secondary Arrays in For Loop.         // On ref array, insert into Specific array Position.         // 1 = UP, 2 = Down. //Array is stored Reverse???         Primary[(BC-BCL)] = IIf( (LTB[BC] < LPB[BC]),1,2);         Secondary[(BC-BCL)] = IIf( (LTB2[BC] < LPB2[BC]),1,2);         } //Add Primary & Secondary ARRAYS to composite. AddToComposite( Primary,   CompName, "O",3);   AddToComposite( Secondary, CompName, "H",3);   AddToComposite( 1,         CompName, "IO",3 ); At 11:44 AM 26/01/2004, you wrote: Here's some little Code Snippets from my trading system work in progress. You should be able to just Cut N Paste into Amibroker. 1st up is an Indicator that shows WalkForward conditions of ZigTrend status. 2nd is a Scan that creates a composite of those WalkForward Conditions. The trends are derived from PeakBar & TroughBar functions. I have Implemented the Calculation of Zig in a SAFE manner (Within a WalkForward style For Loop), For the creation of the Trend directions. Any insights to this (Good or Bad) would be very much welcome at this point. INDICATOR Notes: Use the Parameter function (CTRL-R) to move back in time, Watch the Primary and Secondary Trends change as you Move Back. SCAN Notes: Creates a composite ticker (Based on selected Ticker) Indicating Primary and Secondary Trends. Composite is named: Ticker~Trend COMPOSITE Notes: Open is considered the Primary Trend High is considered the Secondary Trend 1 is considered UP 2 is considered DOWN INDICATOR CODE: // Trend Direction Indicator V1. (Daily Only) // Use Zig 7. BC = (BarCount-1);  //Arrays size is same (Shortcut) adjz = Param("Zig",7,0,15,0.1); adjc = Param("Back",0,0,BarCount,1); CAdj = Ref(Close,-adjc); LTB = TroughBars(CAdj,adjz,1); LPB = PeakBars(CAdj,adjz,1); PlotZig1 = Zig(CAdj,adjz); for( i = (adjz*10); i > -1; i-- )   {    adjz2 = i/10;    LTB2 = TroughBars(CAdj,adjz2);    LPB2 = PeakBars(CAdj,adjz2);    if ((LTB[BC] != LTB2[BC]) OR (LPB[BC] != LPB2[BC])) {i=0;}   } PlotZig2 = Zig(CAdj,adjz2); if (LTB[BC] < LPB[BC])         { Primary = "Up";}         else         { Primary = "Down";} if (LTB2[BC] < LPB2[BC])         { Secondary = "Up";}         else         { Secondary = "Down";} WriteVal(BarCount)+" BarCount (Total)"; WriteVal(BC)+" BC (For Arrays)\n"; Plot(CAdj,"Close",1,styleLine); Plot(PlotZig1,"Zig",colorBlue,styleLine); Plot(PlotZig2,"Zig2",colorRed,9); // Line-Dots. Title = Name() + "\nPrimary: " + Primary + "\nSecondary: " + Secondary + "\n\\c38Diagnostics....." + "\nLTB1: " + LTB + //" BC: " + LTB[BC] + "\nLPB1: " + LPB + //" BC: " + LPB[BC] + "\nLTB2: " + LTB2 + //" BC: " + LTB2[BC] + "\nLPB2: " + LPB2 + //" BC: " + LPB2[BC] + "\nBarIndex: " +BarIndex() + "\nRef Adjust: -" + Adjc + "\nZig1: " + adjz + "\nZig2: " + adjz2 + "\nClose Price: " + Cadj; SCAN CODE: // Create Trend Direction Composite V1. (Daily Only) // //      This is to be run in SCAN mode. // Note - This scan can be slow, Don't run on "All Stocks"! // Setup // Use Zig 7. (Default) // Filter = Current Stock (eg. Index) // n = 1 Buy = 1; // To Satisfy scan (Create Composite) //Scan: CompName = Name() + "~Trend"; BC = (BarCount-1);  //Arrays size is same (Shortcut) adjz = Param("Zig",7,0,15,0.1); for( BCL = (BarCount-1); BCL > -1; BCL-- )         {         CAdj = Ref(Close,-BCL);         LTB = TroughBars(CAdj,adjz,1);         LPB = PeakBars(CAdj,adjz,1);         for( i = (adjz*10); i > -1; i-- )                 {         adjz2 = i/10;         LTB2 = TroughBars(CAdj,adjz2);         LPB2 = PeakBars(CAdj,adjz2);         if ((LTB[BC] != LTB2[BC]) OR (LPB[BC] != LPB2[BC])) {i=0;}                 }         // Create Unique Primary & Secondary Arrays in For Loop.         // On ref array, insert into Specific array Position.         // 1 = UP, 2 = Down.         Primary[BCL] = IIf( (LTB[BC] < LPB[BC]),1,2);         Secondary[BCL] = IIf( (LTB2[BC] < LPB2[BC]),1,2);         } //Add Primary & Secondary ARRAYS to composite. AddToComposite( Primary,   CompName, "O",3);   AddToComposite( Secondary, CompName, "H",3);   AddToComposite( 1,         CompName, "IO",3 ); Send BUG REPORTS to bugs@xxxxxxxxxxxxx Send SUGGESTIONS to suggest@xxxxxxxxxxxxx ----------------------------------------- Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: http://groups.yahoo.com/group/amiquote/messages/) -------------------------------------------- Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html Yahoo! Groups Links To visit your group on the web, go to: http://groups.yahoo.com/group/amibroker/   To unsubscribe from this group, send an email to: amibroker-unsubscribe@xxxxxxxxxxxxxxx   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. Send BUG REPORTS to bugs@xxxxxxxxxxxxx Send SUGGESTIONS to suggest@xxxxxxxxxxxxx ----------------------------------------- Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: http://groups.yahoo.com/group/amiquote/messages/) -------------------------------------------- Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html Yahoo! Groups Links To visit your group on the web, go to: http://groups.yahoo.com/group/amibroker/   To unsubscribe from this group, send an email to: amibroker-unsubscribe@xxxxxxxxxxxxxxx   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. Send BUG REPORTS to bugs@xxxxxxxxxxxxx Send SUGGESTIONS to suggest@xxxxxxxxxxxxx ----------------------------------------- Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx (Web page: http://groups.yahoo.com/group/amiquote/messages/) -------------------------------------------- Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html Yahoo! Groups Sponsor ADVERTISEMENT Yahoo! Groups Links To visit your group on the web, go to:http://groups.yahoo.com/group/amibroker/  To unsubscribe from this group, send an email to:amibroker-unsubscribe@xxxxxxxxxxxxxxx  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.