MT4-判断趋势是否成立的指标

本文介绍了一种基于MetaQuotes软件实现的交易趋势判断算法。该算法通过分析特定数量的K线与其移动平均线的位置关系来判断市场趋势是否成立。具体而言,算法检查在最近一段时间内是否有足够数量的K线位于移动平均线上方或下方,并且最远的一根K线开盘价与最近一根K线收盘价之间的差价是否超过设定阈值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


#property copyright "Copyright ?2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
//>=16根线在平均线上/下,并且最远的一个K线开盘价格与当前收盘价差价>20点
extern int MA_Period=20;
extern int MA_Mode=0;
extern int JC=20;
extern int Kxsl=16; //K线数量

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
  
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
 

if(CheckTrend()==1)
Print("趋势成立");
  
   //Print("pjjg="+pjjg);
   return (0);

  }
  // 返回1趋势成立,0不成立
  int CheckTrend()
  {
 
  int upcount=0; //在平均线以上的K线数量
  int downcount=0;//在平均线以下的K线数量

                                      
                              


   int    counted_bars=IndicatorCounted();  
   if(counted_bars<0) return (-1);
  
   double pjjg=iMA(NULL,0,MA_Period,0,MA_Mode,PRICE_CLOSE,1);  //从最近已经完成的K线计算的平均价
   double iClosesum=0;
   for(int i=0;i<MA_Period;i++)
   {
      //iClosesum=iClosesum+iClose(NULL,0,i+1);
      iClosesum=iClose(NULL,0,i+1);
      if(iClosesum>pjjg)
      {
      upcount++;
      }
      else if(iClosesum<pjjg)
     
      downcount++;
     
   }
  
   double kpj=iOpen(NULL,0,MA_Period);//取最远的那根K线的开盘价
   double spj=iClose(NULL,0,1);//取最近K线的收盘价
  
   if(upcount>=Kxsl)
   {
   if(MathAbs(kpj-spj)>JC )
   {
   return (1);
   }
  
   }
   return (0);
  
  }
//+------------------------------------------------------------------+ 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值