This commit is contained in:
2025-01-05 18:58:43 +05:30
parent 5cd509161b
commit e1c55dbce6
68 changed files with 2253 additions and 212 deletions

View File

@@ -24,7 +24,7 @@ namespace SignalsTest
public decimal SMA25;
public decimal SMA99;
public decimal EMA7,EMA25, EMA99;
public decimal EMA7, EMA25, EMA99;
public decimal MACD = 0;
public decimal EMACD = 0;
@@ -37,11 +37,11 @@ namespace SignalsTest
public decimal STLow;
public decimal ST;
public decimal RSI=0;
public decimal RSI = 0;
public bool STUp => STHigh > Close;
public bool STUp = false;
public static TAReport Generate(string _pair, int _interval,List<KlineCandleStickResponse> response, int index, List<TAReport> history)
public static TAReport Generate(string _pair, int _interval, List<KlineCandleStickResponse> response, int index, List<TAReport> history)
{
TAReport report = new TAReport();
report.pair = _pair;
@@ -61,18 +61,19 @@ namespace SignalsTest
// {
// report.SMAs.Add(ema, Indicators.getEMA(response, index, 0, ema));
// }
report.SMA7 = Indicators.getSMA(response, index,7);
report.SMA25 = Indicators.getSMA(response, index,25);
report.SMA99 = Indicators.getSMA(response, index,99);
report.SMA7 = Indicators.getSMA(response, index, 7);
report.SMA25 = Indicators.getSMA(response, index, 25);
report.SMA99 = Indicators.getSMA(response, index, 99);
report.EMA7 = Indicators.getEMA(response, index,0, 7);
report.EMA25 = Indicators.getEMA(response, index,0,25);
report.EMA99 = Indicators.getEMA(response, index,0,99);
report.EMA7 = Indicators.getEMA(response, index, 0, 7);
report.EMA25 = Indicators.getEMA(response, index, 0, 25);
report.EMA99 = Indicators.getEMA(response, index, 0, 99);
report.MACD = Indicators.getMACD(response, 12, 26, index);
report.RSI = Indicators.getRSI(response,index);
report.RSI = Indicators.getRSI(response, index);
if(history == null){
if (history == null)
{
return report;
}
//MACD Signal
@@ -80,48 +81,61 @@ namespace SignalsTest
List<decimal> ATR10History = new List<decimal>();
List<decimal> ATR14History = new List<decimal>();
foreach(TAReport item in history){
foreach (TAReport item in history)
{
MACDHistory.Add(item.MACD);
ATR10History.Add(item.ATR10);
ATR14History.Add(item.ATR14);
}
report.EMACD = Indicators.getEMA(MACDHistory, index,0,9);
report.ATR10 = Indicators.getATR(response, 10,index, ATR10History);
report.ATR14 = Indicators.getATR(response, 14,index, ATR14History);
report.EMACD = Indicators.getEMA(MACDHistory, index, 0, 9);
report.ATR10 = Indicators.getATR(response, 10, index, ATR10History);
report.ATR14 = Indicators.getATR(response, 14, index, ATR14History);
//SuperTrend
decimal SuperTrendUpper = (response[index].High + response[index].Low) / 2 + 3 * report.ATR10;
decimal SuperTrendLower = (response[index].High + response[index].Low) / 2 - 3 * report.ATR10;
decimal SuperTrendFinal = 0;
// SuperTrend Multiplier
decimal multiplier = 3;
// Basic Upper and Lower Bands
decimal basicUpperBand = (response[index].High + response[index].Low) / 2 + multiplier * report.ATR14;
decimal basicLowerBand = (response[index].High + response[index].Low) / 2 - multiplier * report.ATR10;
// Initialize Final Upper and Lower Bands
decimal finalUpperBand = basicUpperBand;
decimal finalLowerBand = basicLowerBand;
// Adjust Final Upper and Lower Bands based on previous history
if (index > 0)
{
finalUpperBand = (history[index - 1].Close <= history[index - 1].STHigh)
? Math.Min(basicUpperBand, history[index - 1].STHigh)
: basicUpperBand;
finalLowerBand = (history[index - 1].Close >= history[index - 1].STLow)
? Math.Max(basicLowerBand, history[index - 1].STLow)
: basicLowerBand;
}
bool currentTrendUp = true;
if (index > 0)
{
if (history[index - 1].STHigh > SuperTrendUpper || history[index - 1].Close > history[index - 1].STHigh)
if (history[index - 1].STUp) // If the previous trend was up
{
currentTrendUp = (response[index].Close > finalLowerBand); // Price > Final Lower Band => Stay up
}
else
else // If the previous trend was down
{
SuperTrendUpper = history[index - 1].STHigh;
}
if (history[index - 1].STLow < SuperTrendLower || history[index - 1].Close < history[index - 1].STLow)
{
}
else
{
SuperTrendLower = history[index - 1].STLow;
currentTrendUp = (response[index].Close >= finalUpperBand); // Price >= Final Upper Band => Flip to up
}
}
SuperTrendFinal = report.STUp ? SuperTrendLower : SuperTrendUpper;
report.ST = SuperTrendFinal;
// Assign SuperTrend values to the report
report.STHigh = finalUpperBand;
report.STLow = finalLowerBand;
report.STUp = currentTrendUp;
report.ST = currentTrendUp ? finalLowerBand : finalUpperBand;
return report;
}