追踪止损和追踪利润 - 页 5

 
Arav007:


第三笔交易的TP=108.536 [我把这个TP设置在这样的距离上,因此它将像没有TP一样工作] 。

现在,按照我的要求,当价格在7个点[103.603]的利润时,第一笔和第二笔交易的止损将变成1个点的利润[103.543],第三笔交易的止损将变成1个点的利润。

第1次和第2次交易的止损将变成1点利润[103.543],第3次交易的止损将保持在103.386。

就像下面的图片一样。

第一笔GBPUSD订单以10点利润平仓。

第二笔订单仍在运行,它的止损点被移动。

第三笔交易的止损也被移动了,我不希望这样。

BuyOrder_3=OrderSend(Symbol(), iOrderType_Buy, LotSize,OpenPrice,Slippage,dStopLossPrice,0, "Buy Order",MagicNumber, 0,Blue);//tp 0
 
deVries:


谢谢。这是另一种方法,确实是设置无TP的好方法。

但是,SL怎么办?我怎样才能在没有变量订单票 的情况下做到这一点呢?

请注意

 
if(OrdersTotal()>0){
 

for(cnt=OrdersTotal()-1;cnt>=0;cnt--){
        
        if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
        if(OrderSymbol() == Symbol() && OrderMagicNumber() ==  MagicNumber){
                
        
                sl     = OrderStopLoss(); // Stop Loss. 
                tStopLoss = NormalizeDouble(OrderStopLoss(), Digits); // Stop Loss. 
                
                if(OrderType()==OP_BUY){

if (OrdersTotal()==3){

if (cnt==1){

Fixed Stop Loss

}

else{

Trailing Stop Loss

}

}    // end of  if (OrdersTotal()==3)

else{    // Looking for 2nd option                           

if (OrdersTotal()==2){                           // 10 pips TP trade can be closed already

if(cnt== 0){

Fixed Stop Loss

}

else{

Trailing Stop Loss

}

}  // End of  if (OrdersTotal()==2)

}  // End of  else

 

你对此有何看法?这样做对止损 部分可以吗?

 
Arav007:

你对此有何看法?这样做对止损部分可以吗?


不,这是不对的

但我更不喜欢的是我的阅读方式

这是不可读的编码,你在这里改变你的风格,写你的代码 !!!!

不需要空行,这和你的一样

你能像这样做吗?

if(OrdersTotal()>0)
   {
   for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
     {
     if(!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
     if(OrderSymbol() == Symbol() && OrderMagicNumber() ==  MagicNumber)
        {
        sl     = OrderStopLoss(); // Stop Loss. 
        tStopLoss = NormalizeDouble(OrderStopLoss(), Digits); // Stop Loss. 
        if(OrderType()==OP_BUY)
           {
           if (OrdersTotal()==3) 
              {
              if (cnt==1)
                 {
                 Fixed Stop Loss     
                 }
               else{
                   Trailing Stop Loss
                   }
              }    // end of  if (OrdersTotal()==3)
           else{    // Looking for 2nd option                           
               if (OrdersTotal()==2)
                 {                           // 10 pips TP trade can be closed already
                 if(cnt== 0)
                   {
                   Fixed Stop Loss
                   }
                   else{
                       Trailing Stop Loss
                       }
                 }  // End of  if (OrdersTotal()==2)
   }  // End of  else

没有空行

很容易看到"{"开始的地方和"}"结束的地方在代码的哪个部分。

这可能发生在你有20个以上的交易,你不能在循环中使用,如果 (OrdersTotal()========== ========)。

if(cnt==)

为什么你要做这个订单循环?

你做这个订单环路是为了逐一检查你的所有交易

你需要编写的是BreakEven的代码。

固定止损 的作用是什么????

 
deVries:


不,这是不对的

但我更不喜欢的是我的阅读方式

这是不可读的编码,你在这里改变你的风格,写你的代码 !!!!

不需要空行,这和你的一样

你能像这样做吗?

没有空行

很容易看到"{"开始的地方和"}"结束的地方在代码的哪个部分。

这可能发生在你有20个以上的交易,你不能在循环中使用,如果 (OrdersTotal()========== ========)。

if(cnt==)

为什么你要做这个订单循环?

你做这个订单环路是为了逐一检查你的所有交易

你需要编写的是BreakEven的代码。

固定止损的作用 是什么????


对不起,实际上我觉得空行更舒服。无论如何,我将在这里发布代码时遵循它。

我以为'OrdersTotal()'会从EA所连接的货币对中'只'取到订单。

但它可能会获取所有的订单,然后我们将相关的一对订单与其他订单区分开来。

通过使用这一行。

if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)

对吗?

我所说的固定止损 是指 "初始 "止损将不会移动。

谢谢

 
deVries:


改变你的风格写你的代码 !!!!

不需要空行


这是一个见仁见智的 问题,但一般 认为在编码时使用空行(在合理的地方)是好的做法。无论如何,在别人的代码中以这种方式 使用空行并不是真正值得指出的

如果你看一下Apache或Linux Kernel的源代码(两个高度合作的开放项目),你会看到大量的空行。


apache网络服务器。

AP_DECLARE_NONSTD(const char *) ap_set_string_slot(cmd_parms *cmd,
                                                   void *struct_ptr,
                                                   const char *arg)
{
    int offset = (int)(long)cmd->info;

    *(const char **)((char *)struct_ptr + offset) = arg;

    return NULL;
}

LINUX KERNEL:


static int jz4740_musb_init(struct musb *musb)
{
 musb->xceiv = usb_get_phy(USB_PHY_TYPE_USB2);
 if (!musb->xceiv) {
 pr_err("HS UDC: no transceiver configured\n");
 return -ENODEV;
 }

 /* Silicon does not implement ConfigData register.
 * Set dyn_fifo to avoid reading EP config from hardware.
 */
 musb->dyn_fifo = true;

 musb->isr = jz4740_musb_interrupt;

 return 0;
} 
 
Arav007:


有时空行是可以接受的,但如果你在每一行之后都空行就不一样了。

此外,大括号的位置使代码更容易阅读。


MACD 为例

   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         //--- long position is opened
         if(OrderType()==OP_BUY)
           {

            //--- check for trailing stop
            if(TrailingStop>0)
              {
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     //--- modify order and exit
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return;
                    }
                 }
              }
           }
         else // go to short position
           {

            //--- check for trailing stop
            if(TrailingStop>0)
              {
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     //--- modify order and exit
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return;
                    }
                 }
              }
           }
        }
     }

现在你看到了如何将货币图表的价格与你交易的订单价格进行比较

你也要做这样的事情......

 
ydrol:

这是一个见仁见智的 问题,但一般 认为在编码时使用空行(在合理的地方)是好的做法。无论如何,在其他人的代码中,以这种方式使用 空行并不是真正值得指出的事情

如果你看一下Apache或Linux Kernel的源代码(两个高度合作的开放项目),你会看到大量的空行。


apache网络服务器。

Linux KERNEL。

关键是每写一行都是空行

你要不断地向上/向下滚动来阅读 大的代码,就会变得很难。

当没有逻辑地放置{ }时,就更难发现错误了。

 
deVries:


从MACD来作为例子

现在你看到了如何将货币图表的价格与你交易的订单价格进行比较

你也要做这样的事情......


我有这样的价格比较功能。

我怎样才能像选择订单的魔法号码一样,比较OrderSend()中选择订单的'评论'?

例如,如果我想验证OrderComment()是否与所选订单的评论相符?

SellOrder=OrderSend(Symbol(), iOrderType_Sell, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice, "Sell Order",MagicNumber, 0,Red)。

现在我是否可以像这样进行比较。

OrderComment()=="卖出订单" // ?

我还可以这样定义OrderSend()函数 的注释。

string comment_sell="Sell Order"。

SellOrder=OrderSend(Symbol(), iOrderType_Sell, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice, comment_sell ,MagicNumber, 0,Red)。

然后再进行比较:

如果(OrderComment()=="comment_sell")// ?

注意

 
Arav007:


我有这样的价格比较功能。

我怎样才能像比较所选订单的魔法号码一样比较OrderSend()的所选订单的'评论'?

例如,如果我想验证OrderComment()是否与所选订单的评论相符?

SellOrder=OrderSend(Symbol(), iOrderType_Sell, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice, "Sell Order",MagicNumber, 0,Red)。

现在我是否可以像这样进行比较。

OrderComment()=="卖单" // ?

我还可以这样定义OrderSend()函数的注释。

string comment_sell="Sell Order"。

SellOrder=OrderSend(Symbol(), iOrderType_Sell, LotSize,OpenPrice,Slippage,dStopLossPrice,dTakeProfitPrice, comment_sell ,MagicNumber, 0,Red)。

然后再进行比较:

如果(OrderComment()=="comment_sell")// ?

注意


OrderComment可以被你的经纪人覆盖。

你要的是...现在,按照我的要求,当价格达到7点[103.603]的利润时,第一笔和第二笔交易的止损 将变成1点利润[103.603]。

第1次和第2次交易的止损将变成1点利润[103.543],第3次交易的止损将保持在103.386。

使得extern int BreakEven = 7

         if(OrderType()==OP_BUY)
           {

            //--- check for BreakEven
            if(BreakEven>0)
              {
               if(Bid-OrderOpenPrice()>Point(*10)*BreakEven)
                 {
                  if(OrderStopLoss()<OrderOpenPrice())
                    {
                     //--- modify order
                     if(OrderTakeProfit()>Point)OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+Point(*10),OrderTakeProfit(),0,Green);
                    }
                 }
              }
           }

(*10)在5位数的经纪人处修正,以获得点值

原因: