internal void InitTIKReader(int Index, string filepath, bool saveticks, int interval) { tr = new TikReader(filepath); if (_saveticks) { ticks = new List <Tick>(tr.ApproxTicks); } else { ticks = new List <Tick>(); } _saveticks = saveticks; idx = Index; if (interval == 0) { tr.gotTick += new TickDelegate(tr_gotTick); } else { bl = new BarListImpl(tr.Symbol, interval, BarInterval.CustomTime); bl.GotNewBar += new SymBarIntervalDelegate(bl_GotNewBar); tr.gotTick += new TickDelegate(tr_gotTick2); } }
/// <summary> /// create ticks from bars on default interval /// </summary> /// <param name="bl"></param> /// <returns></returns> public static Tick[] Barlist2Tick(BarList bl) { List<Tick> k = new List<Tick>(bl.Count * 4); foreach (Bar b in bl) k.AddRange(BarImpl.ToTick(b)); return k.ToArray(); }
private void button2_Click(object sender, EventArgs e) { OpenFileDialog od = new OpenFileDialog(); od.CheckFileExists = true; od.CheckPathExists = true; od.DefaultExt = "*.EPF"; od.Filter = "TickFiles|*.EPF;*.IDX"; od.InitialDirectory = "c:\\program files\\tradelink\\tickdata\\"; od.Multiselect = false; od.ShowDialog(); BarList bl = od.FileName.Contains(".EPF") ? BarList.FromEPF(od.FileName) : BarList.FromIDX(od.FileName); Chart c = new Chart(bl, false); c.Symbol = bl.Symbol; try { c.StartPosition = FormStartPosition.Manual; c.Location = Chartographer.Properties.Settings.Default.chartstart; } catch (NullReferenceException) { } newChartData += new BarListUpdated(c.NewBarList); c.Move += new EventHandler(c_Move); c.Icon = Chartographer.Properties.Resources.chart; if (maxchartbox.Checked) { c.WindowState = FormWindowState.Maximized; } if (blackbackground.Checked) { c.BackColor = Color.Black; } c.Show(); }
internal void InitCSVReader(int Index, string filepath, bool saveticks, int interval) { var s = ChimeraDataUtils.SecurityFromFileName(filepath); string strQuote = ChimeraDataUtils.QuotePathFromTradePath(filepath); string strNBBO = ChimeraDataUtils.NBBOPathFromTradePath(filepath); trCSV = new CSVtoTikReader(filepath, strQuote, strNBBO, s.symbol, s.Date); if (_saveticks) { ticks = new List <Tick>(trCSV.ApproxTicks); } else { ticks = new List <Tick>(); } _saveticks = saveticks; idx = Index; if (interval == 0) { trCSV.gotTick += new TickDelegate(tr_gotTick); } else { bl = new BarListImpl(trCSV.Symbol, interval, BarInterval.CustomTime); bl.GotNewBar += new SymBarIntervalDelegate(bl_GotNewBar); trCSV.gotTick += new TickDelegate(tr_gotTick2); } }
/// <summary> /// insert one barlist into another barlist /// REMEMBER: You must re-handle the GotNewBar event after calling this method. /// You should also ensure that inserted barlist has same intervals/types as original barlist. /// </summary> /// <param name="bl"></param> /// <param name="insert"></param> /// <returns></returns> public static BarListImpl InsertBarList(BarList bl, BarList insert) { BarListImpl copy = new BarListImpl(bl); for (int j = 0; j < bl.CustomIntervals.Length; j++) { for (int k = 0; k < insert.CustomIntervals.Length; k++) { if (bl.CustomIntervals[j] != insert.CustomIntervals[k]) { continue; } for (int l = 0; l < insert.Count; l++) { for (int m = 0; m < bl.Count; m++) { if (l == m) { addbar(copy, insert[l, (BarInterval)insert.CustomIntervals[k]], j); } addbar(copy, bl[m], j); } } } } return(copy); }
public void NewBarList(BarList barlist) { bl = barlist; Symbol = barlist.Symbol; Text = Title; Invalidate(true); }
void GotNewBar(string symbol, int interval) { // get index for symbol int idx = indicatorcross2.addindex(symbol); // get current barlist for this symbol+interval BarList bl = blt[symbol, interval]; // check for first cross on first interval if (interval == (int)BarInterval.Minute) { // update the cross state indicatorcross1[symbol] = bl.RecentBar.Close > Calc.Avg(bl.Close()); } // check second cross if (interval == (int)BarInterval.FiveMin) { // update the cross state indicatorcross2[symbol] = bl.RecentBar.Close > Calc.Avg(bl.Close()); } // update first1then2 if (first1then2ok[symbol] && indicatorcross2[symbol] && !indicatorcross1[symbol]) { first1then2ok[symbol] = false; } // send order if everything looks good (also showed failed rules) if (gt.rulepasses(idx, "sequential buy entry", senddebug, true, first1then2ok, indicatorcross2, indicatorcross1)) { sendorder(new BuyMarket(symbol, 100)); } }
public static decimal BarSMA(BarList bl, BarInterval bi, int barsback) { if (!bl.Has(barsback)) { return(bl.Get(bl.Last).Close); } decimal sum = 0; for (int i = 0; i < barsback; i++) { try { sum += bl.Get(bl.Last - i, bi).Close; } catch (ArgumentOutOfRangeException) { // ArgumentOutOfRange is thrown when: // (bars requested) > (bars you have) // TO FIX: // make sure you call bl.Has(NumOfBarsYouNeed) // before you call bl.Get(BarNumIDontYetHave) } } return(sum / barsback); }
public void NewBarList(BarList barlist) { chartControl1.NewBarList(barlist); Symbol = barlist.Symbol; Text = chartControl1.Title; Invalidate(true); }
public void NewBars() { BarList bl = new BarList(BarInterval.FiveMin); int newbars = 0; foreach (Tick k in ticklist) { bl.newTick(k); if (bl.NewBar) { newbars++; } } Assert.That(newbars == 2, newbars.ToString()); bl = new BarList(BarInterval.Minute); newbars = 0; foreach (Tick k in ticklist) { bl.newTick(k); if (bl.NewBar) { newbars++; } } Assert.That(newbars == 8, newbars.ToString()); }
/// <summary> /// This function will be delegated in "Reset" method /// and will be called whenever the system got a new bar /// The stratege should be contained in this method /// </summary> /// <param name="symbol"></param> /// <param name="interval"></param> void blt_GotNewBar(string symbol, int interval) { BarList myBars = _blt[symbol, interval]; // If we only get one bar, exit if (myBars.Count <= 1) { return; } // make sure the lastBar is full _lastBar = myBars[myBars.Count - 2]; // Update lastBars if (_lastBars.getindex(symbol) < 0) { _lastBars.addindex(symbol); } _lastBars[symbol] = _lastBar; // Update indicators ComputeSignal(); string[] indicators = GetDisplayIndicators(); sendindicators(indicators); // Buy or sell // Strategy based on computed ATR indicator //DoStrategy(symbol, signal); DoStrategy(); }
/// <summary> /// create bars from ticks /// </summary> /// <param name="k"></param> public void newTick(Tick k) { if (bl == null) { Symbol = k.symbol; bl = new BarListImpl(k.symbol); } bl.newTick(k); if (k.isTrade) { if (k.trade > highesth) { highesth = k.trade; } if (k.trade < lowestl) { lowestl = k.trade; } } barc = bl.Count; if (_alwaysupdate) { redraw(); } }
/// <summary> /// create bars from points /// </summary> /// <param name="p"></param> /// <param name="time"></param> /// <param name="date"></param> /// <param name="size"></param> public void newPoint(decimal p, int time, int date, int size) { if (bl == null) { Symbol = string.Empty; highesth = SMALLVAL; bl = new BarListImpl(string.Empty); } bl.newPoint(p, time, date, size); if (p != 0) { if (p > highesth) { highesth = p; } if (p < lowestl) { lowestl = p; } } barc = bl.Count; if (_alwaysupdate) { redraw(); } }
void GotNewBar(string symbol, int interval) { // get current barlist for this symbol+interval BarList bl = blt[symbol, interval]; // get index for symbol int idx = PRIMARY.getindex(symbol); // check for first cross on first interval if (interval == (int)BarInterval.Minute) { // update the cross state indicatorcross1[symbol] = bl.RecentBar.Close > Calc.Avg(bl.Close()); } // check second cross if (interval == (int)BarInterval.FiveMin) { // update the cross state indicatorcross2[symbol] = bl.RecentBar.Close > Calc.Avg(bl.Close()); } // update first1then2 if (first1then2ok[symbol] && indicatorcross2[symbol] && !indicatorcross1[symbol]) { first1then2ok[symbol] = false; } // send order if everything looks good if (first1then2ok[symbol] && indicatorcross2[symbol] && indicatorcross1[symbol]) { sendorder(new BuyMarket(symbol, 100)); } // notify of current tracker values sendindicators(gt.GetIndicatorValues(idx, gens())); }
/// <summary> /// create bars from points /// </summary> /// <param name="p"></param> /// <param name="time"></param> /// <param name="date"></param> /// <param name="size"></param> public void newPoint(string symbol, decimal p, int time, int date, int size) { if (bl == null) { Symbol = symbol; highesth = SMALLVAL; bl = new BarListImpl(symbol); } bl.newPoint(symbol, p, time, date, size); if (p != 0) { if (p > highesth) { highesth = p; } if (p < lowestl) { lowestl = p; } } if (_alwaysupdate) { redraw(); } }
void tl_gotTick(Tick t) { try { _tlt.newTick(t); _kt.newTick(t); if (spillTick != null) { spillTick(t); } RefreshRow(t); BarList bl = null; if (bardict.TryGetValue(t.symbol, out bl)) { if (SecurityImpl.Parse(t.symbol).Type == SecurityType.CASH) { Tick k = _kt[t.symbol]; decimal p = usebidonfx ? k.bid : k.ask; int s = usebidonfx ? k.bs : k.os; bardict[t.symbol].newPoint(t.symbol, p, k.time, k.date, s); } else { bardict[t.symbol].newTick(t); } } } catch (System.Threading.ThreadInterruptedException) { } }
public decimal AvgVol(BarList bl) // gets the average volume across all bars { if (!bl.Has(MinimumBarsToAvg,bl.DefaultInterval)) return 0; // if we don't have a bar yet we can't have an avg bar volume int sum = 0; for (int i = 0; i < bl.Count; i++) sum += bl[i].Volume; return sum / (bl.Count); }
/// <summary> /// calculates lower bollinger using open (true) or closing (false) prices, at specified # of standard deviations /// </summary> /// <param name="bl"></param> /// <param name="numStdDevs"></param> /// <param name="useOpens"></param> /// <returns></returns> public static decimal BollingerLower(BarList bl, decimal numStdDevs, bool useOpens) { decimal[] prices = useOpens ? bl.Open() : bl.Close(); decimal mean = Avg(prices); decimal stdev = StdDev(prices); return(mean - stdev * numStdDevs); }
public void FromEPF() { // get sample tick data BarList bl = BarListImpl.FromEPF("FTI20070926.EPF"); // verify expected number of 5min bars exist (78 in 9:30-4p) Assert.AreEqual(83, bl.Count); }
void _barlisttracker_GotNewBar(string sym, int interval) { //int idx = Array.IndexOf(_symbols, sym); int idx = _symbols.IndexOf(sym); if (_isactive && _issymbolactive[idx]) { BarList bl = _barlisttracker[sym, interval]; double[] closes = Calc.Decimal2Double(bl.Close()); // when NewBar is triggered, the latest bar only has one tick closes = closes.Take(closes.Length - 1).ToArray(); SMAResult result = AnalysisEngine.SMA(closes, _barslookback); if (result.Values.Count == 0) // Not enough bars { return; } // check if (!_waittobefilled[idx]) { double sma = result.Values.Last(); if (_positiontracker[sym].isFlat) { // if our current price is above SMA if (closes.Last() > sma) { SendDebug("Cross above SMA, buy"); SendOrder(new MarketOrder(sym, _tradesize)); _waittobefilled[idx] = true; } // if our current price is below SMA else if (closes.Last() < sma) { SendDebug("Cross below SMA, sell"); SendOrder(new MarketOrder(sym, -_tradesize)); _waittobefilled[idx] = true; } } else if ((_positiontracker[sym].isLong && (closes.Last() < sma)) || (_positiontracker[sym].isShort && (closes.Last() > sma))) { SendDebug("Counter trend, exit."); SendOrder(new MarketOrderFlat(_positiontracker[sym])); _waittobefilled[idx] = true; } // this way we can debug our indicators during development // indicators are sent in the same order as they are named above if (_waittobefilled[idx]) { SendIndicators(new string[] { "Time: " + _currenttime.ToString(), " SMA:" + sma.ToString("F2", System.Globalization.CultureInfo.InvariantCulture) }); } } } }
public void FromTIK() { const string tf = "FTI20070926.TIK"; // get sample tick data BarList bl = BarListImpl.FromTIK(tf); // verify expected number of 5min bars exist (78 in 9:30-4p) Assert.Greater(bl.Count, 82, "not enough bars from: " + tf); }
public void Basics() { const string sym = "TST"; const int d = 20080509; const int t = 935; const string x = "NYSE"; Tick[] ticklist = new Tick[] { Tick.NewTrade(sym, d, t, 0, 10, 100, x), Tick.NewTrade(sym, d, t + 1, 0, 10, 100, x), Tick.NewTrade(sym, d, t + 2, 0, 10, 100, x), Tick.NewTrade(sym, d, t + 3, 0, 10, 100, x), Tick.NewTrade(sym, d, t + 4, 0, 15, 100, x), // blade up Tick.NewTrade(sym, d, t + 5, 0, 16, 100, x), // new bar (blades reset) Tick.NewTrade(sym, d, t + 6, 0, 16, 100, x), Tick.NewTrade(sym, d, t + 7, 0, 10, 100, x), // blade down Tick.NewTrade(sym, d, t + 7, 10, 10, 100, x), // still a blade down (same bar) Tick.NewTrade(sym, d, t + 8, 0, 15, 100, x), Tick.NewTrade(sym, d, t + 15, 0, 15, 800, x), // volume spike Tick.NewTrade(sym, d, t + 20, 0, 15, 100, x), Tick.NewTrade(sym, d, t + 25, 0, 15, 100, x), }; BarList bl = new BarList(BarInterval.FiveMin, sym); Blade b = new Blade(); Assert.That(b.BladePercentage != 0); b = new Blade(.2m); // 20 percent move is a blade int up = 0, down = 0, newbar = 0, bigvol = 0; foreach (Tick k in ticklist) { bl.AddTick(k); b.newBar(bl); if (bl.NewBar) { newbar++; } if (b.isBladeUP) { up++; } if (b.isBladeDOWN) { down++; } if (b.isBigVolume) { bigvol++; } } Assert.That(up == 1, up.ToString()); Assert.That(down == 2, down.ToString()); Assert.That(newbar == 5, newbar.ToString()); Assert.That(bigvol == 1, bigvol.ToString()); }
public void FromGoogle() { // get a year chart BarList bl = BarListImpl.DayFromGoogle("IBM"); // make sure it's there Assert.IsTrue(bl.isValid); // verify we have at least a year of bar data Assert.GreaterOrEqual(bl.Count, 199); }
/// <summary> /// gets the most recent volumes from a barlist, given a certain number of bars back /// </summary> /// <param name="chart"></param> /// <param name="bars"></param> /// <returns></returns> public static int[] Volumes(BarList chart, int bars) { List <int> l = new List <int>(); for (int i = chart.Count - bars; i < chart.Count; i++) { l.Add(chart[i].Volume); } return(l.ToArray()); }
/// <summary> /// attempts to get year worth of daily data from google, if fails tries yahoo. /// </summary> /// <param name="symbol"></param> /// <returns></returns> public static BarList DayFromAny(string symbol) { BarList bl = BarListImpl.DayFromGoogle(symbol); if (bl.Count == 0) { bl = BarListImpl.DayFromYahoo(symbol); } return(bl); }
/// <summary> /// gets the high to low range of a barlist, for the default interval /// </summary> /// <param name="chart"></param> /// <returns></returns> public static decimal[] HLRange(BarList chart) { List <decimal> l = new List <decimal>(); foreach (BarImpl b in chart) { l.Add(b.High - b.Low); } return(l.ToArray()); }
/// <summary> /// create ticks from bars on default interval /// </summary> /// <param name="bl"></param> /// <returns></returns> public static Tick[] Barlist2Tick(BarList bl) { List <Tick> k = new List <Tick>(bl.Count * 4); foreach (Bar b in bl) { k.AddRange(BarImpl.ToTick(b)); } return(k.ToArray()); }
/// <summary> /// Argument Constructor /// </summary> /// <param name="shortEMA"></param> /// <param name="longEMA"></param> /// <param name="emaType"></param> public EMA(int shortEMA, int longEMA, string emaType) { _shortEMA = shortEMA; _longEMA = longEMA; _emaType = emaType; _barList = new BarList(this._longEMA, emaType); _ema = new decimal[2] { 0, 0 }; }
/// <summary> /// gets array of close to open ranges for default interval of a barlist /// </summary> /// <param name="chart"></param> /// <returns></returns> public static decimal[] CORange(BarList chart) { List <decimal> l = new List <decimal>(); foreach (BarImpl b in chart) { l.Add(b.Close - b.Open); } return(l.ToArray()); }
public void TestMaximumHistory() { const string tf = @"Common\EURUSD20080826.TIK"; // get sample tick data BarList bl = BarListImpl.FromTIK(tf); // verify that the max amount is set to 200 Assert.True(bl.Count == 200); }
public void FromTIK() { const string tf = @"Common\EURUSD20080826.TIK"; // get sample tick data BarList bl = BarListImpl.FromTIK(tf); // verify expected number of 5min bars exist (78 in 9:30-4p) Assert.True(bl.Count > 82); }
/// <summary> /// make copy of a barlist. remember you must re-setup GotNewBar events after using this. /// </summary> /// <param name="original"></param> public BarListImpl(BarList original) : this(original.Symbol,original.CustomIntervals,original.Intervals) { for (int j = 0; j<original.Intervals.Length; j++) { original.DefaultInterval = original.Intervals[j]; for (int i = 0; i < original.Count; i++) { addbar(this, original[i, original.Intervals[j]], j); } } }
/// <summary> /// make copy of a barlist. remember you must re-setup GotNewBar events after using this. /// </summary> /// <param name="original"></param> public BarListImpl(BarList original) : this(original.Symbol, original.CustomIntervals, original.Intervals) { for (int j = 0; j < original.Intervals.Length; j++) { original.DefaultInterval = original.Intervals[j]; for (int i = 0; i < original.Count; i++) { addbar(this, original[i, original.Intervals[j]], j); } } }
/// <summary> /// Initializes a new instance of the <see cref="Chart"/> class. /// </summary> /// <param name="b">The barlist.</param> /// <param name="allowtype">if set to <c>true</c> [allowtype] will allow typing/changing of new symbols on the chart window.</param> public ChartControl(BarList b,bool allowtype) { InitializeComponent(); Paint += new PaintEventHandler(Chart_Paint); MouseDoubleClick += new MouseEventHandler(ChartControl_MouseDoubleClick); MouseWheel +=new MouseEventHandler(Chart_MouseUp); if (b != null) { bl = b; Symbol = b.Symbol; } }
/// <summary> /// Initializes a new instance of the <see cref="Chart"/> class. /// </summary> /// <param name="b">The barlist.</param> /// <param name="allowtype">if set to <c>true</c> [allowtype] will allow typing/changing of new symbols on the chart window.</param> public ChartImpl(BarList b,bool allowtype) { InitializeComponent(); Paint += new PaintEventHandler(Chart_Paint); MouseWheel +=new MouseEventHandler(Chart_MouseUp); if (allowtype) this.KeyUp += new KeyEventHandler(Chart_KeyUp); if (b != null) { bl = b; Symbol = b.Symbol; } }
/// <summary> /// Initializes a new instance of the <see cref="Chart"/> class. /// </summary> /// <param name="b">The barlist.</param> /// <param name="allowtype">if set to <c>true</c> [allowtype] will allow typing/changing of new symbols on the chart window.</param> public Chart(BarList b,bool allowtype) { InitializeComponent(); MouseUp +=new MouseEventHandler(chartControl1.Chart_MouseUp); MouseWheel += new MouseEventHandler(Chart_MouseUp); if (allowtype) this.KeyUp += new KeyEventHandler(Chart_KeyUp); if (b != null) { chartControl1.NewBarList(b); Symbol = b.Symbol; } FormClosing += new FormClosingEventHandler(Chart_FormClosing); }
public bool newBar(BarList bl) { if (!bl.isValid) return false; Bar c = bl.RecentBar; if (!c.isValid) return false; decimal avgvol = Calc.Avg(bl.Vol()); decimal moverequired = c.Open * _percent; bool voltest = (c.Volume - avgvol) > (avgvol * _bigvolper); isBigVolume = (ZeroAvgVolIsBig && voltest) || (!ZeroAvgVolIsBig && (avgvol != 0) && voltest); isBladeDOWN = ((c.Open - c.Close) > moverequired); isBladeUP = ((c.Close-c.Open) > moverequired); pctChange = c.Close / c.Open - 1; return true; }
/// <summary> /// create bars from ticks /// </summary> /// <param name="k"></param> public void newTick(Tick k) { if (bl == null) { Symbol = k.symbol; bl = new BarListImpl(k.symbol); } bl.newTick(k); if (k.isTrade) { if (k.trade > highesth) highesth = k.trade; if (k.trade < lowestl) lowestl = k.trade; } if (_alwaysupdate) redraw(); }
/// <summary> /// create bars from ticks /// </summary> /// <param name="k"></param> public void newTick(Tick k) { if (bl == null) { Symbol = k.symbol; bl = new BarListImpl(BarInterval.FiveMin, k.symbol); } bl.newTick(k); if (k.isTrade) { if (k.trade > highesth) highesth = k.trade; if (k.trade < lowestl) lowestl = k.trade; } barc = bl.Count; if (_alwaysupdate) refresh(); }
/// <summary> /// create bars from points /// </summary> /// <param name="p"></param> /// <param name="time"></param> /// <param name="date"></param> /// <param name="size"></param> public void newPoint(string symbol, decimal p, int time, int date, int size) { if (bl == null) { Symbol = symbol; highesth = SMALLVAL; bl = new BarListImpl(symbol); } bl.newPoint(symbol,p, time, date, size); if (p!=0) { if (p > highesth) highesth = p; if (p < lowestl) lowestl = p; } if (_alwaysupdate) redraw(); }
/// <summary> /// create bars from points /// </summary> /// <param name="p"></param> /// <param name="time"></param> /// <param name="date"></param> /// <param name="size"></param> public void newPoint(decimal p, int time, int date, int size) { if (bl == null) { Symbol = string.Empty; highesth = SMALLVAL; bl = new BarListImpl(BarInterval.FiveMin, string.Empty); } bl.newPoint(p, time, date, size); if (p!=0) { if (p > highesth) highesth = p; if (p < lowestl) lowestl = p; } barc = bl.Count; if (_alwaysupdate) refresh(); }
public void NewBarList(BarList barlist) { if ((barlist != null) && (barlist.isValid)) Symbol = barlist.symbol; if ((barlist == null) || (barlist.Intervals.Length==0) || (barlist.Count==0)) { return; } bl = barlist; highesth = Calc.HH(bl); lowestl = Calc.LL(bl); redraw(); }
public ChartControl(BarList b) : this(b, false) { }
/// <summary> /// reset the chart and underlying data structures /// </summary> public void Reset() { if (InvokeRequired) Invoke(new VoidDelegate(Reset)); else { bl = null; sym = string.Empty; highesth = 0; lowestl = BIGVAL; hasosctextlabels = false; hastextlabels = false; _collineend.Clear(); _collineend_osc.Clear(); _colpoints.Clear(); _colpoints_osc.Clear(); redraw(); } }
/// <summary> /// gets most recent lows from barlist, for certain number of bars /// (default is entire list) /// </summary> /// <param name="chart"></param> /// <param name="bars"></param> /// <returns></returns> public static decimal[] Lows(BarList chart, int bars) { return EndSlice(chart.Low(), bars); }
/// <summary> /// gets ALL lows from barlist, at default bar interval /// </summary> /// <param name="chart"></param> /// <returns></returns> public static decimal[] Lows(BarList chart) { return chart.Low(); }
/// <summary> /// gets opening prices for most recent bars, at default bar interval /// </summary> /// <param name="chart"></param> /// <param name="bars"></param> /// <returns></returns> public static decimal[] Opens(BarList chart, int bars) { return EndSlice(chart.Open(), bars); }
/// <summary> /// gets most recent closing prices for ALL bars, default bar interval /// </summary> /// <param name="chart"></param> /// <returns></returns> public static decimal[] Closes(BarList chart) { return chart.Close(); }
/// <summary> /// calculates lower bollinger using opening prices. calculate yourself for faster speed /// </summary> /// <param name="bl"></param> /// <param name="numStdDevs"></param> /// <returns></returns> public static decimal BollingerLower(BarList bl, decimal numStdDevs) { return BollingerUpper(bl, numStdDevs, true); }
/// <summary> /// calculates lower bollinger using default # stdev of 2.5 and opening prices. /// Note, for speed it's faster to calculate these yourself. /// </summary> /// <param name="bl"></param> /// <returns></returns> public static decimal BollingerLower(BarList bl) { return BollingerUpper(bl, 2.5m, true); }
/// <summary> /// gets an array of true range values representing each bar in chart /// (uses default bar interval) /// </summary> /// <param name="chart"></param> /// <returns></returns> public static decimal[] TrueRange(BarList chart) { List<decimal> l = new List<decimal>(); for (int i = chart.Last; i > 0; i--) { Bar t = chart[i]; Bar p = chart[i - 1]; decimal max = t.High > p.Close ? t.High : p.Close; decimal min = t.Low < p.Close ? t.Low : p.Close; l.Add(max - min); } return l.ToArray(); }
/// <summary> /// gets array of close to open ranges for default interval of a barlist /// </summary> /// <param name="chart"></param> /// <returns></returns> public static decimal[] CORange(BarList chart) { List<decimal> l = new List<decimal>(); foreach (BarImpl b in chart) l.Add(b.Close - b.Open); return l.ToArray(); }
/// <summary> /// gets the high to low range of a barlist, for the default interval /// </summary> /// <param name="chart"></param> /// <returns></returns> public static decimal[] HLRange(BarList chart) { List<decimal> l = new List<decimal>(); foreach (BarImpl b in chart) l.Add(b.High - b.Low); return l.ToArray(); }
/// <summary> /// gets volumes for ALL bars, with default bar interval /// </summary> /// <param name="chart"></param> /// <returns></returns> public static long[] Volumes(BarList chart) { return Volumes(chart, chart.Count); }
/// <summary> /// gets the most recent volumes from a barlist, given a certain number of bars back /// </summary> /// <param name="chart"></param> /// <param name="bars"></param> /// <returns></returns> public static long[] Volumes(BarList chart, int bars) { List<long> l = new List<long>(); for (int i = chart.Count - bars; i < chart.Count; i++) l.Add(chart[i].Volume); return l.ToArray(); }
/// <summary> /// calculates lower bollinger using open (true) or closing (false) prices, at specified # of standard deviations /// </summary> /// <param name="bl"></param> /// <param name="numStdDevs"></param> /// <param name="useOpens"></param> /// <returns></returns> public static decimal BollingerLower(BarList bl, decimal numStdDevs, bool useOpens) { decimal[] prices = useOpens ? bl.Open() : bl.Close(); decimal mean = Avg(prices); decimal stdev = StdDev(prices); return mean - stdev * numStdDevs; }
/// <summary> /// gets opening prices for ALL bars, at the default bar interval /// </summary> /// <param name="chart"></param> /// <returns></returns> public static decimal[] Opens(BarList chart) { return chart.Open(); }
/// <summary> /// gets the most recent closing prices for a certain number of bars /// </summary> /// <param name="chart"></param> /// <param name="bars"></param> /// <returns></returns> public static decimal[] Closes(BarList chart, int bars) { return EndSlice(chart.Close(), bars); }