- 5MA 상승 시점에 매수, 5MA 하락 시점에 매도
- 검증
This commit is contained in:
162
MainForm.cs
162
MainForm.cs
@@ -3,6 +3,7 @@ using System.Windows.Forms;
|
||||
using System.Collections;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace upper_limit_crawler
|
||||
{
|
||||
@@ -257,27 +258,52 @@ namespace upper_limit_crawler
|
||||
Console.WriteLine("StockCur : {0} / {1}", time, time2);
|
||||
}
|
||||
|
||||
struct chart_data
|
||||
{
|
||||
public chart_data(int iTime, int iPrice)
|
||||
{
|
||||
this.iTime = iTime;
|
||||
this.iPrice = iPrice;
|
||||
}
|
||||
|
||||
public int iTime;
|
||||
public int iPrice;
|
||||
|
||||
override public string ToString() { return string.Format("[{0]] {{1}}", iTime, iPrice); }
|
||||
}
|
||||
|
||||
|
||||
private void btMATest_Click(object sender, EventArgs e)
|
||||
{
|
||||
string strCode = "A010240";
|
||||
string strCodeName = "흥국";
|
||||
string strDate = "20160725";
|
||||
string strPrevDate = "20160722";
|
||||
|
||||
List<chart_data> DataList = new List<chart_data>();
|
||||
|
||||
|
||||
CPSYSDIBLib.StockChart stockChart = new CPSYSDIBLib.StockChart();
|
||||
|
||||
stockChart.SetInputValue(0, strCode);
|
||||
stockChart.SetInputValue(1, '1');
|
||||
stockChart.SetInputValue(2, "20160725");
|
||||
stockChart.SetInputValue(3, "20160725");
|
||||
stockChart.SetInputValue(5, new int[] { 0, 1, 2, 3, 4, 5, 6, 10 });
|
||||
stockChart.SetInputValue(2, strPrevDate);
|
||||
stockChart.SetInputValue(3, strPrevDate);
|
||||
stockChart.SetInputValue(4, 1);
|
||||
stockChart.SetInputValue(5, new int[] { 0, 1, 2, 3, 4, 5, 6, 10, 37 });
|
||||
stockChart.SetInputValue(6, 'T');
|
||||
stockChart.BlockRequest2(1);
|
||||
int iTimeTest = (int)stockChart.GetDataValue(1, 0);
|
||||
int iPrevClosing = stockChart.GetDataValue(5, 0);
|
||||
|
||||
|
||||
ULWatchItem item = new ULWatchItem();
|
||||
item.m_strCode = strCode;
|
||||
item.m_strCodeName = "흥국";
|
||||
item.m_iCurPrice = 0;
|
||||
item.m_iPrevClosing = 0;
|
||||
|
||||
ULBalanceDlg.OWN_ITEM OwnItem = new ULBalanceDlg.OWN_ITEM();
|
||||
stockChart.SetInputValue(0, strCode);
|
||||
stockChart.SetInputValue(1, '1');
|
||||
stockChart.SetInputValue(2, strDate);
|
||||
stockChart.SetInputValue(3, strDate);
|
||||
stockChart.SetInputValue(4, 0);
|
||||
stockChart.SetInputValue(5, new int[] { 0, 1, 2, 3, 4, 5, 6, 10, 37 });
|
||||
stockChart.SetInputValue(6, 'T');
|
||||
stockChart.BlockRequest2(1);
|
||||
|
||||
int iFieldCnt = stockChart.GetHeaderValue(1);
|
||||
string[] astrFieldName = stockChart.GetHeaderValue(2);
|
||||
@@ -285,47 +311,83 @@ namespace upper_limit_crawler
|
||||
while (true)
|
||||
{
|
||||
int iCnt = (int)stockChart.GetHeaderValue(3);
|
||||
for (int i = iCnt - 1; i >= 0; i--)
|
||||
for (int i = 0; i < iCnt; i++)
|
||||
{
|
||||
int iTime = (int)stockChart.GetDataValue(1, i);
|
||||
iTime *= 100;
|
||||
|
||||
int iPrice = (int)stockChart.GetDataValue(5, i);
|
||||
int iCurPrice = (int)stockChart.GetDataValue(5, i);
|
||||
int iVolume = (int)stockChart.GetDataValue(5, i);
|
||||
|
||||
if (item.m_iPrevClosing == 0)
|
||||
item.m_iPrevClosing = (int)stockChart.GetHeaderValue(6);
|
||||
DataList.Add(new chart_data(iTime, iCurPrice));
|
||||
}
|
||||
|
||||
item.m_iCurPrice = iPrice;
|
||||
item.InsertPriceNode(iTime, iPrice);
|
||||
if (stockChart.Continue == 1)
|
||||
stockChart.BlockRequest2(1);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
float fCompRate = item.m_iCurPrice / (float)item.m_iPrevClosing - 1.0f;
|
||||
if (fCompRate >= m_DataMgr.m_Setting.m_fBidMin && fCompRate <= m_DataMgr.m_Setting.m_fBidMax)
|
||||
|
||||
|
||||
|
||||
ULWatchItem item = new ULWatchItem();
|
||||
item.m_strCode = strCode;
|
||||
item.m_strCodeName = strCodeName;
|
||||
item.m_iCurPrice = 0;
|
||||
item.m_iPrevClosing = 0;
|
||||
|
||||
ULBalanceDlg.OWN_ITEM OwnItem = new ULBalanceDlg.OWN_ITEM();
|
||||
|
||||
DataList.Reverse();
|
||||
foreach (chart_data data in DataList)
|
||||
{
|
||||
int iTime = data.iTime;
|
||||
int iCurPrice = data.iPrice;
|
||||
|
||||
if (item.m_iPrevClosing == 0)
|
||||
item.m_iPrevClosing = iPrevClosing;
|
||||
|
||||
item.m_iCurPrice = iCurPrice;
|
||||
item.InsertPriceNode(iTime, iCurPrice);
|
||||
|
||||
if(OwnItem.m_iUnitBEP != 0)
|
||||
OwnItem.m_iMaxPrice = Math.Max(OwnItem.m_iMaxPrice, iCurPrice);
|
||||
|
||||
float fCompRate = item.m_iCurPrice / (float)item.m_iPrevClosing - 1.0f;
|
||||
if (fCompRate >= m_DataMgr.m_Setting.m_fBidMin && fCompRate <= m_DataMgr.m_Setting.m_fBidMax)
|
||||
{
|
||||
if (m_DataMgr.IsInBlackList(iTime, strCode) == true)
|
||||
{
|
||||
if (item.Is5MAGoingUp() == false)
|
||||
{
|
||||
//UlUtil.Trace(string.Format("[{0}] 조건 매수 실패. 5ma 상승하지 않음 {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m_DataMgr.IsInBlackList(iTime, strCode) == true)
|
||||
{
|
||||
//UlUtil.Trace(string.Format("[{0}] 조건 매수 실패. black list {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
continue;
|
||||
}
|
||||
|
||||
// bid and add to black list
|
||||
UlUtil.Trace(string.Format("[{0}] 조건 매수 {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
|
||||
//m_DataMgr.GetTrader().Buy(strCode, item.m_iCurPrice, (int)m_DataMgr.m_Setting.m_fBidAmount);
|
||||
m_DataMgr.AddBlackList(iTime, strCode);
|
||||
//UlUtil.Trace(string.Format("[{0}] 조건 매수 실패. black list {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// loss cut
|
||||
if (iPrice <= OwnItem.m_iUnitBEP * (1.0f - m_DataMgr.m_Setting.m_fLossCut))
|
||||
float f5MASlope = item.GetPrev5MASlope(iTime);
|
||||
if (f5MASlope <= 0)
|
||||
{
|
||||
UlUtil.Trace(string.Format("[{0}] 손절 {1}원 ({2})", OwnItem.m_strCodeName, iCurPrice, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%")));
|
||||
//UlUtil.Trace(string.Format("[{0}] 조건 매수 실패. 5ma 상승하지 않음 {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
continue;
|
||||
}
|
||||
|
||||
// bid and add to black list
|
||||
Console.WriteLine(string.Format("[{0}] [{1}] 조건 매수 {2}원 ({3}) (5MA slop:{4:0.00})", iTime, item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%"), f5MASlope));
|
||||
OwnItem.m_iUnitBEP = iCurPrice;
|
||||
OwnItem.m_strCodeName = item.m_strCodeName;
|
||||
|
||||
//m_DataMgr.GetTrader().Buy(strCode, item.m_iCurPrice, (int)m_DataMgr.m_Setting.m_fBidAmount);
|
||||
m_DataMgr.AddBlackList(iTime, strCode);
|
||||
}
|
||||
|
||||
|
||||
if(OwnItem.m_iUnitBEP > 0)
|
||||
{
|
||||
// loss cut
|
||||
if (iCurPrice <= OwnItem.m_iUnitBEP * (1.0f - m_DataMgr.m_Setting.m_fLossCut))
|
||||
{
|
||||
Console.WriteLine(string.Format("[{0}] [{1}] 손절 {2}원 ({3}:{4})", iTime, OwnItem.m_strCodeName, iCurPrice, iCurPrice - OwnItem.m_iUnitBEP, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%")));
|
||||
OwnItem.m_iUnitBEP = 0;
|
||||
|
||||
//m_DataMgr.GetTrader().SellCurPrice(OwnItem.m_strCode, OwnItem.m_iPayBalance);
|
||||
//m_OwnList.Remove(OwnItem);
|
||||
//m_DataMgr.RemoveWatch(strCode);
|
||||
@@ -335,28 +397,28 @@ namespace upper_limit_crawler
|
||||
// 미체결 잔량 취소
|
||||
}
|
||||
// trailing
|
||||
else if (iPrice <= OwnItem.m_iMaxPrice - OwnItem.m_iUnitBEP * m_DataMgr.m_Setting.m_fTrailing)
|
||||
else if (iCurPrice <= OwnItem.m_iMaxPrice - OwnItem.m_iUnitBEP * m_DataMgr.m_Setting.m_fTrailing)
|
||||
{
|
||||
if (WatchItem.Is5MAGoingUp() == true)
|
||||
float f5MASlope = item.GetPrev5MASlope(iTime);
|
||||
if (f5MASlope > 0)
|
||||
{
|
||||
UlUtil.Trace(string.Format("[{0}] 트레일링 매도 대기. 5ma 상승 중 {1}원 ({2})", OwnItem.m_strCodeName, iCurPrice, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%")));
|
||||
//Console.WriteLine(string.Format("[{0}] [{1}] 트레일링 매도 대기. 5ma 상승 중 {2}원 ({3})", iTime, OwnItem.m_strCodeName, iCurPrice, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%")));
|
||||
continue;
|
||||
}
|
||||
|
||||
UlUtil.Trace(string.Format("[{0}] 트레일링 매도 {1}원 ({2})", OwnItem.m_strCodeName, iCurPrice, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%")));
|
||||
Console.WriteLine(string.Format("[{0}] [{1}] 트레일링 매도 {2}원 ({3}:{4}) (5MA slop:{5:0.00})", iTime, OwnItem.m_strCodeName, iCurPrice, iCurPrice- OwnItem.m_iUnitBEP, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%"), f5MASlope));
|
||||
OwnItem.m_iUnitBEP = 0;
|
||||
|
||||
//m_DataMgr.GetTrader().SellCurPrice(OwnItem.m_strCode, OwnItem.m_iPayBalance);
|
||||
//m_OwnList.Remove(OwnItem);
|
||||
//m_DataMgr.RemoveWatch(strCode);
|
||||
}
|
||||
}
|
||||
|
||||
if (stockChart.Continue == 1)
|
||||
stockChart.BlockRequest2(1);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
item.PrintChart();
|
||||
|
||||
//item.PrintChart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,13 +212,21 @@ namespace upper_limit_crawler
|
||||
// trailing
|
||||
else if (iCurPrice <= OwnItem.m_iMaxPrice - OwnItem.m_iUnitBEP * m_DataMgr.m_Setting.m_fTrailing)
|
||||
{
|
||||
if (WatchItem.Is5MAGoingUp() == true)
|
||||
int iTime = UlUtil.GetCurTimeInt();
|
||||
float f5MASlope = WatchItem.GetPrev5MASlope(iTime);
|
||||
if (f5MASlope > 0)
|
||||
{
|
||||
UlUtil.Trace(string.Format("[{0}] 트레일링 매도 대기. 5ma 상승 중 {1}원 ({2})", OwnItem.m_strCodeName, iCurPrice, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%")));
|
||||
//Console.WriteLine(string.Format("[{0}] [{1}] 트레일링 매도 대기. 5ma 상승 중 {2}원 ({3})", iTime, OwnItem.m_strCodeName, iCurPrice, (iCurPrice / (float)OwnItem.m_iUnitBEP - 1.0f).ToString("0.00%")));
|
||||
continue;
|
||||
}
|
||||
|
||||
UlUtil.Trace(string.Format("[{0}] 트레일링 매도 {1}원 ({2})", OwnItem.m_strCodeName, iCurPrice, (iCurPrice/(float)OwnItem.m_iUnitBEP-1.0f).ToString("0.00%")));
|
||||
UlUtil.Trace(string.Format("[{0}] 트레일링 매도 {1}원 ({2}:{3}) (5MA slop:{4:0.00})",
|
||||
OwnItem.m_strCodeName,
|
||||
iCurPrice,
|
||||
iCurPrice - OwnItem.m_iUnitBEP,
|
||||
(iCurPrice/(float)OwnItem.m_iUnitBEP-1.0f).ToString("0.00%"),
|
||||
f5MASlope));
|
||||
|
||||
m_DataMgr.GetTrader().SellCurPrice(OwnItem.m_strCode, OwnItem.m_iPayBalance);
|
||||
m_OwnList.Remove(OwnItem);
|
||||
m_DataMgr.RemoveWatch(strCode);
|
||||
|
||||
@@ -159,24 +159,28 @@ namespace upper_limit_crawler
|
||||
|
||||
if (fCompRate >= m_DataMgr.m_Setting.m_fBidMin && fCompRate <= m_DataMgr.m_Setting.m_fBidMax)
|
||||
{
|
||||
if(item.Is5MAGoingUp() == false)
|
||||
int iTime = UlUtil.GetCurTimeInt();
|
||||
if (m_DataMgr.IsInBlackList(iTime, strCode) == true)
|
||||
{
|
||||
UlUtil.Trace(string.Format("[{0}] 조건 매수 실패. 5ma 상승하지 않음 {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
//UlUtil.Trace(string.Format("[{0}] 조건 매수 실패. black list {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
continue;
|
||||
}
|
||||
|
||||
int iCurTime = int.Parse(UlUtil.GetCurTime().ToString("HHmmss"));
|
||||
if (m_DataMgr.IsInBlackList(iCurTime, strCode) == true)
|
||||
float f5MASlope = item.GetPrev5MASlope(iTime);
|
||||
if (f5MASlope <= 0)
|
||||
{
|
||||
UlUtil.Trace(string.Format("[{0}] 조건 매수 실패. black list {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
//UlUtil.Trace(string.Format("[{0}] 조건 매수 실패. 5ma 상승하지 않음 {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
continue;
|
||||
}
|
||||
|
||||
// bid and add to black list
|
||||
UlUtil.Trace(string.Format("[{0}] 조건 매수 {1}원 ({2})", item.m_strCodeName, item.m_iCurPrice, fCompRate.ToString("0.00%")));
|
||||
UlUtil.Trace(string.Format("[{0}] 조건 매수 {1}원 ({2}) (5MA slop:{3:0.00})",
|
||||
item.m_strCodeName,
|
||||
item.m_iCurPrice,
|
||||
fCompRate.ToString("0.00%"),
|
||||
f5MASlope));
|
||||
|
||||
m_DataMgr.GetTrader().Buy(strCode, item.m_iCurPrice, (int)m_DataMgr.m_Setting.m_fBidAmount);
|
||||
int iTime = int.Parse(UlUtil.GetCurTime().ToString("HHmmss"));
|
||||
m_DataMgr.AddBlackList(iTime, strCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,13 +271,25 @@ namespace upper_limit_crawler
|
||||
CandleTick node1Min = m_1MinChart.Values[i];
|
||||
MATick node5MA = m_5MAChart.ContainsKey(iKey) ? m_5MAChart[iKey] : null;
|
||||
|
||||
sb.AppendFormat("{0:######} : {1:###,###,###} ({2:###,##0.###})\n", iKey, node1Min.m_iEnd, node5MA != null ? node5MA.m_fMA : 0);
|
||||
sb.AppendFormat("{0:######} : Price : {1:###,###,###} (5MA : {2:###,##0.###})\n", iKey, node1Min.m_iEnd, node5MA != null ? node5MA.m_fMA : 0);
|
||||
}
|
||||
|
||||
sb.AppendLine("======= END =======");
|
||||
Console.WriteLine(sb.ToString());
|
||||
}
|
||||
|
||||
public float GetPrev5MASlope(int iTime)
|
||||
{
|
||||
int iKey = (iTime / 100) * 100 - 100;
|
||||
int iPrevKey = iKey - 100;
|
||||
if (m_5MAChart.ContainsKey(iKey) == false || m_5MAChart.ContainsKey(iPrevKey) == false)
|
||||
return 0;
|
||||
|
||||
MATick lastMA = m_5MAChart[iKey];
|
||||
MATick prevMA = m_5MAChart[iPrevKey];
|
||||
return lastMA.m_fMA - prevMA.m_fMA;
|
||||
}
|
||||
|
||||
public bool Is5MAGoingUp()
|
||||
{
|
||||
if(m_5MAChart.Values.Count >= 2)
|
||||
@@ -287,7 +299,7 @@ namespace upper_limit_crawler
|
||||
|
||||
if (lastMA.m_fMA > prevMA.m_fMA)
|
||||
{
|
||||
UlUtil.Trace(string.Format("[Is5MAGoingUp][{0}] ma up ({1}, {2}", m_strCodeName, lastMA.m_fMA, prevMA.m_fMA));
|
||||
//UlUtil.Trace(string.Format("[Is5MAGoingUp][{0}] ma up ({1}, {2}", m_strCodeName, lastMA.m_fMA, prevMA.m_fMA));
|
||||
return true;
|
||||
}
|
||||
else if(lastMA.m_fMA == 0)
|
||||
@@ -299,7 +311,7 @@ namespace upper_limit_crawler
|
||||
|
||||
if (lastTick.m_iEnd > prevTick.m_iEnd)
|
||||
{
|
||||
UlUtil.Trace(string.Format("[Is5MAGoingUp][{0}] cur up ({1}, {2}", m_strCodeName, lastTick.m_iEnd, prevTick.m_iEnd));
|
||||
//UlUtil.Trace(string.Format("[Is5MAGoingUp][{0}] cur up ({1}, {2}", m_strCodeName, lastTick.m_iEnd, prevTick.m_iEnd));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user