gpt4 book ai didi

algorithmic-trading - 如何在多个时间范围内搜索烛台形态

转载 作者:行者123 更新时间:2023-12-04 04:06:07 26 4
gpt4 key购买 nike

我有一个专家顾问在一个特别定义的看跌 pinbar 上绘制矩形,然后是看涨蜡烛。请看下面的代码。它基本上显示了图表上显示的时间范围内的矩形。

如何在 H1 烛台到 M2 的时间范围内搜索此烛台模式,以便我可以过滤具有最长看跌 pinbar 的模式来自所有时间范围?

string prefix="PBar";
int magicnumber = 12345;

bool drawBearPinbarRectangle(int candleInt,const double top,const double bottom, ENUM_TIMEFRAMES cDuration, color rectColor)
{
bool checkBarCount = true;
int useCurrDuration = PeriodSeconds(cDuration)/PeriodSeconds();

const datetime starts = iTime(_Symbol,_Period,candleInt);

const datetime ends = starts + useCurrDuration*PeriodSeconds();
const string name=prefix+"_"+"_"+TimeToString(starts)+TimeToString(ends);
if(!ObjectCreate(0,name,OBJ_RECTANGLE,0,starts ,top, ends, bottom))
{
return false;
}


ObjectSetInteger(0,name,OBJPROP_COLOR, rectColor);

ObjectSetInteger(0,name,OBJPROP_STYLE, STYLE_DASHDOT);

ObjectSetInteger(0,name,OBJPROP_WIDTH,1);

ObjectSetInteger(0,name,OBJPROP_FILL, true);

return true;
}

bool isBearPinBarType(int candleInt, ENUM_TIMEFRAMES cDuration, double maxLowerWickSize, double maxBodySize) {

if (iOpen( _Symbol, cDuration, candleInt ) > iClose( _Symbol, cDuration, candleInt )) {

double upperWick = iHigh( _Symbol, cDuration, candleInt ) - iOpen( _Symbol, cDuration, candleInt );
double body = iOpen( _Symbol, cDuration, candleInt ) - iClose( _Symbol, cDuration, candleInt );
double lowerWick = iClose( _Symbol, cDuration, candleInt ) - iLow( _Symbol, cDuration, candleInt );

double totalCandle = upperWick + body + lowerWick;

if (((lowerWick > 0.0) && (lowerWick <= totalCandle*maxLowerWickSize)) && ((body > 0.0) && (body <= totalCandle*maxBodySize)))
return true;

return false;

}

else
return false;
}


bool isBullPinBarType(int candleInt, ENUM_TIMEFRAMES cDuration, double maxLowerWickSize, double maxBodySize) {

if ((iHigh( _Symbol, cDuration, candleInt ) - iClose( _Symbol, cDuration, candleInt )) > 0) {

double upperWick = iHigh( _Symbol, cDuration, candleInt ) - iOpen( _Symbol, cDuration, candleInt );
double body = iOpen( _Symbol, cDuration, candleInt ) - iClose( _Symbol, cDuration, candleInt );
double lowerWick = iClose( _Symbol, cDuration, candleInt ) - iLow( _Symbol, cDuration, candleInt );

double totalCandle = upperWick + body + lowerWick;

if (((lowerWick > 0.0) && (lowerWick <= totalCandle*maxLowerWickSize)) && ((body > 0.0) && (body <= totalCandle*maxBodySize)))
return true;

return false;

}

else
return false;
}

void showPinbarRectOnDispTime() {


for (int i=NumOfDisplayBars;i>=1;i--) {

double barOpen = iOpen(_Symbol,0,i + 1);
double barHigh = iHigh(_Symbol,0,i + 1);


if (isBearPinBarType(i + 2, 0, 0.15, 0.3)
&&
(iOpen(_Symbol,0,i + 1) < iClose(_Symbol,0,i + 1))) {

drawBearPinbarRectangle(i +2,iHigh(_Symbol,0,i + 2),iLow(_Symbol,0,i + 2), 0, clrCyan);


}
}

}

bool isBearPinBarWithOpenAndClose(int numCandle, ENUM_TIMEFRAMES cDuration, double maxLowerWickSize, double maxBodySize,
double candleOpen, double candleHigh) {



if ((NormalizeDouble((iOpen( _Symbol, cDuration, numCandle)), 2) == NormalizeDouble(candleOpen, 2)) &&
(NormalizeDouble((iHigh( _Symbol, cDuration, numCandle)), 2) == NormalizeDouble(candleHigh, 2)) &&
((iHigh( _Symbol, cDuration, numCandle ) - iClose( _Symbol, cDuration, numCandle )) > 0)) {

double upperWick = iHigh( _Symbol, cDuration, numCandle ) - iOpen( _Symbol, cDuration, numCandle );
double body = iOpen( _Symbol, cDuration, numCandle ) - iClose( _Symbol, cDuration, numCandle );
double lowerWick = iClose( _Symbol, cDuration, numCandle ) - iLow( _Symbol, cDuration, numCandle );

double totalCandle = upperWick + body + lowerWick;

if (((lowerWick > 0.0) && (lowerWick <= totalCandle*maxLowerWickSize)) && ((body > 0.0) && (body <= totalCandle*maxBodySize)))
return true;

return false;

}

else
return false;


}

void OnDeinit(const int reason){ObjectsDeleteAll(0,prefix);}


void OnTick()
{



showPinbarRectOnDispTime();

}

最佳答案

  1. 声明所有必要的时间范围 ENUM_TIMEFRAMES tfs[];
  2. 将其填入 OnInit() 然后循环值:for(int i=ArraySize(tfs)-1;i>=0;i--){showPinbarRectOnDispTime(tfs[ i]);};
  3. 编辑 showPinbarRectOnDispTime(ENUM_TIMEFRAMES tf) 函数:double barOpen = iOpen(_Symbol,tf,i + 1); 等等;
  4. 考虑您是只需要绘制 pin bar 矩形,还是以某种方式在不绘制的情况下使用该数据。

关于algorithmic-trading - 如何在多个时间范围内搜索烛台形态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62479581/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com