交易筑基吧 关注:9贴子:30
  • 3回复贴,共1

【mt5源码】倒转K线指标

只看楼主收藏回复

这是我早期写的一个指标,翻出来共享,那时候写代码都是抄过来改,感觉有点乱。
有段时间,在看行情下跌趋势时,总感觉不如看向上趋势有把握,影响做空。就写了这个指标。

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots 3
#property indicator_label1 "TalonBars"
#property indicator_type1 DRAW_CANDLES
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
#property indicator_color1 clrLime,clrBlack,clrWhite
#property indicator_label2 "iMA7"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 2
#property indicator_label3 "iMA21"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrYellow
#property indicator_style3 STYLE_SOLID
#property indicator_width3 2
input int N=5;
input int bars=500;
input bool messages=false;
double ColorBarsBuffer1[];
double ColorBarsBuffer2[];
double ColorBarsBuffer3[];
double ColorBarsBuffer4[];
double MAlineBuffer1[];
double MAlineBuffer2[];
int OnInit()
{
//--- 指标缓冲区映射
SetIndexBuffer(0,ColorBarsBuffer1,INDICATOR_DATA);
SetIndexBuffer(1,ColorBarsBuffer2,INDICATOR_DATA);
SetIndexBuffer(2,ColorBarsBuffer3,INDICATOR_DATA);
SetIndexBuffer(3,ColorBarsBuffer4,INDICATOR_DATA);
SetIndexBuffer(4,MAlineBuffer1,INDICATOR_DATA);
SetIndexBuffer(5,MAlineBuffer2,INDICATOR_DATA);
return(INIT_SUCCEEDED);
}
int OnCalculate( const int rates_total, const int prev_calculated, const datetime &time[],
const double &open[], const double &high[], const double &low[], const double &close[],
const long &tick_volume[], const long &volume[], const int &spread[] )
{
static int ticks=0;
ticks++;
if(ticks>=N)
{
int tries=0;
while(!CopyFromSymbolToBuffers(rates_total) && tries<5) {tries++;}
ticks=0;
}
return(rates_total);
}
bool CopyFromSymbolToBuffers(int total)
{
MqlRates rates[];
int attempts=0;
int copied=0;
while(attempts<25 && (copied=CopyRates(_Symbol,_Period,0,bars,rates))<0)
{
Sleep(100);
attempts++;
}
if(copied!=bars) {return(false);}
ArrayInitialize(ColorBarsBuffer1,0.0);
ArrayInitialize(ColorBarsBuffer2,0.0);
ArrayInitialize(ColorBarsBuffer3,0.0);
ArrayInitialize(ColorBarsBuffer4,0.0);
ArrayInitialize(MAlineBuffer1,0.0);
ArrayInitialize(MAlineBuffer2,0.0);
ColorBarsBuffer1[0]=rates[0].open;
ColorBarsBuffer2[0]=rates[0].high;
ColorBarsBuffer3[0]=rates[0].low;
ColorBarsBuffer4[0]=rates[0].close;
for(int i=1;i<copied;i++)
{
int buffer_index=total-copied+i;
double newOpenPrice= ColorBarsBuffer4[i-1]-(rates[i].open-ColorBarsBuffer4[i-1]);
ColorBarsBuffer1[buffer_index]=newOpenPrice;
ColorBarsBuffer2[buffer_index]=newOpenPrice+(rates[i].open-rates[i].low);
ColorBarsBuffer3[buffer_index]=newOpenPrice-(rates[i].high-rates[i].open);
ColorBarsBuffer4[buffer_index]=newOpenPrice-(rates[i].close-rates[i].open);
if (buffer_index>=7)
{
MAlineBuffer1[buffer_index]=ColorBarsBuffer4[buffer_index];
for(int j=6;j>0;j--)
{
MAlineBuffer1[buffer_index]=MAlineBuffer1[buffer_index]+ColorBarsBuffer4[buffer_index-j];
}
MAlineBuffer1[buffer_index]=MAlineBuffer1[buffer_index]/7;
}
if (buffer_index>=21)
{
MAlineBuffer2[buffer_index]=ColorBarsBuffer4[buffer_index];
for(int j=20;j>0;j--)
{
MAlineBuffer2[buffer_index]=MAlineBuffer2[buffer_index]+ColorBarsBuffer4[buffer_index-j];
}
MAlineBuffer2[buffer_index]=MAlineBuffer2[buffer_index]/21;
}
}
return(true);
}


1楼2024-07-22 14:53回复
    老哥大义,正想要这个呢


    IP属地:上海2楼2025-08-22 23:47
    回复
      2026-09-19 18:17:29
      广告
      不感兴趣
      开通SVIP免广告
      可调色4个(目前3个)好看些,能不能增加一个可调K线色?


      IP属地:河南来自Android客户端3楼2025-09-18 13:41
      回复
        哪个能给个现成的指标,不会写自定义指标。


        IP属地:河南4楼2026-08-18 11:24
        回复