关闭半数地段。 - 页 7

 
  if(OrderSelect(OrdersTotal(),SELECT_BY_TICKET,MODE_TRADES)==true && OpenOrdersThisPair(Symbol())==1 && OrderType()==OP_BUY){ // Even though I am calling "OP_BUY" here, it doesn't seem to work?
         
         }
         double minLot  = MarketInfo(Symbol(), MODE_MINLOT);
                {
                Print("The minimum lots are: ", DoubleToStr( minLot, Digits ));
                }
                        
         double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
                {
                Print("The Lotstep is: ", DoubleToStr( lotStep, Digits ));
                }
                
         double half    = MathCeil(OrderLots()/2/lotStep)*lotStep;
                {
                Print("The Lots to close is: ", DoubleToStr( half, Digits ));
                }
      
      for( int c=OrdersTotal()-1; c >=0; c-- )
      {
         if(OrderSelect(c,SELECT_BY_POS,MODE_TRADES)==true)
            {
            Print("Order Ticker Number = ",OrderTicket());
            Print("Order Lots Open = ", OrderLots());
            } 
         else{
           Print("Order Select returned the error of ", GetLastError()); // Order Select does not seem to want to work?
            continue;
            }
            
           double FirstTarget_Buy = OrderOpenPrice() + ( ( OrderTakeProfit()-OrderOpenPrice() ) / 2 );
           {
           Print("FirstTarget_Buy: ", DoubleToStr( FirstTarget_Buy, Digits ));
           }
            if(OrderMagicNumber()==MagicNumber)
              if(OrderSymbol()==Symbol())
                
               Print("Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                if(OrderType()==OP_BUY && Bid >= FirstTarget_Buy +(Point / 2))
                  {
                  Print("Bid >= FirstTarget_Buy - Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                  bool Close_Half_Order_Buy = OrderClose(OrderTicket(),half,Bid,3,CLR_NONE);
                  if(Close_Half_Order_Buy!=TRUE)Print("Close_Half_Order_Buy Last Error = ", GetLastError());
                  }

         } 
   }
     
我知道它有点邋遢!我一直在玩弄它的负荷--所以赶紧把它放回我们说话的地方?我想你是指这整个部分,对吗?
 
   if (direction==0){ //--Buy--//
      
      double bsl=buy_stop_price;
      double btp=buy_takeprofit_price;
      LotSize = (RiskedAmount/(pips_to_bsl/pips))/10;
      
      if(OpenOrdersThisPair(Symbol())==0){
         int BuyTicketOrder = OrderSend(Symbol(),OP_BUYSTOP,LotSize,buyPrice,3,bsl,btp,NULL,MagicNumber,0,Green); // This puts out the initial order.
      }
      
         if(OrderStopLoss()<iMA(NULL,0,MA_Period,0,1,0,0)-MA_PadAmount*pips){// This triggers the For loop if the pending order needs adjusting relative to where the MA is.
         
               for(int b=OrdersTotal()-1; b >=0; b--) 
                  {
    
                     if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)==true){
                     Print(" Stop loss value for the order is ", OrderStopLoss());
                     }
    
                     else if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES)==false){
                     Print(" OrderSelect failed error code is ",GetLastError());
                     }
                     if(OrderMagicNumber()==MagicNumber)
                        if(OrderSymbol()==Symbol())
                           if(OrderType()==OP_BUYSTOP)
                              if(OrderStopLoss()<iMA(NULL,0,MA_Period,0,1,0,0)-MA_PadAmount*pips)
                                if(OpenOrdersThisPair(Symbol())==1) 
                                 DeleteOrder = OrderDelete(OrderTicket());
                                    if(DeleteOrder!=TRUE)Print("DeleteOrder Last Error = ", GetLastError());
                                  
                                 if(OpenOrdersThisPair(Symbol())==0) 
                                  NewBuyOrder = OrderSend(Symbol(),OP_BUYSTOP,LotSize,buyPrice,3,bsl,btp,NULL,MagicNumber,0,Green); // New Pending order with calibrated stops, lots and targets.
                                   if(NewBuyOrder!=TRUE)Print("New Buy Order Last Error = ", GetLastError());  // This is giving me an "Error 0", despite the trade ACTUALLY being placed correctly...?   

                  }
                 } 
             
               if(NewBuyOrder == true){
               Print("New Buy Order Placed #", NewBuyOrder);
               }
               else{
               Print("New Buy Order Send Failed, error # ", GetLastError());   
               }
               }
这是购买部分--只是吐出一个 "OP_BUYSTOP"。
 
DomGilberto:
我知道它有点邋遢。我一直在玩弄它,所以赶紧把它放回我们刚才说的地方?我想你是指这整个部分,对吗?

呃 . . . 你需要退后一步,深呼吸,仔细阅读你的代码,逐个功能,逐行阅读 . . . 问自己 "我想在这里做什么?",然后检查你的代码是否要做到这一点 . . . 例如。

  if(OrderSelect(OrdersTotal(), SELECT_BY_TICKET,   MODE_TRADES)==true && OpenOrdersThisPair(Symbol())==1 && OrderType()==OP_BUY)

         { // Even though I am calling "OP_BUY" here, it doesn't seem to work?
         
         }

这个if测试执行一个注释,如果它是真的????暂时不考虑这个问题。.OrdersTotal()怎么会是一个票号?如果你用SELECT_BY_TICKET,它甚至不是一个有效的位置。


我不认为这段代码是你的问题所在 ...... 尽管它有一些问题。

 

是的--好地方,虽然说实话,这并没有任何实质性的区别。

Hmmm....

 
DomGilberto:

是的--好地方,虽然说实话,这并没有任何实质性的区别。

Hmmm....

不,它没有......。

RaptorUK:


我不认为这段代码是给你带来问题的原因 ...... 尽管它有一些问题。

我不认为你展示的是产生问题的代码 ......。

 
DomGilberto:
这是购买部分--只是吐出了一个 "OP_BUYSTOP"

这 . . .

if(OpenOrdersThisPair(Symbol())==0) 
   NewBuyOrder = OrderSend(Symbol(),OP_BUYSTOP,LotSize,buyPrice,3,bsl,btp,NULL,MagicNumber,0,Green); // New Pending order with calibrated stops, lots and targets.

if(NewBuyOrder!=TRUE)Print("New Buy Order Last Error = ", GetLastError());  // This is giving me an "Error 0", despite the trade ACTUALLY being placed correctly...? 

. . . 是{} 大括号的问题 . .

if(OpenOrdersThisPair(Symbol())==0) 
   {
   NewBuyOrder = OrderSend(Symbol(),OP_BUYSTOP,LotSize,buyPrice,3,bsl,btp,NULL,MagicNumber,0,Green); // New Pending order with calibrated stops, lots and targets.

   if(NewBuyOrder != TRUE)Print("New Buy Order Last Error = ", GetLastError());  // This is giving me an "Error 0", despite the trade ACTUALLY being placed correctly...? 
   }

对你的缩进进行分类,你会很快 "看到 "这些问题。

 
是的,再一次很好的呼喊,我已经通过并整理了一些缩进的问题......但仍然停留在相同的问题上?你认为这可能是什么其他代码?我无法想象它来自我编码的任何其他部分...?
 
if(OrderSelect(OrdersTotal(),SELECT_BY_POS,MODE_TRADES)==true && OpenOrdersThisPair(Symbol())==1) // If I put "OrderType() == OP_BUY" it won't work at all. This means that it could just grab a pending order - which is wrong.
  { 
         
         
         double minLot  = MarketInfo(Symbol(), MODE_MINLOT);
                {
                Print("The minimum lots are: ", DoubleToStr( minLot, Digits ));
                }
                        
         double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
                {
                Print("The Lotstep is: ", DoubleToStr( lotStep, Digits ));
                }
                
         double half    = MathCeil(OrderLots()/2/lotStep)*lotStep;
                {
                Print("The Lots to close is: ", DoubleToStr( half, Digits ));
                }
      
    for( int c=OrdersTotal()-1; c >=0; c-- )
      {
         if(OrderSelect(c,SELECT_BY_POS,MODE_TRADES)==true)
            {
            Print("Order Ticker Number = ",OrderTicket());
            Print("Order Lots Open = ", OrderLots());
            } 
         else{
           Print("Order Select returned the error of ", GetLastError()); 
           continue;
           }

           double FirstTarget_Buy = OrderOpenPrice() + ( ( OrderTakeProfit()-OrderOpenPrice() ) / 2 );
           {
           Print("FirstTarget_Buy: ", DoubleToStr( FirstTarget_Buy, Digits ));
           }
            
            if(OrderMagicNumber()==MagicNumber)
              if(OrderSymbol()==Symbol())
                
               Print("Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                
                if(OrderType()==OP_BUY && Bid >= FirstTarget_Buy +(Point / 2)) // Does not go further than this. I do not get an error from OrderClose?
                  {
                  Print("Bid >= FirstTarget_Buy - Current Bid: ", DoubleToStr(Bid, Digits), " FirstTarget_Buy: ", DoubleToStr(FirstTarget_Buy, Digits)  );
                  bool Close_Half_Order_Buy = OrderClose(OrderTicket(),half,Bid,3,CLR_NONE);
                  if(Close_Half_Order_Buy!=TRUE)Print("Close_Half_Order_Buy Last Error = ", GetLastError());
                  }
                   
       } 
   }
我被卡住了--我已经尝试了很多转变和改变,现在一定是遗漏了一些我不知道存在的东西......一定是这样吗?OrderType()==OP_BUY似乎不起作用?请看上面代码中的注释--我已经检查了 缩进...这真是史诗级的!哈哈...
 
DomGilberto:
是的,再一次很好的呼喊,我已经通过并整理了一些缩进的问题......但仍然停留在相同的问题上?你认为这可能是什么其他代码?我无法想象它来自我编码的任何其他部分...?
大笑,我不知道,我还没有看到全部......但当你有一个OP_BUY的时候,有些东西阻止了执行打印的代码的运行。
 
2013.08.02 10:52:47	2013.02.01 15:00  trendfishing_play_ground EURUSD,H1: NEW BUY ORDER:-  Lots to open: 0.18215 Entry Price: 1.36790 Buy Stop Loss: 1.35649 Buy Take Profit: 1.39072 Magic Number is: 1234.00000

在我的for循环中,在买入止损单的情况下,如果60EMA大于OrderStopLoss,它将关闭挂单,用新的SL(在60EMA后面)打开一个新的订单,调整止盈以 获得1:2的回报,并改变相对于止损点的手数和我的风险状况(例如2%)。

因此,当这一切都在进行时,"当前手数 "也就是OrderSend中的 "LotSize "自定义变量是有效的,但它发送的手数对服务器来说是不正确的?"0.18215"?这可能是一个问题,尽管订单实际上是通过发送的 - 这个问题更多的是与 "这可能是我不能调用 "OrderType==OP_BUY "的原因有关?

这是个漫长的过程......。