如何在MT4图表中显示这样的历史交易信号?

Discussion in 'MetaTrader' started by dadupi, Oct 4, 2010.

  1. [​IMG]

    做EA测试的时候,可以在图表中显示交易信号
    那么在实盘手动操作的时候,如何显示这样的历史的开平仓信号?
     
  2. 搜了一晚上,找到两个解决方案

    1.直接把历史成交拖拽到图表上,就可以。
    优点,方便,而且实时切换到发生交易的那个时间段
    缺点,麻烦,成交多的话,比如有个几百条,那很幸苦的

    2.有人在外汇群论坛上发过“复盘工具”http://bbs.waihuiqun.com/viewthread.php?tid=1899&highlight=%B8%B4%C5%CC
    优点,一次批量倒入,还有成交价格显示
    缺点,麻烦,需要先导出历史记录,存成cvs格式,再导入

    期待有更好的解决方案
     
  3. 关注...
     
  4. 这个想法不错!已经实现了,做出一个指标形式的,直接在图表中显示开平仓历史,附上指标即可,很方便,跟MT4的EA做出来的是一样的,有需要,留下邮件地址可以发送。
     
  5. Code:
    //+------------------------------------------------------------------+
    //|                                                 ShowTradeHis.mq4 |
    //|                                      ST小散           liangdawen |
    //+------------------------------------------------------------------+
    #property copyright "liangdawen"
    #property link      "ldawen@126.com"
    
    #property indicator_chart_window
    
    string indNames = "";
    
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    
    int init()
    {
       return(0);
    }
    
    int deinit()
    {
       DelTradesHis();
       ObjectDelete("Show Trade History ");
       ObjectDelete("copyright");
    
       return(0);
    }
    
    
    //+------------------------------------------------------------------+
    //|                                                                  |
    //+------------------------------------------------------------------+
    
    int start()
    {
         /*
         LabelCreate("ldw1",10,10,"abckmklsjfls");
         ArrowCreate("ldwdsf",D'2010.10.01 22:10',1.3675,"safs",Red,3);
         ArrowCreate("ld1wdsf",D'2010.10.01 20:10',1.3625,"sasfs",Blue,1);
         ArrowCreate("ld1sf",D'2010.10.01 10:10',1.3615,"sasfs",Blue,4);
         TrendLineCreate("kslsflksfsl",D'2010.10.01 22:10',1.3675,D'2010.10.01 20:10',1.3625);
         */
    
       static datetime BarTime = 0;
       if(BarTime  != Time[0])
       {
         BarTime  = Time[0];
         LabelCreate("Show Trade History ",10,10,"Show Trade History");
         LabelCreate("copyright",25,25,"(liangdawen)");
         
         ShowTrades();
         
       }
       return(0);
      }
    
    //+------------------------------------------------------------------+
    
    
    void LabelCreate(string name,int x,int y,string text="-",int size=10,string font="Arial",color colour=Red,int window = 0)
    {
       if (ObjectFind(indNames+name) == -1)
       {
          ObjectCreate(indNames+name,OBJ_LABEL,window,0,0);
             ObjectSet(indNames+name,OBJPROP_CORNER,1);
             ObjectSet(indNames+name,OBJPROP_XDISTANCE,x);
             ObjectSet(indNames+name,OBJPROP_YDISTANCE,y);
       }               
       ObjectSetText(indNames+name,text,size,font,colour);
    }
    
    void ArrowCreate(string name,datetime dt,double price,string text = "-",color colour=Red,int ArrowType = 1,int window = 0)
    {
       if (ObjectFind(indNames+name) == -1)
       {
          ObjectCreate(indNames+name,OBJ_ARROW,window,dt,price);
          ObjectSet(indNames+name,OBJPROP_ARROWCODE,ArrowType);
          ObjectSet(indNames+name,OBJPROP_COLOR,colour);
       }               
    
    }
    
    void TrendLineCreate(string name,datetime dt1,double price1,datetime dt2,double price2,color colour=Red,int window = 0)
    {
       if (ObjectFind(indNames+name) == -1)
       {
          ObjectCreate(indNames+name,OBJ_TREND,window,dt1,price1,dt2,price2);
          ObjectSet(indNames+name,OBJPROP_COLOR,colour);
          ObjectSet(indNames+name,OBJPROP_RAY,false);
          ObjectSet(indNames+name,OBJPROP_STYLE,STYLE_DOT);
       }               
    }
    
    
    void ShowTrades()
    {
       int     cnt;
       color OpenArrowColor; 
       color CloseArrowColor; 
       
       color StopLossColor;
       color LineColor; 
       string SType = " ";
       string text;
        
       int oc = OrdersHistoryTotal();   
       for(cnt=0;cnt<oc;cnt++)
       {
          if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY) ==false) continue;
          if(OrderSymbol() != Symbol()) continue;
          
          if( OrderType()==OP_SELL )
          {
             OpenArrowColor = Red;
             CloseArrowColor = Violet;
             StopLossColor = Red;
             LineColor =  Red;
          }
          if( OrderType()==OP_BUY )
          {
             OpenArrowColor = Blue;
             CloseArrowColor = Goldenrod;
             StopLossColor = Blue;
             LineColor =  Blue;
          }
          if(OrderType() == OP_SELL) SType = "SELL";
          if(OrderType() == OP_BUY) SType = "BUY";
          
          string ticket =  DoubleToStr(OrderTicket(),0);
          double lots = NormalizeDouble(OrderLots(),2);
          double op= NormalizeDouble(OrderOpenPrice(),Digits);
          double cp = NormalizeDouble(OrderClosePrice(),Digits);     
          text = StringConcatenate("# ",OrderTicket()," ",SType," ",lots," ",OrderSymbol()," at ",op," ",cp);
          
          ArrowCreate("o "+text,OrderOpenTime(),OrderOpenPrice()," ",OpenArrowColor,1);  // --Open arrow
          ArrowCreate("c "+text,OrderCloseTime(),OrderClosePrice()," ",CloseArrowColor,3); // --close arrow
          ArrowCreate("s "+text,OrderOpenTime(),OrderStopLoss()," ",OpenArrowColor,4);  // --stop arrow
          TrendLineCreate("l " + text ,OrderOpenTime(),OrderOpenPrice(),OrderCloseTime(),OrderClosePrice(),LineColor);  // trendline
    
       }  // end for
    
    }   //end ShowTrades
    
    
    void DelTradesHis()
    {
       int     cnt;
       string SType = " ";
       string text;
       int obj_id ;
       string obj_name;
        
       int oc = OrdersHistoryTotal();   
       for(cnt=0;cnt<oc;cnt++)
       {
          if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY) ==false) continue;
          if(OrderSymbol() != Symbol()) continue;
          
          if(OrderType() == OP_SELL) SType = "SELL";
          if(OrderType() == OP_BUY) SType = "BUY";
          
          string ticket =  DoubleToStr(OrderTicket(),0);
          double lots = NormalizeDouble(OrderLots(),2);
          double op= NormalizeDouble(OrderOpenPrice(),Digits);
          double cp = NormalizeDouble(OrderClosePrice(),Digits);     
          text = StringConcatenate("# ",OrderTicket()," ",SType," ",lots," ",OrderSymbol()," at ",op," ",cp);
          
          obj_name = "o "+text;
          obj_id = ObjectFind(obj_name); 
          if(obj_id!=-1) ObjectDelete(obj_name); // --Open arrow
    
          obj_name = "c "+text;
          obj_id = ObjectFind(obj_name); 
          if(obj_id!=-1) ObjectDelete(obj_name); // --close arrow
          
          obj_name = "s "+text;
          obj_id = ObjectFind(obj_name); 
          if(obj_id!=-1) ObjectDelete(obj_name); // --stop arrow
    
          obj_name = "l "+text;
          obj_id = ObjectFind(obj_name); 
          if(obj_id!=-1) ObjectDelete(obj_name); // --trendline
         
    
    
       }  // end for
    
    }   //end ShowTrades
    
    
     
  6. 学习学习,谢谢
     
  7. nix

    nix

    ? 下订单的时候,有颜色参数的呀,自动画出来的吧
     
  8. 由EA来开仓,是可以设置颜色参数,自动画出来。但手工交易时,是不会有历史开平仓的信号在图表中,说的就是这个意思吧。
     
  9. 兄弟大才
    我后来自己写了一个在用
    今天回过来看到此贴,用了一下你的指标
    比我写的好,还显示了止盈止损线,强
    谢谢兄台
    不知有无QQ?想与兄台保持联系,继续请教。
     
  10. 这个指标有的!
     
  11. 有一些自定义指标有这个功能。
     
  12. 好东西
     
  13. 如果我想用csv格式导入历史交易,应该如何操作?

    多谢!