This commit is contained in:
kyh
2022-06-08 21:08:40 +09:00

View File

@@ -1,4 +1,5 @@
using System;
using Million.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.RightsManagement;
@@ -44,5 +45,113 @@ namespace Million.IndicatorConditionSetup
};
return clone;
}
}
public override string GetKeyName(bool IndexStr = false)
{
var key = "PSAR" + IncrementValue + MaxiumValue;
if (IndexStr)
return IndexString + key;
return key;
}
public override void excute(List<CandleData> data)
{
//3개 이하는 처리 하지 않음
if (data.Count <= 3)
return;
var key = GetKeyName();
var parabolicSars = new double[data.Count];
var trendFlip = new bool[data.Count];
int trend = (data[1].HighValue >= data[0].HighValue || data[0].LowValue <= data[1].LowValue) ? +1 : -1;
double parabolicSar = (trend > 0) ? data[0].LowValue : data[0].HighValue;
double extremePoint = (trend > 0) ? data[0].HighValue : data[0].LowValue;
double accelerationFactor = 0;
var accelerationMax = MaxiumValue;
var acceleration = IncrementValue;
parabolicSars[1] = parabolicSar; // SAR Results
data[1].IndicatorDic[key].value = trend;
for (int i = 1; i < data.Count -1; i++) {
double nextSar;
// Up Trend if trend is bigger then 0 else it's a down trend
if (trend > 0)
{
// Higher highs, accelerate
if (data[i].HighValue > extremePoint)
{
extremePoint = data[i].HighValue;
accelerationFactor = Math.Min(accelerationMax, accelerationFactor + acceleration);
}
// Next Parabolic SAR based on today's close/price value
nextSar = parabolicSar + accelerationFactor * (extremePoint - parabolicSar);
// Rule: Parabolic SAR can not be above prior period's low or
// the current low.
nextSar = (i > 0) ? Math.Min(Math.Min(data[i].LowValue, data[i-1].LowValue), nextSar) : Math.Min(data[i].LowValue, nextSar);
// Rule: If Parabolic SAR crosses tomorrow's price range, the
// trend switches.
if (nextSar > data[i+1].LowValue)
{
trend = -1;
nextSar = extremePoint;
extremePoint = data[i+1].LowValue;
accelerationFactor = acceleration;
}
}
else
{
// Making lower lows: accelerate
if (data[i].LowValue < extremePoint)
{
extremePoint = data[i].LowValue;
accelerationFactor = Math.Min(accelerationMax, accelerationFactor + acceleration);
}
// Next Parabolic SAR based on today's close/price value
nextSar = parabolicSar + accelerationFactor * (extremePoint - parabolicSar);
// Rule: Parabolic SAR can not be below prior period's high or
// the current high.
nextSar = (i > 0) ? Math.Max(Math.Max(data[i].HighValue, data[i-1].HighValue), nextSar) : Math.Max(data[i].HighValue, nextSar);
// Rule: If Parabolic SAR crosses tomorrow's price range, the
// trend switches.
if (nextSar < data[i+1].HighValue)
{
trend = +1;
nextSar = extremePoint;
extremePoint = data[i+1].HighValue;
accelerationFactor = acceleration;
}
}
// System.out.println(extremePoint + " " + accelerationFactor);
///data[i+1].IndicatorDic[key]
//data[i + 1].IndicatorDic[key].value = Math.Round(nextSar);
parabolicSars[i + 1] = nextSar;
data[i + 1].IndicatorDic[key].value = trend;
if (data[i].IndicatorDic[key].value != data[i + 1].IndicatorDic[key].value)
{
trendFlip[i + 1] = true;
}
else
{
trendFlip[i + 1] = false;
}
parabolicSar = nextSar;
}
}
}
}