设为首页收藏本站

『外汇堂』·专业外汇论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 3183|回复: 0
打印 上一主题 下一主题

有请高手帮帮忙,我的EA不开单

[复制链接]
跳转到指定楼层
1#
发表于 2011-3-27 11:27:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
这个是我周末做的小EA,不知道什么原因,测试就是不开单啊,我急啊,帮我改改可以吗 ?
//---- input parameters
extern double TakeProfit = 20;
extern double StopLoss = 30;
extern double Lots = 2;
extern double TrailingStop = 50;
int period=26;
double         ExtBuffer0[];
double         ExtBuffer1[];
double         ExtBuffer2[];
double         UPBuffer[];
double         DOWNBuffer[];
double         MO[];
double         DO[];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(8);
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_ARROW);
   SetIndexStyle(4,DRAW_ARROW);
   SetIndexArrow(3,233);
   SetIndexArrow(4,234);
   IndicatorDigits(Digits+1);

   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
   SetIndexBuffer(3,UPBuffer);
   SetIndexBuffer(4,DOWNBuffer);
   SetIndexBuffer(5,MO);
   SetIndexBuffer(6,DO);
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
int start()
  {
   int cnt, ticket, total;
   int    limit;
   int    counted_bars=IndicatorCounted();
   double prev,current,old;
   double Value=0,Value1=0,Value2=0,Fish=0,Fish1=0,Fish2=0;
   double price;
   double MinL=0;
   double MaxH=0;  
   static int isCrossed  = 0;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;


   for(int i=0; i<Bars; i++)
    {
      MaxH = High[Highest(NULL,0,MODE_HIGH,period,i)];
      MinL = Low[Lowest(NULL,0,MODE_LOW,period,i)];
      price = (High+Low)/2;
      
      if(MaxH-MinL == 0) Value =0.67 *2*(0-0.5) +0.33 *Value1;
      else Value = 0.67*2*((price-MinL)/(MaxH-MinL)-0.5) +0.33 *Value1;     
      
      Value=MathMin(MathMax(Value,-0.999),0.999);
      
      if(1-Value == 0) ExtBuffer0=0.5+0.5*Fish1;
      else ExtBuffer0=0.5*MathLog((1+Value)/(1-Value))+0.5*Fish1;
      
      Value1=Value;
      Fish1=ExtBuffer0;
    }
   
     bool up=true;
   for(i=Bars; i>=0; i--)
     {
      current=ExtBuffer0;
      prev=ExtBuffer0[i+1];
      MO=ExtBuffer0;
      DO=ExtBuffer0[i+1];     
      if (((current<0)&&(prev>0))||(current<0))   up=false;   
      if (((current>0)&&(prev<0))||(current>0))   up=true;
      
      if(!up)
        {
         ExtBuffer2=current;
         ExtBuffer1=0.0;
        }
        
       else
         {
          ExtBuffer1=current;
          ExtBuffer2=0.0;
         }
     }
   
   for(i=Bars; i>=0; i--)
     {
      if (MO>0 && MO[i+1]<0)
         isCrossed = 1;
         UPBuffer=-0.1 ;
      if (MO<0 && MO[i+1]>0)
         isCrossed =2 ;
         DOWNBuffer=0.1;
      return(0);   
     }
//----
    total  = OrdersTotal();
    if(total < 1)
      {
        if(isCrossed == 1)
          {
            ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask - StopLoss*Point,
                               Ask + TakeProfit*Point, "Fisher", 0, 0, Green);
            if(ticket > 0)
              {
                if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
                    Print("BUY order opened : ",OrderOpenPrice());
              }
            else
                Print("Error opening BUY order : ", GetLastError());
            return(0);
          }
        if(isCrossed == 2)
          {
            ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Bid + StopLoss*Point,
                               Bid - TakeProfit*Point, "Fisher", 0, 0, Red);
            if(ticket > 0)
              {
                if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
                    Print("SELL order opened : ", OrderOpenPrice());
              }
            else
                Print("Error opening SELL order : ",GetLastError());
            return(0);
          }
        return(0);
      }
//----
    for(cnt = 0; cnt < total; cnt++)
      {
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
        if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
          {
            if(OrderType() == OP_BUY)   // long position is opened
              {
                // check for trailing stop
                if(TrailingStop > 0)  
                  {                 
                    if(Bid - OrderOpenPrice() > Point*TrailingStop)
                      {
                        if(OrderStopLoss() < Bid - Point*TrailingStop)
                          {
                            OrderModify(OrderTicket(), OrderOpenPrice(),
                                        Bid - Point*TrailingStop,
                                        OrderTakeProfit(), 0, Green);
                            return(0);
                          }
                      }
                  }
              }
            else // go to short position
              {
                // check for trailing stop
                if(TrailingStop > 0)  
                  {                 
                    if((OrderOpenPrice() - Ask) > (Point*TrailingStop))
                      {
                        if((OrderStopLoss() > (Ask + Point*TrailingStop)) ||
                           (OrderStopLoss() == 0))
                          {
                            OrderModify(OrderTicket(), OrderOpenPrice(),
                                        Ask + Point*TrailingStop,
                                        OrderTakeProfit(), 0, Red);
                            return(0);
                          }
                      }
                  }
              }
          }
      }

    return(0);
  }


//+------------------------------------------------------------------+
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|小黑屋|外汇堂·专业外汇论坛    

GMT+8, 2024-4-20 18:06 , Processed in 0.167973 second(s), 25 queries .

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表