sup res lines

This commit is contained in:
Sewmina 2025-01-14 11:18:57 +05:30
parent 077c1d21fc
commit 1e4fcc678a
3 changed files with 97 additions and 20 deletions

View File

@ -46,7 +46,7 @@ namespace SignalsTest
} }
} }
} }
InitLivestream(); // InitLivestream();
KeepUpdatingCandles(); KeepUpdatingCandles();
// TestCallbacks(); // TestCallbacks();
} }

View File

@ -58,26 +58,26 @@ public static class Confirmations
return HeightIncrement; return HeightIncrement;
} }
public static List<decimal> GetResistanceLeevls(List<TAReport> reports, float tolerance = 0.1f, int steps = 5){ public static List<decimal> GetSupportiveLevels(List<TAReport> reports, float tolerance = 0.1f, int steps = 5){
List<decimal> allResistances = new List<decimal>(); List<decimal> allSups = new List<decimal>();
decimal highest = 0; decimal highest = 0;
decimal lowest = 1000000000000000; decimal lowest = 1000000000000000;
int lastMACross = 0; int lastMACross = 0;
for(int k =0; k < reports.Count; k++){ for(int k =0; k < reports.Count; k++){
if(highest < reports[k].High){ if(highest < reports[k].candle.High){
highest = reports[k].High; highest = reports[k].candle.High;
} }
if(lowest > reports[k].Low){ if(lowest > reports[k].candle.Low){
lowest = reports[k].Low; lowest = reports[k].candle.Low;
} }
if(k <steps * 3){continue;} //not enough history if(k <steps * 3){continue;} //not enough history
bool MATopNow = reports[k].SMA20 > reports[k].High; bool MATopNow = reports[k].SMA20 > reports[k].candle.High;
bool MATopBefore = reports[k-1].SMA20 > reports[k-1].High; bool MATopBefore = reports[k-1].SMA20 > reports[k-1].candle.High;
bool MACrossed = MATopBefore!=MATopNow; bool MACrossed = MATopBefore!=MATopNow;
if(!MACrossed){continue;}//No cross if(!MACrossed){continue;}//No cross
@ -88,14 +88,72 @@ public static class Confirmations
//Get lowest point between this and last cross //Get lowest point between this and last cross
decimal lowestInPeriod = 1000000; decimal lowestInPeriod = 1000000;
for(int i=k; i < lastMACross; i++ ){ for(int i=lastMACross; i < k; i++ ){
if(reports[i].Low < lowestInPeriod){ if(reports[i].candle.Low < lowestInPeriod){
lowestInPeriod=reports[i].Low; 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<decimal> formattedSups = new List<decimal>();
decimal range = highest-lowest;
foreach(decimal sup in allSups){
formattedSups.Add(sup);
}
return formattedSups;
}
public static List<decimal> GetResistanceLevels(List<TAReport> reports, float tolerance = 0.1f, int steps = 5){
List<decimal> allResistances = new List<decimal>();
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 <steps * 3){continue;} //not enough history
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
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<decimal> formattedResistances = new List<decimal>();
decimal range = highest-lowest;
foreach(decimal resistance in allResistances){
formattedResistances.Add(resistance);
}
return formattedResistances;
} }
} }

View File

@ -7,8 +7,12 @@ using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing; using SixLabors.ImageSharp.Processing;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Diagnostics;
public class Picasso{ public class Picasso{
public static void DrawChart(List<TAReport> reports, decimal max, decimal min, decimal volMax, string filename="test"){ public static void DrawChart(List<TAReport> reports, decimal max, decimal min, decimal volMax, string filename="test"){
// float height = (float)Math.Ceiling(max - min) * 2f; // float height = (float)Math.Ceiling(max - min) * 2f;
// float width = ((float)height / 9f) * 16f; // float width = ((float)height / 9f) * 16f;
@ -65,7 +69,7 @@ public class Picasso{
topPoints[0] = new PointF(i * widthMultiplier, highVal+squareOffset+ candlesOffset); topPoints[0] = new PointF(i * widthMultiplier, highVal+squareOffset+ candlesOffset);
topPoints[1] = new PointF(i * widthMultiplier, highVal+15+ candlesOffset); topPoints[1] = new PointF(i * widthMultiplier, highVal+15+ candlesOffset);
#region TWS #region TWS
if(reports[i].TWS > 1){ if(reports[i].TWS > 1){
Color TWSColor = Color.Blue; Color TWSColor = Color.Blue;
if(reports[i].TWS == 2){ if(reports[i].TWS == 2){
@ -79,10 +83,10 @@ public class Picasso{
TWSPoints[1]-= new PointF(0,TWSHeightIncrement); TWSPoints[1]-= new PointF(0,TWSHeightIncrement);
img.Mutate(ctx=>ctx.DrawLine(TWSColor, 10, TWSPoints)); 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 #region TBC
if(reports[i].TBC > 1){ if(reports[i].TBC > 1){
Color TBCColor = Color.Red; Color TBCColor = Color.Red;
@ -97,10 +101,9 @@ public class Picasso{
TBCPoints[1]+= new PointF(0,TBCHeightIncremenet); TBCPoints[1]+= new PointF(0,TBCHeightIncremenet);
img.Mutate(ctx=>ctx.DrawLine(TBCColor, 10, TBCPoints)); 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 #endregion
} }
// Console.WriteLine("Getting paths"); // Console.WriteLine("Getting paths");
// object t = GetPropByName(reports[reports.Count- 1], "SMA7"); // object t = GetPropByName(reports[reports.Count- 1], "SMA7");
@ -121,6 +124,22 @@ public class Picasso{
#endregion #endregion
#region LINES
List<decimal> 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<decimal> 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 #region OVERLAY LINES
//Overlay - Candles //Overlay - Candles