Pine Willy(Pine pine) { var highest = TA.Highest(pine, 5); var lowest = TA.Lowest(pine, 5); return(60.0 * (pine - highest) / (highest - lowest) + 80); }
public static PineNA ValueWhen(PineNA condition, Pine source, uint occurrence = 0) { PineNA ret = new PineNA(); Queue <double> Queue = new Queue <double>(); foreach ((double?cond, double sour)tuple in ZipEnd(condition, source, (cond, sour) => (cond, sour))) { if (tuple.cond == null) { ret.Add(null); } else { Queue.Enqueue(tuple.sour); if (occurrence == 0) { ret.Add(Queue.Dequeue()); } else { ret.Add(null); occurrence--; } } } return(ret); }
public static Pine ZipEnd( Pine first, Pine second, Pine third, Pine fourth, Pine fifth, Pine sixth, Pine seventh, Pine eighth, Func <double, double, double, double, double, double, double, double, double> result) { var fR = ((IEnumerable <double>)first).Reverse(); var sR = ((IEnumerable <double>)second).Reverse(); var tR = ((IEnumerable <double>)third).Reverse(); var fH = ((IEnumerable <double>)fourth).Reverse(); var fF = ((IEnumerable <double>)fifth).Reverse(); var sX = ((IEnumerable <double>)sixth).Reverse(); var sV = ((IEnumerable <double>)seventh).Reverse(); var eG = ((IEnumerable <double>)eighth).Reverse(); var fs = fR.Zip(sR, (s1, s2) => (s1, s2)); var tf = tR.Zip(fH, (s3, s4) => (s3, s4)); var f6 = fF.Zip(sX, (s5, s6) => (s5, s6)); var sE = sV.Zip(eG, (s7, s8) => (s7, s8)); var fstf = fs.Zip(tf, (f, s) => (f.s1, f.s2, s.s3, s.s4)); var fsse = f6.Zip(sE, (f, s) => (f.s5, f.s6, s.s7, s.s8)); var ret = fstf.Zip(fsse, (f, ff) => (f.s1, f.s2, f.s3, f.s4, ff.s5, ff.s6, ff.s7, ff.s8)); return(ret.Reverse().Select(x => result(x.s1, x.s2, x.s3, x.s4, x.s5, x.s6, x.s7, x.s8)).ToPine()); }
public static Pine Linreg(Pine source, int period, int offset = 0) { Pine intercept = Intercept(source, period); Pine slope = Slope(source, period); return(intercept + slope * (period - 1 - offset)); }
public static PineNA ZipEnd(Pine first, Pine second, Func <double, double, double?> result) { var fR = ((IEnumerable <double>)first).Reverse(); var sR = ((IEnumerable <double>)second).Reverse(); var fs = fR.Zip(sR, (f, s) => (f, s)); return(fs.Reverse().Select(x => result(x.f, x.s)).ToPineNA()); }
public static Pine ToPine(this IEnumerable <double> source) { Pine ret = new Pine(); foreach (double num in source) { ret.Add(num); } return(ret); }
public static Pine operator /(double number, Pine pine) { Pine ret = new Pine(); foreach (double num in pine) { ret.Add(number / num); } return(ret); }
Pine TSIfor3min(Pine pine) {//csi = 90+91 * (ema(ema(low-low[1], 36), 2) / ema(ema(abs(low-low[1]), 36), 2)) Pine emaSrc36 = TA.Ema(pine, 36); Pine emaSrc36abs = TA.Ema(TA.Abs(pine), 36); Pine emaemaSrc36 = TA.Ema(emaSrc36, 2); Pine emaemaSrc36abs = TA.Ema(emaSrc36abs, 2); Pine ret = 90 + (91 * emaemaSrc36) / emaemaSrc36abs; return(ret); }
public static Pine operator -(Pine pine, double number) { Pine ret = new Pine(); foreach (double num in pine) { ret.Add(num - number); } return(ret); }
/// <summary>Выбирает возвращаемые значения из элементов двух последовательностей по условию в первой последовательности</summary> /// <param name="pineBool">Последовательность задающая условие выбора</param> /// <param name="pineTrue">Последовательность для True</param> /// <param name="pineFalse">Последовательность для False</param> /// <returns></returns> public static Pine IIF(PineBool pineBool, Pine pineTrue, Pine pineFalse) { var bl = ((IEnumerable <bool>)pineBool).Reverse(); var tr = ((IEnumerable <double>)pineTrue).Reverse(); var fl = ((IEnumerable <double>)pineFalse).Reverse(); var btf = bl.Zip(tr, (b, t) => (b, t)).Zip(fl, (bt, f) => (bt.b, bt.t, f)); return(btf.Reverse().Select(x => x.b ? x.t : x.f).ToPine()); }
public static Pine IIF(PineBool pineBool, double pineTrue, Pine pineFalse) { var bl = ((IEnumerable <bool>)pineBool).Reverse(); var tr = pineTrue; var fl = ((IEnumerable <double>)pineFalse).Reverse(); var bf = bl.Zip(fl, (b, f) => (b, f)); return(bf.Reverse().Select(x => x.b ? tr : x.f).ToPine()); }
public static Pine IIF(PineBool pineBool, Pine pineTrue, double pineFalse) { var bl = ((IEnumerable <bool>)pineBool).Reverse(); var tr = ((IEnumerable <double>)pineTrue).Reverse(); var fl = pineFalse; var bt = bl.Zip(tr, (b, t) => (b, t)); return(bt.Reverse().Select(x => x.b ? x.t : fl).ToPine()); }
public static Pine ZipEnd(Pine first, Pine second, Pine third, Func <double, double, double, double> result) { var fR = ((IEnumerable <double>)first).Reverse(); var sR = ((IEnumerable <double>)second).Reverse(); var tR = ((IEnumerable <double>)third).Reverse(); var fsr = fR.Zip(sR, (f, s) => (f, s)).Zip(tR, (fs, t) => (fs.f, fs.s, t)); return(fsr.Reverse().Select(x => result(x.f, x.s, x.t)).ToPine()); }
Pine Tradition(Pine pine, Pine pVolume) { var tci = TCI(pine); var mf = MF(pine, pVolume); var rsi = TA.RSI(pine, 3); OutValues.Add("tci", tci); OutValues.Add("mf", mf); OutValues.Add("rsi", rsi); return(Pine.ZipEnd(tci, mf, rsi, (t, m, r) => (t + r + m) / 3.0)); }
public static Pine ToPine_v1(this IEnumerable <decimal?> source) { Pine p = new Pine(); List <double?> boo = new List <double?>(); foreach (var item in source) { boo.Add(decimal.ToDouble((decimal)item)); } return(p); }
Pine TCI(Pine pine) { //Pine emaSrc35, src_emaSrc35, abs_src_emaSrc35, emaAbs, comm, ret; Pine emaSrc35 = TA.Ema(pine, 35); Pine src_emaSrc35 = pine - emaSrc35; Pine abs_src_emaSrc35 = TA.Abs(src_emaSrc35); Pine emaAbs = TA.Ema(abs_src_emaSrc35, 35); Pine comm = src_emaSrc35 / (0.025 * emaAbs); Pine ret = TA.Ema(comm, 5) + 50; return(ret); }
public static Pine VolumeToPine(this List <TradeBucketedDto> source) { Pine p = new Pine(); List <double?> boo = new List <double?>(); foreach (var item in source.OrderBy(x => x.Timestamp)) { boo.Add(item.Volume == null ? null : (double?)Convert.ToDouble(item.Volume));// } p = boo.ToPine(Enums.Approximation.LinearNew); return(p); }
public static Pine ZipEnd(Pine first, Pine second, Pine third, Pine fourth, Func <double, double, double, double, double> result) { var fR = ((IEnumerable <double>)first).Reverse(); var sR = ((IEnumerable <double>)second).Reverse(); var tR = ((IEnumerable <double>)third).Reverse(); var fH = ((IEnumerable <double>)fourth).Reverse(); var fs = fR.Zip(sR, (f, s) => (s1: f, s2: s)); var tf = tR.Zip(fH, (t, f4) => (s3: t, s4: f4)); var fsrf = fs.Zip(tf, (f, s) => (f.s1, f.s2, s.s3, s.s4)); return(fsrf.Reverse().Select(x => result(x.s1, x.s2, x.s3, x.s4)).ToPine()); }
Pine MF(Pine pine, Pine pVolume) { var pChange = TA.Change(pine); var chnM = TA.ZipEnd(pChange, pine, (ch, cl) => ch <= 0 ? 0 : cl).ToPine(); var sumChnM = TA.Sum(pVolume * chnM, 3); var chnL = TA.ZipEnd(pChange, pine, (ch, cl) => ch >= 0 ? 0 : cl).ToPine(); var sumChnL = TA.Sum(pVolume * chnL, 3); //mf(src) => rsi(sum(volume * (change(src) <= 0 ? 0 : src), 3), sum(volume * (change(src) >= 0 ? 0 : src), 3)) return(TA.RSI(sumChnM, sumChnL)); //var result = TradingAlgos.Alroritm(candles6, 35, 5, 3); }
public static PineBool CrossOver(Pine xSource, Pine ySource) { IEnumerable <(double x, double y)> tuples = ZipEnd(xSource, ySource, (x, y) => (x, y)); PineBool ret = new PineBool(); (double x, double y)prev = tuples.First(); ret.Add(prev.x == prev.y); tuples = tuples.Skip(1); foreach ((double x, double y)tupl in tuples) { ret.Add(tupl.x == tupl.y || (tupl.x > tupl.y && prev.x < prev.y)); prev = tupl; } return(ret); }
public static Pine Ema(Pine source, int period) { double[] emaValues = new double[source.Count]; var sourceFix = source.ToArray(); var sma = TA.Ema(0, source.Count - 1, sourceFix, period, out int outBegIdx, out int outNbElement, emaValues); if (sma == TA.RetCode.Success) { return(emaValues.Take(outNbElement).ToPine()); } throw new Exception("Could not calculate EMA!"); }
public static Pine Linreg(Pine source, int period = 14) { // int outBegIdx, outNbElement; double[] outValues = new double[source.Count]; var sourceFix = source.ToArray(); var ema = TA.LinearReg(0, source.Count - 1, sourceFix, period, out int outBegIdx, out int outNbElement, outValues); if (ema == TA.RetCode.Success) { return(outValues.Take(outNbElement).ToPine()); } throw new Exception("Could not calculate RSI!"); }
public static Pine Sma(Pine source, int period = 30) { // int outBegIdx, outNbElement; double[] smaValues = new double[source.Count]; //List<double?> outValues = new List<double?>(); var sourceFix = source.ToArray(); var sma = TA.Sma(0, source.Count - 1, sourceFix, period, out int outBegIdx, out int outNbElement, smaValues); if (sma == TA.RetCode.Success) { return(smaValues.Take(outNbElement).ToPine()); /*FixIndicatorOrderingD(smaValues.ToList(), outBegIdx, outNbElement);*/ } throw new Exception("Could not calculate SMA!"); }
public static List <(double tci, double mf, double willy)> Alroritm(List <Candle> candles, int EMA1Period, int EMA2Period, int MfPeriod) { var candlesSort = candles.OrderBy(x => x.TimeStamp).ToList(); Pine close = candlesSort.Close().ToPine(); Pine open = candlesSort.Open().ToPine(); Pine volume = candlesSort.Volume().ToPine(); Pine change = candlesSort.Select(cnd => cnd.Close - cnd.Open).ToPine(); //tci(src) => ema((src - ema(src, 35)) / (0.025 * ema(abs(src - ema(src, 35)), 35)), 5) + 50 Pine tci; { Pine emaSrc35 = Ema(close, EMA1Period); Pine src_emaSrc35 = close - emaSrc35; Pine abs_src_emaSrc35 = Abs(src_emaSrc35); tci = Ema(src_emaSrc35, EMA1Period) / (0.025 * Ema(abs_src_emaSrc35, EMA2Period)) + 50; } // mf(src) => rsi(sum(volume * (change(src) <= 0 ? 0 : src), 3), sum(volume * (change(src) >= 0 ? 0 : src), 3)) var mf = Mf(candlesSort, MfPeriod); /// willy(src) => 60 * (src - highest(src, 5)) / (highest(src, 5) - lowest(src, 5)) + 80 var willy = ZipEnd(candles.Close().Select(x => (double)x), Highest(candles.Close(), 5), Lowest(candles.Close(), 5), (c, h, l) => 60.0 * (c - h) / (h - l) + 80).ToList(); //var mfi = Mfi(candlesSort, RSIPeriod); //var rsi = RSI(candlesSort.Close(), RSIPeriod); ////csi(src) => avg(rsi(src, 3),tsi(src0,35,5)*50+50) //var csi = ZipEnd(RSI(candles.Close(), 3), TCI) //int countTrad = new int[] { tsi.Count, mfi.Count, rsi.Count }.Min(); //var tradition = ZipEnd(tsi, mfi, rsi, (t, m, r) => (t + r + m) / 3.0); //tsi.Skip(tsi.Count - countTrad).Zip(mfi.Skip(mfi.Count - countTrad), (t, m) => t + m).Zip(rsi.Skip(rsi.Count - countTrad), (r, tm) => (r + tm) / 3.0).ToList(); return(ZipEnd(tci, mf, willy, (t, m, w) => (t, m, w)).ToList()); }
public static Pine BarsSince(PineBool source) { Pine ret = new Pine(); double count = 0; foreach (bool x in source) { if (x) { count++; } else { count = 0; } ret.Add(count); } return(ret); }
public static Pine ZipEnd(Pine first, Pine second, Pine third, Pine fourth, Pine fifth, Pine sixth, Pine seventh, Func <double, double, double, double, double, double, double, double> result) { var fR = ((IEnumerable <double>)first).Reverse(); var sR = ((IEnumerable <double>)second).Reverse(); var tR = ((IEnumerable <double>)third).Reverse(); var fH = ((IEnumerable <double>)fourth).Reverse(); var fF = ((IEnumerable <double>)fifth).Reverse(); var sX = ((IEnumerable <double>)sixth).Reverse(); var sV = ((IEnumerable <double>)seventh).Reverse(); var fs = fR.Zip(sR, (s1, s2) => (s1, s2)); var tf = tR.Zip(fH, (s3, s4) => (s3, s4)); var f6 = fF.Zip(sX, (s5, s6) => (s5, s6)).Zip(sV, (f, s7) => (f.s5, f.s6, s7)); var fsrf = fs.Zip(tf, (f, s) => (f.s1, f.s2, s.s3, s.s4)).Zip(f6, (f, ff) => (f.s1, f.s2, f.s3, f.s4, ff.s5, ff.s6, ff.s7)); return(fsrf.Reverse().Select(x => result(x.s1, x.s2, x.s3, x.s4, x.s5, x.s6, x.s7)).ToPine()); }
Pine f_fractalize(Pine pine) { double minMaxFract(IEnumerable <double> segm) { int index = segm.Count() / 2; double elm = segm.ElementAt(index); IEnumerable <double> items = segm.Take(index).Concat(segm.Skip(index + 1)); if (items.Max() < elm) { return(1.0); } if (items.Min() > elm) { return(-1.0); } return(0.0); } return(pine.SplitSegments(5).Select(x => minMaxFract(x)).ToPine()); }
//public static Pine BarsSince(PineBool source) //{ // Pine ret = new Pine(); // foreach (bool x in source) // { // if (x) // count++; // else if() // else // count = 0; // ret.Add(count); // } // return ret; //} public static Pine BarsSince(PineBool source) { Pine buf = new Pine(); double count = 0; for (int i = 0; i < source.Count; i++) { if (source[i]) { count = 1; } else if (i > 0 && !source[i] && buf.ElementAt(i - 1) > 0) { count++; } else { count = 0; } buf.Add(count); } buf.Reverse(); return(buf); }
PineBool CrossOver(Pine xSource, Pine ySource) => TA.CrossOver(xSource, ySource);
Pine ValueWhen(PineNA condition, Pine source, uint occurrence) => TA.ValueWhen(condition, source, occurrence).ToPine(Enums.Approximation.Step);