159 lines
5.2 KiB
C#
159 lines
5.2 KiB
C#
using SignalsTest;
|
|
|
|
public static class Confirmations
|
|
{
|
|
public static int GetTWSConfirmation(List<TAReport> reports, int i)
|
|
{
|
|
int TWSHeightIncrement = 0;
|
|
|
|
if (i > 22)
|
|
{
|
|
bool hasCrossedST = false;
|
|
bool hasCrossedMA = false;
|
|
for (int z = 0; z < 20; z++)
|
|
{
|
|
if (!reports[i - z].STUp && reports[i].STUp)
|
|
{
|
|
hasCrossedST = true;
|
|
}
|
|
|
|
if (reports[i - z].SMA20 < reports[i - z].Open && reports[i].SMA20 > reports[i].Open)
|
|
{
|
|
hasCrossedMA = true;
|
|
}
|
|
}
|
|
|
|
if (hasCrossedMA) TWSHeightIncrement += 1;
|
|
if (hasCrossedST) TWSHeightIncrement += 1;
|
|
}
|
|
|
|
return TWSHeightIncrement;
|
|
}
|
|
|
|
public static float GetTBCConfirmation(List<TAReport> reports, int i)
|
|
{
|
|
float HeightIncrement = 0;
|
|
|
|
if (i > 22)
|
|
{
|
|
bool hasCrossedST = false;
|
|
bool hasCrossedMA = false;
|
|
for (int z = 0; z < 20; z++)
|
|
{
|
|
if (reports[i - z].STUp && !reports[i].STUp)
|
|
{
|
|
hasCrossedST = true;
|
|
}
|
|
|
|
if (reports[i - z].SMA20 > reports[i - z].Open && reports[i].SMA20 < reports[i].Open)
|
|
{
|
|
hasCrossedMA = true;
|
|
}
|
|
}
|
|
|
|
if (hasCrossedMA) HeightIncrement += 15;
|
|
if (hasCrossedST) HeightIncrement += 15;
|
|
}
|
|
|
|
return HeightIncrement;
|
|
}
|
|
|
|
public static List<decimal> GetSupportiveLevels(List<TAReport> reports, float tolerance = 0.1f, int steps = 5, string SMA="SMA20"){
|
|
List<decimal> allSups = 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 = decimal.Parse(Utils.GetPropByName(reports[k], SMA).ToString() ?? "0") > reports[k].candle.High;
|
|
bool MATopBefore = decimal.Parse(Utils.GetPropByName(reports[k-1], SMA).ToString() ?? "0") > 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 lowestInPeriod = 1000000;
|
|
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;
|
|
}
|
|
}
|
|
|
|
allSups.Add(lowestInPeriod);
|
|
}
|
|
|
|
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, string SMA="SMA20"){
|
|
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 = decimal.Parse(Utils.GetPropByName(reports[k], SMA).ToString() ?? "0") > reports[k].candle.High;
|
|
bool MATopBefore = decimal.Parse(Utils.GetPropByName(reports[k-1], SMA).ToString() ?? "0") > 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;
|
|
}
|
|
} |