using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components;namespace WealthLab.Strategies { public class FibLucas : WealthScript { private StrategyParameter paramAmount; int[] fib = new int[] {5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,6765}; int[] lucas = new int[] {3,4,7,11,18,29,47,76,123,199,322,521,843,1364,2207,3571}; Font font = new Font("Wingdings", 8, FontStyle.Bold); Font font2 = new Font("Verdana", 7, FontStyle.Regular); string upArrow = Convert.ToChar(0x00E9).ToString(); string dnArrow = Convert.ToChar(0x00EA).ToString(); public FibLucas() { paramAmount = CreateParameter("Reversal %", 10, 2, 50, 1); } // Marking bars private void Highlighter( int[] array, double barsSince, int bar, Color color) { for( int i = 0; i < array.GetLength(0); i++ ) { if( barsSince == array[i] ) { AnnotateBar(upArrow, bar, false, color, Color.Transparent, font); AnnotateBar(array[i].ToString(), bar, false, color, Color.Transparent, font2); SetBarColor( bar, color ); break; } } } protected override void Execute() { // Variable definition, series creation and array initialization PeakTroughMode pct = PeakTroughMode.Percent; double amt = paramAmount.Value; Peak p = Peak.Series( High, amt, pct ); PeakBar pb = PeakBar.Series( High, amt, pct ); Trough t = Trough.Series( Low, amt, pct ); TroughBar tb = TroughBar.Series( Low, amt, pct ); Calculate c = new Calculate(this); // pass an instance of the WealthScript object DataSeries barsSince = new DataSeries(Bars,"Bars Since Start"); int markbar = -1; int init = -1; SetBarColors( Color.Silver,Color.Silver ); HideVolume(); // Build auxiliary binary wave DataSeries start = new DataSeries( Bars, "start" ); for(int bar = Bars.Count-1; bar >= 0; bar--) { int i = Math.Max( (int)tb[bar], (int)pb[bar] ); if( i > -1 ) { start[i] = i; init = i; break; } else start[i] = -1; } for(int bar = init; bar < Bars.Count; bar++) { // Building BarsSince series if( c.BarsSince( bar, CrossOver(bar, start, 0) ) == 0) markbar = bar; if( markbar > 0 ) barsSince[bar] = bar - markbar; // Marking Fibonacci/Lucas bars Highlighter( fib, barsSince[bar], bar, Color.Blue ); Highlighter( lucas, barsSince[bar], bar, Color.Red ); } } } }