意见--非常成功的EA--3000美元的账户在两周内升至6300美元(本来可以升至9000美元)。 - 页 5

 

在我去工作之前,有一件事很重要,有一些布尔变量可以是真或假。

我很难相信你是按照书上说的做的。

 
zzuegg:

在我去工作之前,有一件事很重要,有一些布尔变量可以是真或假。

我很难相信你是按照书上说的做的。

我正在努力。我同时在学习交易+程序+MQL。

你只看书就能学会驾驶汽车吗?

但谢谢你

 
MickGlancy:

我得到的错误是OpenBuyOrder和OpenSellOrder函数没有返回结果。

我做错了什么?

你得到这个错误是因为OpenBuyOrder()和OpenSellOrder()函数 实际上不返回结果。你把它们定义为void, 意味着它们不返回任何参数,但你却试图返回一个整数(0)。

下面是带有一些评论的代码。

void OpenBuyOrder( double StopLoss, double TakeProfit )
{
         int Ticket;			
         double SL,TP,SLP,TPP,OPP;
         
         if(HideSL==false && StopLoss>0){SL=Ask-StopLoss*Point;}
         else {SL=0;}
         
         if(SL>0 && SL>(Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)){SL=Bid-MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;}
         
         if(HideTP==false && TakeProfit>0){TP=Ask+TakeProfit*Point;}
         else {TP=0;}
         
         Ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,EAName,Magic,0,Blue);	//-- this stores the value for Ticket, but it never gets used.. 
                                                                                        //-- you can simply call OrderSend() without storing the result 

   return;    //--- void means the function returns no argument.. thus, no parentheses for return
}

void OpenSellOrder( double StopLoss, double TakeProfit)
{
         int Ticket;
         double SL,TP,SLP,TPP,OPP;
         
         if(HideSL==false && StopLoss>0){SL=Bid+StopLoss*Point;}
         else {SL=0;}
         
         if(SL>0 && SL<(Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point)){SL=Ask+MarketInfo(Symbol(),MODE_STOPLEVEL)*Point;}
         
         if(HideTP==false && TakeProfit>0){TP=Bid-TakeProfit*Point;}
         else {TP=0;/*TPP=0;*/}
         
         Ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,EAName,Magic,0,Red);
         
    return; 
}

根据你的GetSignal函数,你似乎想用OpenBuy/SellOrder()来打开一个订单,而不是实际返回一些参数。 我用一些注释对你的GetSignal()函数进行了清理

void GetSignal(int MaxBuyOrders, double StopLoss, double TakeProfit) 		//--- Why make this function a bool??
{
   int Op_Buy,Op_Sell,Op_BuyStop,Op_SellStop,Op_BuyLimit,Op_SellLimit;
        
   int total = OrdersTotal();
  
   for(int x=total-1; x>=0; x--)
   {
      OrderSelect(x, SELECT_BY_POS, MODE_TRADES);
      int type   = OrderType();
      bool result = false;    //-- not used anywhere??
      
      if (type==OP_BUY)       Op_Buy++;
      if (type==OP_SELL)      Op_Sell++;
      if (type==OP_BUYSTOP)   Op_BuyStop++;
      if (type==OP_SELLSTOP)  Op_SellStop++;         
   }
  
   int limit=1;		        //--- why define limit to 1 
   for(int i=1;i<=limit;i++)    //--- your for-loop will always run once, in which case why even have a for-loop?
   {
      double MA1=iMA(NULL,0,100,0,1,0,0);
      double MA2=iMA(NULL,0,100,0,1,0,1);
      double MA3=iMA(NULL,0,40,0,1,0,0);
      double MA4=iMA(NULL,0,40,0,1,0,1);
      
      bool BUY=false;   //-- as one guy mentioned better to go with booleans here
      bool SELL=false;

      if(MA1 < MA3 && MA2 > MA4) BUY=true;  
      if(MA1 > MA3 && MA2 < MA4) SELL=true;
      // missed out  && total == 0 for now
      bool SignalBUY=false;
      bool SignalSELL=false;
      
      if(BUY) //-- dont need to write == for bool's ..BUY is same as BUY==true, !BUY same as BUY==false
      if(ReverseSystem) SignalSELL=true;
      else SignalBUY=true;
      
      if(SELL)
      if(ReverseSystem) SignalBUY=true;
      else SignalSELL=true;
      
      if (SignalBUY && Op_Buy < MaxBuyOrders )   OpenBuyOrder(StopLoss,TakeProfit); 	//--- no need to return the return of OpenBuyOrder().. simply calling it will run the code
      if (SignalSELL && Op_Sell < MaxSellOrders) OpenSellOrder(StopLoss,TakeProfit);	//-- same
   }
   return;
}
 
supertrade:

你得到这个错误是因为OpenBuyOrder()和OpenSellOrder()函数实际上不返回结果。你把它们定义为void, 意味着它们不返回任何参数,但你却试图返回一个整数(0)。

下面是带有一些评论的代码。

根据你的GetSignal函数,你似乎想用OpenBuy/SellOrder()来打开一个订单,而不是实际返回一些参数。 我用一些注释对你的GetSignal()函数进行了一些清理

这说明了问题,非常感谢你,我现在正在尝试。

我自己的代码有点乱,因为我基本上是抄袭其他的EA,并试图使其发挥作用。

 
没问题......如果你遇到其他问题,随时可以问。
 
void MoveTrailingStop()
{
   int cnt,total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL  &&  OrderSymbol()==Symbol() ) //&&  OrderMagicNumber()==Magic
      {
         if(OrderType()==OP_BUY)
         {
            if(TrailingStop>0)  
            {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-Point*(TrailingStop+TrailingStep),Digits)) || (OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue);
                  return(0);
               }
            }
         }
         else 
         {
            if(TrailingStop>0)  
            {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+Point*(TrailingStop+TrailingStep),Digits)))||(OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red);
                  return(0);
               }
            }
         }
      }
   }
}
supertrade
:

没问题......如果你遇到其他问题,请随时提问。

我收集了很多跟踪止损的例子,但我需要一个立即开始跟踪,通过-V值到0,然后像收支平衡一样停止。

因此,如果入市价格为100,止损 为100,如果价格移动到+25,跟踪止损移动到-75,然后一旦价格达到100,跟踪止损就停在0,不再移动。

谁能帮我解决这个问题?我已经花了一整天的时间试图让它工作,但我就是做不到。

我想我已经做到了,但我没有,我的追踪止损在0处。

 

伪装代码。

OrderSelect()

if (Buyorder and stoploss < openrice) : we need to trail
if (Sellorder and stoploss > openprice): we need to trail
if (we need to trail):
Modify Stoploss to Currentprice (+ or -) original stoploss
 

zzuegg:

如果(Buyorder and stoploss < openrice):我们需要跟踪。

止损 是否总是低于openprice,反之亦然?

我打算最终使用MaxLoss函数,所以我不会在OrderSend中设置止损。

如果Op_Buy

if bid <= OpenOrderPrice()+(Trailing stop value) : trail -- 一旦bid > TSV,就不应该继续移动?

如果Op_Sell

If ask >= OpenOrderPrice()-(Trailing stop value): trail ?

然后在高于追踪止损值时,平衡点可以完成工作 ?

 OrderSelect(SELECT_BY_POS,MODE_TRADES);
   if(TrailingStop>0)
      {
      if(OrderType()==OP_BUY)
            {
            if ( Bid <= (OrderOpenPrice()+Point*TrailingStop)  )
               {
                  MoveTrailingStop();
               }
            }
      if(OrderType()==OP_SELL)
            {   
            if ( Ask >= (OrderOpenPrice()-Point*TrailingStop) )
               {
                  MoveTrailingStop();
               }
            }
      }
BTW thanks zzuegg, thats another order management milestone achieved. What can happen with a little help. I am gratefull.
 
MickGlancy:

zzuegg:

如果(Buyorder and stoploss < openrice):我们需要跟踪。

止损是否总是低于开盘价,反之亦然? 不,只有在盈亏平衡之前

我认为你的代码不起作用,似乎你试图做相反的事情......
 
zzuegg:
我不认为你的代码有效,似乎你试图做相反的事情......

不,它正在完美地工作。让我检查一下,现在的情况和那个答复中的情况一样。

这是我能得到的最接近的妥协,即关闭移动交易背后的亏损缺口,但仍给它以呼吸空间。在这之前,交易必须达到60点才会发生BE,所以有很多最大止损的交易,这导致我的缩减很高。希望这能改变这种情况。

OrderSelect(SELECT_BY_POS,MODE_TRADES);
   if(TrailingStop>0)
      {
      if(OrderType()==OP_BUY)
            {
            if ( Bid <= (OrderOpenPrice()+Point*TrailingStop)  )
               {
                  MoveTrailingStop();
               }
            }
      if(OrderType()==OP_SELL)
            {   
            if ( Ask >= (OrderOpenPrice()-Point*TrailingStop) )
               {
                  MoveTrailingStop();
               }
            }
      }