tailing1985 发表于 2025-3-5 11:14:39

一款简单的关于cci基本应用的ea代写

1.参数设置
开仓手数
cci参数设置
上穿做多cci数值
下穿做空cci数值
2. **入场条件**
   - **多头信号**:CCI上穿-100且价格突破前一根K线高点。
   - **空头信号**:CCI下穿+100且价格跌破前一根K线低点。
每一次符合条件都开单,允许同时两个方向持仓多个单子

LDC 发表于 2025-3-5 16:28:50

靠这个做单是不是有点马虎

EAXAU 发表于 2025-3-11 02:27:38

基于MT4还是MT5?

EAXAU 发表于 2025-3-11 04:05:54

#property copyright "VX luolin9687"
#property link      "https://www.zhihu.com/people/ll-xau"
#property version   "1.00"
#property strict

input int    mMagic=88888;//订单识别号
input double mLots   =0.01;   //开仓手数

input ENUM_TIMEFRAMES    tpCciTimeFrame=PERIOD_CURRENT;      //图表周期
input int                tpCciIndex    =21;   //CCI周期
input ENUM_APPLIED_PRICE tpCciPrice    =4;       //CCI应用价格
input double             tpCciDn       =-100;         //上穿做多cci数值
input double             tpCciUp       =100;         //下穿做空cci数值




double ma_val1=0,ma_val2=0;
int    totals=0;
datetime k_time=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                 |
//+------------------------------------------------------------------+
int OnInit()
{
//---
   
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
   
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{
//---
   RefOrders();
   
   kaicang();
   
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void RefOrders()
{
        totals=0;
       
        int total=OrdersTotal();
        for(int i=0;i<total;i++)
        {
           if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
         continue;
      int magc=OrderMagicNumber();
      int otype =OrderType();
      if(OrderSymbol()==Symbol() && magc==mMagic && otype<=OP_SELL)
      {
         totals++;
      }
        }

}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool IsCicang(int type)
{
        int total=OrdersTotal();
        for(int i=0;i<total;i++)
        {
           if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      int magc=OrderMagicNumber();
      int otype =OrderType();
      if(OrderSymbol()==Symbol() && magc==mMagic && otype==type)
      {
         if(OrderOpenTime()>=iTime(Symbol(),tpCciTimeFrame,0)) return(true);
      }
        }
        return(false);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double tpCCI;
string coment="";
int GetItorVal()
{
        ArrayInitialize(tpCCI,0);
   for(int i=0;i<2;i++)
      tpCCI=iCCI(NULL,tpCciTimeFrame,tpCciIndex,tpCciPrice,i);
       
        //CCI突破下轨做多
        if(tpCCI<=tpCciDn && tpCCI>tpCciDn
        && Bid>=iHigh(NULL,0,1))
        {
                coment="CCI突破开多";   return(1);
        }
   
   if(tpCCI>=tpCciUp && tpCCI<tpCciUp
        && Bid<=iLow(NULL,0,1))
        {
                coment="CCI突破开空";   return(2);
        }
   
   return 0;       
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool kaicang()
{
        if(GetItorVal()==1 && !IsCicang(OP_BUY))
        { Print(" IsCicang(OP_BUY)=",IsCicang(OP_BUY));
                double tlots=NormalizeDouble(mLots,Digits);
                if(OrderSend(Symbol(),OP_BUY,tlots,Ask,3,0,0,coment,mMagic,0,clrGreen))
           {
                   return true;
           }
           else{
              Print("开多单失败。错误 #",GetLastError());
           }
        }
       
        if(GetItorVal()==2 && !IsCicang(OP_SELL))
        {Print(" IsCicang(OP_SELL)=",IsCicang(OP_SELL));
                double tlots=NormalizeDouble(mLots,Digits);
                if(OrderSend(Symbol(),OP_SELL,tlots,Bid,3,0,0,coment,mMagic,0,clrRed))
           {
                   return true;
           }
           else{
              Print("开空单失败。错误 #",GetLastError());
           }
        }
       
        return false;
}
页: [1]
查看完整版本: 一款简单的关于cci基本应用的ea代写