1 Star 0 Fork 43

开发/ChanlunX

forked from mywildquant/ChanlunX 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Bi.cpp 17.76 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690
#include "BaoHan.h"
#include "Bi.h"
// 从fromIndex到toIndex,最后一个值是最低的
int LastIsMin(float *pLow, int fromIndex, int toIndex) {
for (int i = fromIndex; i < toIndex; i++) {
if (pLow[i] < pLow[toIndex]) {
return 0;
}
}
return 1;
}
// 从fromIndex到toIndex,最后一个值是最高的
int LastIsMax(float *pHigh, int fromIndex, int toIndex) {
for (int i = fromIndex; i < toIndex; i++) {
if (pHigh[i] > pHigh[toIndex]) {
return 0;
}
}
return 1;
}
// 计算底分型中间K线区间高
float RangeHign(float *pOutHigh, int nLastD) {
for (int i = nLastD - 1; i >= 0; i--) {
if (pOutHigh[i] > pOutHigh[nLastD]) {
return pOutHigh[i];
}
}
return pOutHigh[0];
}
// 计算顶分型中间K线区间低
float RangeLow(float *pOutLow, int nLastG) {
for (int i = nLastG - 1; i >= 0; i--) {
if (pOutLow[i] < pOutLow[nLastG]) {
return pOutLow[i];
}
}
return pOutLow[0];
}
// 反向跳空
int IsReverseJump(int i, int nState, int nLastD, int nLastG, float *pHigh,
float *pLow) {
if (nState == 1) {
if (pHigh[i] < pLow[nLastD]) {
if (i > nLastG && pHigh[i] < pLow[i - 1]) {
return 1;
}
}
} else if (nState == -1) {
if (pLow[i] > pHigh[nLastG]) {
if (i > nLastD && pLow[i] > pHigh[i - 1]) {
return 1;
}
}
}
return 0;
}
// 从index往前找低点坐标
int GetLastDIndex(int index, float *pSig) {
for (int x = index; x >= 0; x--) {
if (pSig[x] == -1) {
return x;
}
}
return -1;
}
// 从index往前找高点坐标
int GetLastGIndex(int index, float *pSig) {
for (int x = index; x >= 0; x--) {
if (pSig[x] == 1) {
return x;
}
}
return -1;
}
// 比较强势的上涨或者下跌也成笔
int IsStrongMove(int i, int nState, int nLastD, int nLastG, float *pHigh,
float *pLow, float* pSig) {
if (nState == 1) {
if (pLow[i] < pLow[nLastD]) {
int g1 = GetLastGIndex(i, pSig);
int g2 = GetLastGIndex(g1 - 1, pSig);
if (g1 >= 0 && g2 >= 0 && pHigh[g1] > pHigh[g2] && i - g1 >= 4) {
return 1;
}
}
} else if (nState == -1) {
if (pHigh[i] > pHigh[nLastG]) {
int d1 = GetLastDIndex(i, pSig);
int d2 = GetLastDIndex(d1 - 1, pSig);
if (d1 >= 0 && d2 >= 0 && pLow[d1] < pLow[d2] && i - d1 >= 4) {
return 1;
}
}
}
return 0;
}
bool HasTempBi(int nState, int nCount, int i, float *pHigh, float *pLow,
float *pInclude, float *pOutHigh, float *pOutLow) {
int kCount = 1;
if (nState == 1) // 找向上笔
{
for (int x = i; x < nCount; x++) {
if (pLow[x] < pLow[i]) {
return false;
} else {
if (pInclude[x] == 0) {
kCount++;
}
if (kCount >= 5 && LastIsMax(pHigh, i, x)
&& pOutHigh[x] > pOutHigh[i]) {
return true;
}
}
}
} else if (nState == -1) // 找向下笔
{
for (int x = i; x < nCount; x++) {
if (pHigh[x] > pHigh[i]) {
return false;
} else {
if (pInclude[x] == 0) {
kCount++;
}
if (kCount >= 5 && LastIsMin(pLow, i, x)
&& pOutLow[x] < pOutLow[i]) {
return true;
}
}
}
}
return true;
}
void Bi0(int nCount, float *pOut, float *pIn, float *pHigh, float *pLow) {
float *pDirection = new float[nCount];
float *pOutHigh = new float[nCount];
float *pOutLow = new float[nCount];
float *pInclude = new float[nCount];
BaoHan(nCount, pDirection, pOutHigh, pOutLow, pInclude, pHigh, pLow);
pOut[0] = -1; // -1表示笔底,1表示笔顶,初始化是第一根K线认为是一个底。
int nState = -1; // -1表示向下笔中,1表示向上笔中,初始化时候认为是向下笔的延续中
int nLastD = 0; // 底位置
int nLastG = -1; // 顶位置,初始化没有顶
int kCountDown = 5; // 计数K线数量,初始值假设已经向下笔第五根K线
int kCountUp = 1;
for (int i = 1; i < nCount; i++) {
if (nState == -1) {
// 向下笔中遇到K线出新低,底就要移到新低这里,这里不需要管K线的方向。
if (pLow[i] < pLow[nLastD]) {
pOut[nLastD] = 0;
nLastD = i;
pOut[nLastD] = -1;
kCountUp = 1;
}
// 向下笔中遇到K线不出新低。
else {
if (pInclude[i] == 0) {
if (pDirection[i] == 1) {
kCountUp++;
} else {
if (pOutHigh[i] > RangeHign(pOutHigh, nLastD)) {
kCountUp++;
} else {
kCountUp = 1;
}
}
}
if ((kCountUp >= 5
|| IsStrongMove(i, nState, nLastD, nLastG, pHigh, pLow,
pOut)
|| IsReverseJump(i, nState, nLastD, nLastG, pHigh, pLow))
&& LastIsMax(pHigh, nLastD, i)) {
nState = 1;
nLastG = i;
pOut[nLastG] = 1;
kCountDown = 1;
}
}
} else if (nState == 1) {
// 向上笔中遇到K线出新高,顶就要移到新高这里,这里不需要管K线的方向。
if (pHigh[i] > pHigh[nLastG]) {
pOut[nLastG] = 0;
nLastG = i;
pOut[nLastG] = 1;
kCountDown = 1;
}
// 向上笔中遇到K线不出新高。
else {
if (pInclude[i] == 0) {
if (pDirection[i] == -1) {
kCountDown++;
} else {
if (pOutLow[i] < RangeLow(pOutLow, nLastG)) {
kCountDown++;
} else {
kCountDown = 1;
}
}
}
if ((kCountDown >= 5
|| IsStrongMove(i, nState, nLastD, nLastG, pHigh, pLow,
pOut)
|| IsReverseJump(i, nState, nLastD, nLastG, pHigh, pLow))
&& LastIsMin(pLow, nLastG, i)) {
// 转向到向下笔状态
nState = -1;
nLastD = i;
pOut[nLastD] = -1;
kCountUp = 1;
}
}
}
// 向下笔中有高点大于前高,前高要调整。
// 向上笔中有低点小于前低,低点要调整。
while (pOut[i] == -1 || pOut[i] == 1) {
if (pOut[i] == -1) {
// 中间如果有更高的K线,前面的顶要移到更高K线那里
int IsLastGMoved = 0;
int nTemp = 0;
if (nLastG >= 0) {
nTemp = nLastG + 1;
while (nTemp <= i) {
if (pHigh[nTemp] > pHigh[nLastG]) {
IsLastGMoved = 1;
break;
}
nTemp++;
}
}
if (IsLastGMoved == 1) {
pOut[nLastG] = 0; // 消掉原来顶
nLastG = nTemp;
pOut[nLastD] = 0;
pOut[nLastG] = 1; // 顶后移
nLastD = GetLastDIndex(nLastG, pOut); // 底归位
i = nLastG; // 从新的顶重新开始计算
kCountDown = 1; // 向下K线数量归位
nState = 1;
} else {
break;
}
} else if (pOut[i] == 1) {
// 中间如果有更低的K线,前面的底要移到更低K线那里
int IsLastDMoved = 0;
int nTemp = 0;
if (nLastD >= 0) {
nTemp = nLastD + 1;
while (nTemp <= i) {
if (pLow[nTemp] < pLow[nLastD]) {
IsLastDMoved = 1;
break;
}
nTemp++;
}
}
if (IsLastDMoved == 1) {
pOut[nLastD] = 0; // 消掉原来底
nLastD = nTemp;
pOut[nLastG] = 0;
pOut[nLastD] = -1; // 底后移
nLastG = GetLastGIndex(nLastD, pOut); // 底归位
i = nLastD; // 从新的顶重新开始计算
kCountUp = 1; // 向上K线数量归位
nState = -1;
} else {
break;
}
}
}
}
delete[] pDirection;
delete[] pOutHigh;
delete[] pOutLow;
delete[] pInclude;
}
void Bi1(int nCount, float *pOut, float *pIn, float *pHigh, float *pLow) {
CIniReader iniReader(".\\T0002\\dlls\\ChanlunX.ini");
int iFenXingQuJian = iniReader.ReadInteger("PeiZhi", "FenXingQuJian", 2);
float *pDirection = new float[nCount];
float *pOutHigh = new float[nCount];
float *pOutLow = new float[nCount];
float *pInclude = new float[nCount];
BaoHan(nCount, pDirection, pOutHigh, pOutLow, pInclude, pHigh, pLow);
pOut[0] = -1; // -1表示笔底,1表示笔顶,初始化是第一根K线认为是一个底。
int nState = -1; // -1表示向下笔中,1表示向上笔中,初始化时候认为是向下笔的延续中
int nLastD = 0; // 底位置
int nLastG = -1; // 顶位置,初始化没有顶
int kCountDown = 5; // 计数K线数量,初始值假设已经向下笔第五根K线
int kCountDownRaw = 5;
int kCountUp = 1;
int kCountUpRaw = 1;
for (int i = 1; i < nCount; i++) {
if (nState == -1) {
// 向下笔中遇到K线出新低,底就要移到新低这里,这里不需要管K线的方向。
if (pLow[i] < pLow[nLastD]) {
pOut[nLastD] = 0;
nLastD = i;
pOut[nLastD] = -1;
kCountUp = 1;
kCountUpRaw = 1;
}
// 向下笔中遇到K线不出新低。
else {
if (pInclude[i] == 0) {
kCountUp++;
}
kCountUpRaw++;
if (((kCountUp >= 4 && kCountUpRaw >= 5)
|| IsStrongMove(i, nState, nLastD, nLastG, pHigh, pLow,
pOut)
|| IsReverseJump(i, nState, nLastD, nLastG, pHigh, pLow))
&& LastIsMax(pHigh, nLastD, i)
&& (iFenXingQuJian == 1 ?
pOutHigh[i] > RangeHign(pOutHigh, nLastD) :
pOutHigh[i] > pOutHigh[nLastD])) {
nState = 1;
nLastG = i;
pOut[nLastG] = 1;
kCountDown = 1;
kCountDownRaw = 1;
}
}
} else if (nState == 1) {
// 向上笔中遇到K线出新高,顶就要移到新高这里,这里不需要管K线的方向。
if (pHigh[i] > pHigh[nLastG]) {
pOut[nLastG] = 0;
nLastG = i;
pOut[nLastG] = 1;
kCountDown = 1;
kCountDownRaw = 1;
}
// 向上笔中遇到K线不出新高。
else {
if (pInclude[i] == 0) {
kCountDown++;
}
kCountDownRaw++;
if (((kCountDown >= 4 && kCountDownRaw >= 5)
|| IsStrongMove(i, nState, nLastD, nLastG, pHigh, pLow,
pOut)
|| IsReverseJump(i, nState, nLastD, nLastG, pHigh, pLow))
&& LastIsMin(pLow, nLastG, i)
&& (iFenXingQuJian == 1 ?
pOutLow[i] < RangeLow(pOutLow, nLastG) :
pOutLow[i] < pOutLow[nLastG])) {
// 转向到向下笔状态
nState = -1;
nLastD = i;
pOut[nLastD] = -1;
kCountUp = 1;
kCountUpRaw = 1;
}
}
}
// 向下笔中有高点大于前高,前高要调整。
// 向上笔中有低点小于前低,低点要调整。
while (pOut[i] == -1 || pOut[i] == 1) {
if (pOut[i] == -1) {
// 中间如果有更高的K线,前面的顶要移到更高K线那里
int IsLastGMoved = 0;
int nTemp = 0;
if (nLastG >= 0) {
nTemp = nLastG + 1;
while (nTemp <= i) {
if (pHigh[nTemp] > pHigh[nLastG]) {
IsLastGMoved = 1;
break;
}
nTemp++;
}
}
if (IsLastGMoved == 1) {
pOut[nLastG] = 0; // 消掉原来顶
nLastG = nTemp;
pOut[nLastD] = 0;
pOut[nLastG] = 1; // 顶后移
nLastD = GetLastDIndex(nLastG, pOut); // 底归位
i = nLastG; // 从新的顶重新开始计算
kCountDown = 1; // 向下K线数量归位
kCountDownRaw = 1;
nState = 1;
} else {
break;
}
} else if (pOut[i] == 1) {
// 中间如果有更低的K线,前面的底要移到更低K线那里
int IsLastDMoved = 0;
int nTemp = 0;
if (nLastD >= 0) {
nTemp = nLastD + 1;
while (nTemp <= i) {
if (pLow[nTemp] < pLow[nLastD]) {
IsLastDMoved = 1;
break;
}
nTemp++;
}
}
if (IsLastDMoved == 1) {
pOut[nLastD] = 0; // 消掉原来底
nLastD = nTemp;
pOut[nLastG] = 0;
pOut[nLastD] = -1; // 底后移
nLastG = GetLastGIndex(nLastD, pOut); // 底归位
i = nLastD; // 从新的顶重新开始计算
kCountUp = 1; // 向上K线数量归位
kCountUpRaw = 1;
nState = -1;
} else {
break;
}
}
}
}
delete[] pDirection;
delete[] pOutHigh;
delete[] pOutLow;
delete[] pInclude;
}
void Bi2(int nCount, float *pOut, float *pIn, float *pHigh, float *pLow) {
CIniReader iniReader(".\\T0002\\dlls\\ChanlunX.ini");
int iFenXingQuJian = iniReader.ReadInteger("PeiZhi", "FenXingQuJian", 2);
float *pDirection = new float[nCount];
float *pOutHigh = new float[nCount];
float *pOutLow = new float[nCount];
float *pInclude = new float[nCount];
BaoHan(nCount, pDirection, pOutHigh, pOutLow, pInclude, pHigh, pLow);
pOut[0] = -1; // -1表示笔底,1表示笔顶,初始化是第一根K线认为是一个底。
int nState = -1; // -1表示向下笔中,1表示向上笔中,初始化时候认为是向下笔的延续中
int nLastD = 0; // 底位置
int nLastG = -1; // 顶位置,初始化没有顶
int kCountDown = 5; // 计数K线数量,初始值假设已经向下笔第五根K线
int kCountUp = 1;
for (int i = 1; i < nCount; i++) {
if (nState == -1) {
// 向下笔中遇到K线出新低,底就要移到新低这里,这里不需要管K线的方向。
if (pLow[i] < pLow[nLastD]) {
pOut[nLastD] = 0;
nLastD = i;
pOut[nLastD] = -1;
kCountUp = 1;
}
// 向下笔中遇到K线不出新低。
else {
if (pInclude[i] == 0) {
kCountUp++;
}
if ((kCountUp >= 5
|| IsStrongMove(i, nState, nLastD, nLastG, pHigh, pLow,
pOut)
|| IsReverseJump(i, nState, nLastD, nLastG, pHigh, pLow))
&& LastIsMax(pHigh, nLastD, i)
&& (iFenXingQuJian == 1 ?
pOutHigh[i] > RangeHign(pOutHigh, nLastD) :
pOutHigh[i] > pOutHigh[nLastD])) {
nState = 1;
nLastG = i;
pOut[nLastG] = 1;
kCountDown = 1;
} else {
int d1 = GetLastDIndex(i, pOut);
int d2 = GetLastDIndex(d1 - 1, pOut);
int g1 = GetLastGIndex(i, pOut);
if (d1 >= 0 && d2 >= 0 && g1 >= 0 && g1 < d1 && d2 < g1
&& pLow[d1] > pLow[d2] && pHigh[i] > pHigh[g1]
&& HasTempBi(nState, nCount, i, pHigh, pLow,
pInclude, pOutHigh, pOutLow)) {
pOut[d1] = 0;
pOut[g1] = 0;
nState = 1;
nLastG = i;
pOut[nLastG] = 1;
kCountDown = 1;
} else {
pOut[i] = 0;
}
}
}
} else if (nState == 1) {
// 向上笔中遇到K线出新高,顶就要移到新高这里,这里不需要管K线的方向。
if (pHigh[i] > pHigh[nLastG]) {
pOut[nLastG] = 0;
nLastG = i;
pOut[nLastG] = 1;
kCountDown = 1;
}
// 向上笔中遇到K线不出新高。
else {
if (pInclude[i] == 0) {
kCountDown++;
}
if ((kCountDown >= 5
|| IsStrongMove(i, nState, nLastD, nLastG, pHigh, pLow,
pOut)
|| IsReverseJump(i, nState, nLastD, nLastG, pHigh, pLow))
&& LastIsMin(pLow, nLastG, i)
&& (iFenXingQuJian == 1 ?
pOutLow[i] < RangeLow(pOutLow, nLastG) :
pOutLow[i] < pOutLow[nLastG])) {
// 转向到向下笔状态
nState = -1;
nLastD = i;
pOut[nLastD] = -1;
kCountUp = 1;
} else {
int g1 = GetLastGIndex(i, pOut);
int g2 = GetLastGIndex(g1 - 1, pOut);
int d1 = GetLastDIndex(i, pOut);
if (g1 >= 0 && g2 >= 0 && d1 >= 0 && d1 < g1 && g2 < d1
&& pHigh[g1] < pHigh[g2] && pLow[i] < pLow[d1]
&& HasTempBi(nState, nCount, i, pHigh, pLow,
pInclude, pOutHigh, pOutLow)) {
pOut[g1] = 0;
pOut[d1] = 0;
nState = -1;
nLastD = i;
pOut[nLastD] = -1;
kCountUp = 1;
} else {
pOut[i] = 0;
}
}
}
}
// 向下笔中有高点大于前高,前高要调整。
// 向上笔中有低点小于前低,低点要调整。
while (pOut[i] == -1 || pOut[i] == 1) {
if (pOut[i] == -1) {
// 中间如果有更高的K线,前面的顶要移到更高K线那里
int IsLastGMoved = 0;
int nTemp = 0;
if (nLastG >= 0) {
nTemp = nLastG + 1;
while (nTemp <= i) {
if (pHigh[nTemp] > pHigh[nLastG]) {
IsLastGMoved = 1;
break;
}
nTemp++;
}
}
if (IsLastGMoved == 1) {
pOut[nLastG] = 0; // 消掉原来顶
nLastG = nTemp;
pOut[nLastD] = 0;
pOut[nLastG] = 1; // 顶后移
nLastD = GetLastDIndex(nLastG, pOut); // 底归位
i = nLastG; // 从新的顶重新开始计算
kCountDown = 1; // 向下K线数量归位
nState = 1;
} else {
break;
}
} else if (pOut[i] == 1) {
// 中间如果有更低的K线,前面的底要移到更低K线那里
int IsLastDMoved = 0;
int nTemp = 0;
if (nLastD >= 0) {
nTemp = nLastD + 1;
while (nTemp <= i) {
if (pLow[nTemp] < pLow[nLastD]) {
IsLastDMoved = 1;
break;
}
nTemp++;
}
}
if (IsLastDMoved == 1) {
pOut[nLastD] = 0; // 消掉原来底
nLastD = nTemp;
pOut[nLastG] = 0;
pOut[nLastD] = -1; // 底后移
nLastG = GetLastGIndex(nLastD, pOut); // 底归位
i = nLastD; // 从新的顶重新开始计算
kCountUp = 1; // 向上K线数量归位
nState = -1;
} else {
break;
}
}
}
}
delete[] pDirection;
delete[] pOutHigh;
delete[] pOutLow;
delete[] pInclude;
}
void Bi3(int nCount, float *pOut, float *pIn, float *pHigh, float *pLow)
{
float *pDirection = new float[nCount];
float *pOutHigh = new float[nCount];
float *pOutLow = new float[nCount];
float *pInclude = new float[nCount];
BaoHan(nCount, pDirection, pOutHigh, pOutLow, pInclude, pHigh, pLow);
for (int i = 1; i < nCount; i++)
{
if (pDirection[i-1] == 1 && pDirection[i] == -1)
{
pOut[i-1] = 1;
}
else if (pDirection[i-1] == -1 && pDirection[i] == 1)
{
pOut[i-1] = -1;
}
else
{
pOut[i-1] = 0;
}
}
if (pDirection[nCount-1]== 1)
{
pOut[nCount-1] = 1;
}
else if (pDirection[nCount-1]== -1)
{
pOut[nCount-1] = -1;
}
for (int i = 0; i < nCount; i++)
{
if (pOut[i] == 1)
{
int d = i;
for (int j = i - 1; j >= 0; j--)
{
if (pOut[j] == -1) break;
if (pHigh[j] > pHigh[d])
{
pOut[d] = 0;
d = j;
pOut[d] = 1;
}
}
}
else if (pOut[i] == -1)
{
int d = i;
for (int j = i - 1; j >= 0; j--)
{
if (pOut[j] == 1) break;
if (pLow[j] < pLow[d])
{
pOut[d] = 0;
d = j;
pOut[d] = -1;
}
}
}
}
delete []pDirection;
delete []pOutHigh;
delete []pOutLow;
delete []pInclude;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/development/ChanlunX.git
git@gitee.com:development/ChanlunX.git
development
ChanlunX
ChanlunX
master

搜索帮助