检查开放交易的问题 - 页 5

 
BrotherPyrus:
嘿,Daz & Co,

hothand在五位数的MT4平台上工作,但在四位数的平台上不工作。
你能更具体地说明它是如何不工作的吗?
 
BrotherPyrus:
hothand在五位数的MT4上可以工作,但在四位数的平台上却不行。知道是什么原因造成的吗,有什么线索可以解决这个问题?
EA必须调整4/5位数,TP,SL,和滑点。在ECN经纪商,你必须先开仓,然后再设置止损。
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.0015      0.00150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){
    if (Digits == 5 || Digits == 3){    // Adjust for five (5) digit brokers.
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
 
   if(iBarHour >= iOpenHour && iBarHour <= iOpenHour + iBarsToTrade && Tradeopen()==false) // Check if time is ok to trade & no trade is open
                  {

                          
                              //  if(High[2]>High[1] && Low[2]<Low[1]) // see if we have an inside bar
                                if(iHigh(hothand(), 60, 2)>iHigh(hothand(), 60, 1) && iLow(hothand(), 60, 2) < iLow(hothand(), 60, 1)) // see if we have an inside bar
                                 {                                                                                                     // on the hothand pair
                                           
                                        // IB found 
                                        if(iHigh(hothand(), 60, 1) > dDayOpenPrice) // IB high on hothand pair is greater than day open price bullish signal
                                          {
                                             int    buyspread=MarketInfo(hothand(),MODE_SPREAD);
                              double buyentry =  iHigh(hothand(), 60, 1) + 10 + buyspread;  //Low of prev bar + 1 pip + spread
                              double buystop = iLow(hothand(), 60, 1) - 10;    //Low of prev bar - 1 pip
                              double buytpx1 = iHigh(hothand(), 60, 1)+(iHigh(hothand(), 60, 1)-iLow(hothand(), 60, 1)); //1:1 r:r
                              double buytpx3 = iHigh(hothand(), 60, 1)+(iHigh(hothand(), 60, 1)-iLow(hothand(), 60, 1))*3; // 1:3 r:r
                              
                              
                           OrderSend(Symbol(),OP_BUY,1 , Ask, 3, buystop, buytpx1, "DIBSBUY", Mnumber1);  //Open buy order
                           OrderSend(Symbol(),OP_BUY,1 , Ask, 3, buystop, buytpx3, "DIBSBUY", Mnumber3);
                            }
                            
                         if(iLow(hothand(), 60, 1) < dDayOpenPrice) // IB low on hothand pair is lower than day open price bearish signal
                            {
                              int    sellspread=MarketInfo(hothand(),MODE_SPREAD);
                              double sellentry = iLow(hothand(), 60, 1)-10; //Low of prev bar - 1 pip 
                              double sellstop = iHigh(hothand(), 60, 1)+ 10 + sellspread; // High of prev bar + 1 pip + Spread
                              double selltpx1 = iLow(hothand(), 60, 1)-(iHigh(hothand(), 60, 1)- iLow(hothand(), 60, 1)); //1:1 r:r
                              double selltpx3 = iLow(hothand(), 60, 1)-(iHigh(hothand(), 60, 1)- iLow(hothand(), 60, 1))*3; // 1:3 r:r
                              
                              
                           OrderSend(Symbol(),OP_SELL,1 , Ask, 3, sellstop, selltpx1,"DIBSSELL",Mnumber1);  //Open Sell Order
                           OrderSend(Symbol(),OP_SELL,1 , Ask, 3, sellstop, selltpx3,"DIBSSELL",Mnumber3);  //Open Sell Order
               
                                      } 
                        }
                               
                   }
     //  
  
    
      }

好了,我回来了。


这是我的代码中执行交易的部分,目前我只打算用5位数工作。这里的想法是我用我的hothand函数来选择哪一对是当天最好的交易。这段代码应该扫描1小时图上的内杠。(hothand函数返回一个货币对的字符串)当它找到一个内杠时,我只是让它为测试目的开出一个平仓买入或卖出交易。我不确定回测器 是否能处理一个图表中的多个货币对交易?我下载了它使用的所有货币对的1分钟历史。但它似乎只在金牛座上打开交易,也就是我所附的图表。

WHRoeder也感谢你的到来并再次提供帮助。那么,用EA开立交易的正确方法是先开立,然后在开立后再去填入sl和tp?我相信你也能发现这段代码有很多问题。

 
  1. OrderSend(Symbol(),OP_BUY,1 , Ask, 3, buystop, buytpx1, "DIBSBUY", Mnumber1);  //Open buy order
    

    不调整4/5位数的滑移量。不兼容ECN

    总是测试返回代码,这样你就能找到它不工作的原因。

    int ticket = OrderSend(Symbol(),OP_BUY,1 , Ask, 3, buystop, buytpx1, "DIBSBUY", Mnumber1);  //Open buy order
    if (ticket < 0) Alert("OrderSend [1] failed: ",GetLastError());

  2. buystop = iLow(hothand()...
    你的止损是基于hothand()对,但你是用Symbol()开的单。如果它们不一样,止损就完全是假的。
 
dazamate:

好了,我回来了。


这是我的代码中执行交易的部分,目前我只打算用5位数工作。这里的想法是我用我的hothand函数来选择哪一对是当天最好的交易。这段代码应该扫描1小时图上的内杠。(hothand函数返回一个货币对的字符串)当它找到一个内杠时,我只是让它为测试目的开出一个平仓买入或卖出交易。我不确定回测器是否能处理一个图表中的多个货币对交易?我下载了它使用的所有货币对的1分钟历史。但它似乎只在金牛座上打开交易,也就是我所附的图表。


一些一般性的评论:

,你在Ask 买入并在Bid 卖出。

如果你的经纪人是ECN类型的经纪人,你不能在下单时设置SL和TP(在这种情况下,将它们设置为0),你必须先下单,然后修改订单,添加SL和TP

始终检查 下单的结果,并检查返回的错误,你将需要通过相应的行动来处理这些错误。

如果你打算在多个图表上使用这个EA,即从多个图表下单,你将需要某种Mutex来避免Order Context Busy(查看WHRoeder的帖子,他有一个优秀的Mutex)。

 
Damm WHRoeder,你是对的,"我们的止损是基于对hothand(),但你是用Symbol()开的单 "我没有注意到这一点。多么愚蠢。当你试图学习的时候,这些东西就会让你精神疲劳。但是,是的,很愚蠢。谢谢你把这些乱七八糟的东西翻出来。我可能会休息一下,明天再来,我的头脑会很清醒。我会把你指出的那些东西改好的。
 
dazamate:

但它似乎只在金牛座上打开交易,也就是我所附的图表。

是的,.. .

OrderSend(Symbol(),OP_SELL,1 , Ask, 3, sellstop, selltpx1,"DIBSSELL",Mnumber1);  //Open Sell Order

Symbol()是EA/Indicator所连接的货币对,你是想用这个来代替吗?

OrderSend(hothand(),OP_SELL,1 , Ask, 3, sellstop, selltpx1,"DIBSSELL",Mnumber1);  //Open Sell Order
 

是的,我确实想这么做,但现在我得到了这个错误


http://clip2net.com/s/144hq


好像它不能识别hothand函数 的配对输出。hothand函数的输出是一个字符串,所以我不明白它为什么不能工作。

 
dazamate:
就像它不承认hothand函数的配对输出。hothand函数的输出是一个字符串,所以我不明白它为什么不能工作。
OrderSend(hothand(),OP_SELL,1 , Ask, 3, sellstop, selltpx1,"DIBSSELL",Mnumber1);  //Open Sell Order
  1. Ask/Bid是当前的Symbol()价格,但你试图打开另一个交易。虚假的价格。
  2. 你无法从测试器中获得 其他TF/货币对的条形 零值
  3. 你不能在测试器中打开其他货币对的交易,IIRC
  4. 在OrderSend功能中,符号名称USDCHF未知。
    你从哪里得到这个字符串?当前的图表是相同的模式,还是美元、欧元,还是美元/欧元,还是美元/欧元m,还是美元/欧元fxf等等。
  5. 我建议你只交易当前的货币对。如果hothand()不是当前的,就没有交易。这样它在测试中就能发挥作用,你可以随时把EA放在其他货币对上,从而控制它交易的货币对,而且你可以避免所有的陷阱。
 

嘿,伙计们,我正试图编写一些代码,做以下工作


extern string  sComment4                = "Max Hours allowed before pending orders are deleted";
extern int     pendinglimit        = 4;

// * EVERYTIME A TRADE GETS TRIGGERED 

bartraded = TimeHour(TimeCurrent());


// DELETE PENDING ORDERS THAT HAVE NOT BEEN TRIGGERED WITHIN 

   if(TimeHour(TimeCurrent()) > bartraded + pendinglimit && Tradeopen()==true) // Check to see if pending orders have expired
     {
        for(int tnumber = OrdersTotal()-1; tnumber >= 0 ; tnumber--)  //scan through open orders
        {
          if (OrderSelect(tnumber, SELECT_BY_POS) &&   
           OrderType()==(OP_BUYSTOP||OP_SELLSTOP) &&     // The order selected is either a pending buy on stop order or a buy on sell order
            OrderMagicNumber()==(Mnumber1||Mnumber3))    // The orders magic number is the same as the magic number used in this ea
          
               {
                OrderSelect(tnumber, SELECT_BY_POS);     // Select order
                OrderDelete(tnumber);                    // Delete it
               }
        }
     }

如果一个挂单 已经开了x个柱子,如果柱子数超过x,就删除它。


我的逻辑可能有问题吗?