public RsiData GetRsiData(PlotCollectionSet dataset, int nDataIdx, int nLookahead = 0, bool bAddToParams = false) { RsiData data = Pre(dataset, nDataIdx); for (int i = 0; i < data.SrcData.Count; i++) { Process(data, i, null, nLookahead, bAddToParams); } MinMax minmax = new MinMax(); minmax.Add(0); minmax.Add(100); data.DstData.SetMinMax(minmax); return(data); }
public double Process(SmaData data, int i, MinMax minmax = null, int nLookahead = 0, bool bAddToParams = false) { bool bActive = data.SrcData[i].Active; PlotCollection dataSrc = data.SrcData; PlotCollection dataDst = data.DstData; double dfInc = data.Increment; if (bActive) { if (data.Count < m_config.Interval) { data.SMA += dataSrc[i].Y * dfInc; if (dataDst != null) { dataDst.Add(dataSrc[i].X, dataSrc[i].Y, false, dataSrc[i].Index); } } else { if (i < dataSrc.Count - nLookahead) { data.SMA = (data.SMA * (1 - dfInc)) + dataSrc[i].Y * dfInc; } if (dataDst != null) { dataDst.Add(dataSrc[i].X, data.SMA, true, dataSrc[i].Index); } if (bAddToParams) { dataSrc[i].SetParameter(dataDst.Name, (float)data.SMA); } } if (minmax != null) { minmax.Add(data.SMA); } data.Count++; } else { if (dataDst != null) { dataDst.Add(dataSrc[i].X, dataSrc[i].Y, false, dataSrc[i].Index); } } return(data.SMA); }
/// <summary> /// Initilizes default fields. /// </summary> /// <param name="inputFile">FullName of input GeoTIFF.</param> /// <param name="outputDirectory">FullName of output directory.</param> /// <param name="minZ">Minimum zoom.</param> /// <param name="maxZ">Maxmimum zoom.</param> /// <param name="resampling">Resampling method.</param> private static void Initialize(string inputFile, string outputDirectory, int minZ, int maxZ, ResampleAlg resampling) { InputFile = inputFile; OutputDirectory = outputDirectory; MinZ = minZ; MaxZ = maxZ; Resampling = resampling; QuerySize = 4 * TileSize; // Open the input file Dataset inputDataset = Gdal.Open(InputFile, Access.GA_ReadOnly); DataBandsCount = inputDataset.RasterCount; // Read the georeference double[] outGeoTransform = new double[6]; inputDataset.GetGeoTransform(outGeoTransform); OutGeoTransform = outGeoTransform; // Set x/y sizes of dataset RasterXSize = inputDataset.RasterXSize; RasterYSize = inputDataset.RasterYSize; // Dispose InputDataset inputDataset.Dispose(); // Generate dictionary with min max tile coordinates for all zoomlevels foreach (int zoom in Enumerable.Range(MinZ, MaxZ - MinZ + 1)) { double xMin = OutGeoTransform[0]; double yMin = OutGeoTransform[3] - RasterYSize * OutGeoTransform[1]; double xMax = OutGeoTransform[0] + RasterXSize * OutGeoTransform[1]; double yMax = OutGeoTransform[3]; int[] lonLatToTile = GetTileNumbersFromCoords(xMin, yMin, xMax, yMax, TileSize, zoom); int tileMinX = lonLatToTile[0]; int tileMinY = lonLatToTile[1]; int tileMaxX = lonLatToTile[2]; int tileMaxY = lonLatToTile[3]; // crop tiles extending world limits (+-180,+-90) tileMinX = Math.Max(0, tileMinX); tileMinY = Math.Max(0, tileMinY); tileMaxX = Math.Min(Convert.ToInt32(Math.Pow(2, zoom + 1)) - 1, tileMaxX); tileMaxY = Math.Min(Convert.ToInt32(Math.Pow(2, zoom)) - 1, tileMaxY); MinMax.Add(zoom, new[] { tileMinX, tileMinY, tileMaxX, tileMaxY }); } }
/// <summary> /// Updates the visibility of all items based on the ones that should be visible. /// </summary> private void UpdateScroll() { int n = components.Count; if (n > 0) { MinMax above = new MinMax(0.0f), below = new MinMax(0.0f), left = new MinMax(0.0f), right = new MinMax(0.0f); GetViewableRect(out float xl, out float xr, out float yb, out float yt); for (int i = 0; i < n; i++) { var item = components[i]; float yMin = item.min.y, xMin = item.min.x, yMax = item.max.y, xMax = item.max.x; if (forceShow.Contains(item.entry)) { // Always visible item.SetVisible(true); } else if (yMin > yt) { // Component above above.Add(yMin, yMax); item.SetVisible(false); } else if (yMax < yb) { // Component below below.Add(yMin, yMax); item.SetVisible(false); } else if (xMin > xr) { // Component to the right right.Add(xMin, xMax); item.SetVisible(false); } else if (xMax < xl) { // Component to the left left.Add(xMin, xMax); item.SetVisible(false); } else { item.SetVisible(true); } } } }
private PlotCollection getLowPoints(PlotCollection data, int nLevel, int nLookahead) { if (data == null || data.Count < 3) { return(null); } PlotCollection dataLow = new PlotCollection(data.Name + " L" + nLevel.ToString()); int nOpen = data[0].PrimaryIndexY; int nHigh = data[0].PrimaryIndexY; int nLow = data[0].PrimaryIndexY; int nClose = data[0].PrimaryIndexY; if (data[0].Y_values.Length == 4) { nHigh = 1; nLow = 2; nClose = 3; } List <Tuple <int, Plot> > rgActive = new List <Tuple <int, Plot> >(); for (int i = 0; i < data.Count - nLookahead; i++) { if (data[i].Active) { rgActive.Add(new Tuple <int, Plot>(i, data[i])); } } if (rgActive.Count < 3) { return(null); } MinMax minmax = new MinMax(); int nIdx = 1; for (int i = 0; i < data.Count; i++) { int nIdxCurrent = rgActive[nIdx].Item1; if (i == nIdxCurrent && nIdx < rgActive.Count - 1) { Plot plotCurrent = data[nIdxCurrent]; int nIdxPast = rgActive[nIdx - 1].Item1; Plot plotPast = data[nIdxPast]; int nIdxFuture = rgActive[nIdx + 1].Item1; Plot plotFuture = data[nIdxFuture]; double dfOpen = (plotCurrent.Y_values.Length == 1) ? plotCurrent.Y : plotCurrent.Y_values[nOpen]; double dfClose = (plotCurrent.Y_values.Length == 1) ? plotCurrent.Y : plotCurrent.Y_values[nClose]; double dfHigh1 = (plotCurrent.Y_values.Length == 1) ? plotCurrent.Y : plotCurrent.Y_values[nHigh]; double dfLow1 = (plotCurrent.Y_values.Length == 1) ? plotCurrent.Y : plotCurrent.Y_values[nLow]; double dfHigh0 = (plotPast.Y_values.Length == 1) ? plotPast.Y : plotPast.Y_values[nHigh]; double dfLow0 = (plotPast.Y_values.Length == 1) ? plotPast.Y : plotPast.Y_values[nLow]; double dfHigh2 = (plotFuture.Y_values.Length == 1) ? plotFuture.Y : plotFuture.Y_values[nHigh]; double dfLow2 = (plotFuture.Y_values.Length == 1) ? plotFuture.Y : plotFuture.Y_values[nLow]; bool bLow = false; if (dfLow1 < dfLow0 && dfLow1 < dfLow2) { bLow = true; } minmax.Add(dfLow1); dataLow.Add(new Plot(data[nIdxCurrent].X, dfLow1, null, bLow, data[nIdxCurrent].Index)); nIdx++; } else { double dfLow = (data[i].Y_values.Length == 1) ? data[i].Y : data[i].Y_values[nLow]; dataLow.Add(new Plot(data[i].X, dfLow, null, false, data[i].Index)); } } dataLow.SetMinMax(minmax); return(dataLow); }
public double Process(EmaData data, int i, MinMax minmax = null, int nLookahead = 0, bool bAddToParams = false) { bool bActive = data.SrcData[i].Active; PlotCollection dataSrc = data.SrcData; PlotCollection dataDst = data.DstData; double dfMult = data.Multiplier; if (i < dataSrc.Count) { if (data.Index < m_config.Interval) { if (bActive) { data.Total += dataSrc[i].Y; data.Index++; if (dataDst != null) { dataDst.Add(dataSrc[i].X, data.Total / (data.Index + 1), false, dataSrc[i].Index); } } else { if (dataDst != null) { dataDst.Add(dataSrc[i].X, dataSrc[i].Y, false, dataSrc[i].Index); } } } else { if (data.EMA == 0) { data.EMA = data.Total / m_config.Interval; } if (i < dataSrc.Count - nLookahead) { data.EMA = (dataSrc[i].Y - data.EMA) * data.Multiplier + data.EMA; } else { bActive = false; } if (dataDst != null) { dataDst.Add(data.EMA, bActive, dataSrc[i].Index); } if (bAddToParams && bActive) { dataSrc[i].SetParameter(dataDst.Name, (float)data.EMA); } if (minmax != null) { minmax.Add(data.EMA); } } } return(data.EMA); }
/// <summary> /// Calculate the BB based on Investopedia's formula. /// </summary> /// <remarks> /// @see [Bollinger Band Definition](https://www.investopedia.com/terms/b/bollingerbands.asp) /// </remarks> /// <param name="data">Specifies the BB data from the previous cycle.</param> /// <param name="i">Specifies the current data index.</param> /// <param name="minmax">Currently, not used here.</param> /// <param name="nLookahead">Specifies the look ahead value if any.</param> /// <param name="bAddToParams">Optionally, specifies whether or not to add the BB to the parameters of the original data.</param> /// <returns>The new BB values are returned.</returns> public Tuple <long, double, double, double, double, double> Process(BbData data, int i, MinMax minmax = null, int nLookahead = 0, bool bAddToParams = false) { bool bActive = data.SrcData[i].Active; Plot plot = new Plot(data.SrcData[i].X, new float[] { 0, 0, 0 }, null, false, data.SrcData[i].Index, data.SrcData[i].Action1Active, data.SrcData[i].Action2Active); data.DstData.Add(plot, false); float fTypicalValue = (data.SrcData[i].Y_values.Length == 4) ? (data.SrcData[i].Y_values[1] + data.SrcData[i].Y_values[2] + data.SrcData[i].Y_values[3]) / 3 : data.SrcData[i].Y; if (data.SrcData[i].Y_values.Length == 4 && m_target != TARGET.DEFAULT) { if (m_target == TARGET.BAR) { float fVal = (data.SrcData[i].Y_values[0] - data.SrcData[i].Y); m_caValExt.Add(fVal, null, true); } else if (m_target == TARGET.RANGE) { float fVal = (data.SrcData[i].Y_values[1] - data.SrcData[i].Y_values[2]); m_caValExt.Add(fVal, null, true); } } if (m_caVal.Add(fTypicalValue, null, false)) { data.Ave = (float)m_caVal.Average; float fStdevTp = (float)m_caVal.StdDev; if (m_target != TARGET.DEFAULT) { fStdevTp = (float)m_caValExt.StdDev; } double dfStdDvTp = (m_dfStdDev * fStdevTp); data.BbAbove = data.Ave + dfStdDvTp; data.BbBelow = data.Ave - dfStdDvTp; plot.SetYValues(new float[] { (float)data.BbBelow, (float)data.Ave, (float)data.BbAbove }, true); double dfAboveBelow = data.BbAbove - data.BbBelow; data.BbPctb = 0; if (dfAboveBelow != 0) { data.BbPctb = (data.SrcData[i].Y - data.BbBelow) / dfAboveBelow; } data.BbWid = 0; if (data.Ave != 0) { data.BbWid = dfAboveBelow / data.Ave; } if (bAddToParams && bActive) { data.SrcData[i].SetParameter(data.DstData.Name + " Below", data.BbBelow); data.SrcData[i].SetParameter(data.DstData.Name + " Ave", data.Ave); data.SrcData[i].SetParameter(data.DstData.Name + " Above", data.BbAbove); data.SrcData[i].SetParameter(data.DstData.Name + " %b", data.BbPctb); data.SrcData[i].SetParameter(data.DstData.Name + " BandWidth", data.BbWid); } if (minmax != null) { minmax.Add(data.BbBelow); minmax.Add(data.Ave); minmax.Add(data.BbAbove); } } data.Count++; return(new Tuple <long, double, double, double, double, double>((long)data.SrcData[i].X, data.BbBelow, data.Ave, data.BbAbove, data.BbPctb, data.BbWid)); }