diff --git a/CoinWatch.cs b/CoinWatch.cs index 0befc2e..b57ae66 100644 --- a/CoinWatch.cs +++ b/CoinWatch.cs @@ -46,7 +46,7 @@ namespace SignalsTest } } } - InitLivestream(); + // InitLivestream(); KeepUpdatingCandles(); // TestCallbacks(); } diff --git a/Confirmations.cs b/Confirmations.cs index 7cd8f07..3d5a32c 100644 --- a/Confirmations.cs +++ b/Confirmations.cs @@ -58,26 +58,26 @@ public static class Confirmations return HeightIncrement; } - public static List GetResistanceLeevls(List reports, float tolerance = 0.1f, int steps = 5){ - List allResistances = new List(); + public static List GetSupportiveLevels(List reports, float tolerance = 0.1f, int steps = 5){ + List allSups = new List(); decimal highest = 0; decimal lowest = 1000000000000000; int lastMACross = 0; for(int k =0; k < reports.Count; k++){ - if(highest < reports[k].High){ - highest = reports[k].High; + if(highest < reports[k].candle.High){ + highest = reports[k].candle.High; } - if(lowest > reports[k].Low){ - lowest = reports[k].Low; + if(lowest > reports[k].candle.Low){ + lowest = reports[k].candle.Low; } if(k reports[k].High; - bool MATopBefore = reports[k-1].SMA20 > reports[k-1].High; + bool MATopNow = reports[k].SMA20 > reports[k].candle.High; + bool MATopBefore = reports[k-1].SMA20 > reports[k-1].candle.High; bool MACrossed = MATopBefore!=MATopNow; if(!MACrossed){continue;}//No cross @@ -88,14 +88,72 @@ public static class Confirmations //Get lowest point between this and last cross decimal lowestInPeriod = 1000000; - for(int i=k; i < lastMACross; i++ ){ - if(reports[i].Low < lowestInPeriod){ - lowestInPeriod=reports[i].Low; + for(int i=lastMACross; i < k; i++ ){ + if(reports[i].candle.Low < lowestInPeriod){ + decimal candleBot = reports[i].candle.Open < reports[i].candle.Close ? reports[i].candle.Open : reports[i].candle.Close; + + lowestInPeriod=candleBot; } } - allResistances.Add(lowestInPeriod); + + allSups.Add(lowestInPeriod); } - return allResistances; + List formattedSups = new List(); + decimal range = highest-lowest; + foreach(decimal sup in allSups){ + formattedSups.Add(sup); + } + + return formattedSups; + } + + public static List GetResistanceLevels(List reports, float tolerance = 0.1f, int steps = 5){ + List allResistances = new List(); + + decimal highest = 0; + decimal lowest = 1000000000000000; + + int lastMACross = 0; + for(int k =0; k < reports.Count; k++){ + if(highest < reports[k].candle.High){ + highest = reports[k].candle.High; + } + + if(lowest > reports[k].candle.Low){ + lowest = reports[k].candle.Low; + } + + if(k reports[k].candle.High; + bool MATopBefore = reports[k-1].SMA20 > reports[k-1].candle.High; + + bool MACrossed = MATopBefore!=MATopNow; + if(!MACrossed){continue;}//No cross + if(lastMACross == 0){ + lastMACross = k; + continue; //First Cross + } + + //Get lowest point between this and last cross + decimal highestInPeriod = 0; + for(int i=lastMACross; i < k; i++ ){ + if(reports[i].candle.High > highestInPeriod){ + decimal candleTop = reports[i].candle.Open > reports[i].candle.Close ? reports[i].candle.Open : reports[i].candle.Close; + highestInPeriod=candleTop; + } + } + + allResistances.Add(highestInPeriod); + } + + List formattedResistances = new List(); + decimal range = highest-lowest; + foreach(decimal resistance in allResistances){ + formattedResistances.Add(resistance); + } + + return formattedResistances; } } \ No newline at end of file diff --git a/Picasso.cs b/Picasso.cs index 16a4ce5..26a545e 100644 --- a/Picasso.cs +++ b/Picasso.cs @@ -7,8 +7,12 @@ using SixLabors.ImageSharp.Drawing.Processing; using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.Processing; using Newtonsoft.Json; +using System.Diagnostics; public class Picasso{ + + + public static void DrawChart(List reports, decimal max, decimal min, decimal volMax, string filename="test"){ // float height = (float)Math.Ceiling(max - min) * 2f; // float width = ((float)height / 9f) * 16f; @@ -65,7 +69,7 @@ public class Picasso{ topPoints[0] = new PointF(i * widthMultiplier, highVal+squareOffset+ candlesOffset); topPoints[1] = new PointF(i * widthMultiplier, highVal+15+ candlesOffset); - #region TWS +#region TWS if(reports[i].TWS > 1){ Color TWSColor = Color.Blue; if(reports[i].TWS == 2){ @@ -79,10 +83,10 @@ public class Picasso{ TWSPoints[1]-= new PointF(0,TWSHeightIncrement); img.Mutate(ctx=>ctx.DrawLine(TWSColor, 10, TWSPoints)); - img.Mutate(ctx=>ctx.DrawLine(Color.DarkGrey , 0.5f, [new PointF(i * widthMultiplier, 0),new PointF(i * widthMultiplier, height)])); //Draw Vertical guide - + img.Mutate(ctx=>ctx.DrawLine(Color.DarkBlue , 0.5f, [new PointF(i * widthMultiplier, 0),new PointF(i * widthMultiplier, height)])); //Draw Vertical guide } - #endregion +#endregion + #region TBC if(reports[i].TBC > 1){ Color TBCColor = Color.Red; @@ -97,10 +101,9 @@ public class Picasso{ TBCPoints[1]+= new PointF(0,TBCHeightIncremenet); img.Mutate(ctx=>ctx.DrawLine(TBCColor, 10, TBCPoints)); - img.Mutate(ctx=>ctx.DrawLine(Color.DarkGrey , 0.5f, [new PointF(i * widthMultiplier, 0),new PointF(i * widthMultiplier, height)])); //Draw Vertical guide + img.Mutate(ctx=>ctx.DrawLine(Color.DarkBlue , 0.5f, [new PointF(i * widthMultiplier, 0),new PointF(i * widthMultiplier, height)])); //Draw Vertical guide } #endregion - } // Console.WriteLine("Getting paths"); // object t = GetPropByName(reports[reports.Count- 1], "SMA7"); @@ -121,6 +124,22 @@ public class Picasso{ #endregion + #region LINES + List resistancePoints = Confirmations.GetResistanceLevels(reports); + foreach(decimal point in resistancePoints){ + float yVal = ((float)(point-min) * heightMultiplier) + candlesOffset; + Console.WriteLine($"{filename} res at {yVal/height}"); + img.Mutate(ctx=> ctx.DrawLine(Color.Red,1f, [new PointF(0, yVal), new PointF(width, yVal)])); + } + + List supPoints = Confirmations.GetSupportiveLevels(reports); + foreach(decimal point in supPoints){ + float yVal = ((float)(point-min) * heightMultiplier) + candlesOffset; + Console.WriteLine($"{filename} sup at {yVal/height}"); + img.Mutate(ctx=> ctx.DrawLine(Color.Green,1f, [new PointF(0, yVal), new PointF(width, yVal)])); + } + #endregion + #region OVERLAY LINES //Overlay - Candles