iCustom()缓冲区 - 如何从MT4中的自定义指标缓冲区获取值?

时间:2017-07-18 17:11:47

标签: algorithmic-trading mql4 metatrader4 mt4

当我的自定义指标显示箭头{卖出或买入}时,我正在尝试编写一个可以进行买入的EA。我使用 iCustom() 来做到这一点,但我在努力比较价值。

这是我的代码:



void OnTick()
  {
//---
       double sell=iCustom(NULL,0,"fx30",0,0);
       double buy=iCustom(NULL,0,"fx30",1,0);
       
       if(sell>0)//sell
       {
        //check if buy trade is running
        //close a buy trade
        //open a sell trade on success
         if(buyTicket>0)
          {
            bool ret=OrderClose(buyTicket, lot, Bid, slipage,clrBlue);
            if(ret==true)
              {
                printf("the sell number is: "+sell);
                sellTicket=OrderSend(Symbol(),OP_SELL,lot,Bid,slipage,NULL,NULL,"MATHUNYA SELL",magic,0,clrRed);
              }
          }
         else
         {
           //we dont have a buy trade open
           //place a sell trade
           //only one trade should be open
           if(sellTicket>0)
           {
             printf("sell order already running");
           }
           else
           {
             printf("the sell number is: "+sell);
             sellTicket=OrderSend(Symbol(),OP_SELL,lot,Bid,slipage,NULL,NULL,"MATHUNYA SELL",magic,0,clrRed);
           }     
         }            
       }
       else{
         Print("buy: "+buy+", sell: "+sell+" Time: "+TimeToStr(Time[1]));
         printf("awaiting sell order..");
       }
       
       if(buy>0)//buy
       {
       //check if sell trade is running
       //close a sell trade
       //open a buy trade on success
         if(sellTicket>0)
          {
            bool ret=OrderClose(sellTicket, lot, Ask, slipage,clrYellow);
            if(ret==true)
              {
                printf("the buy number is: "+buy);
                buyTicket=OrderSend(Symbol(),OP_BUY,lot,Ask,slipage,NULL,NULL,"MATHUNYA BUY",magic,0,clrGreen);
              }
          }
         else
         {
           //we dont have a sell trade open
           //place a buy trade
           //only one trade should be open
           if(buyTicket>0)
           {
             printf("buy order already running");
           }
           else
           {
              printf("the buy number is: "+buy);
              buyTicket=OrderSend(Symbol(),OP_BUY,lot,Ask,slipage,NULL,NULL,"MATHUNYA BUY",magic,0,clrGreen);
           }     
         }          
       }else
       {
         Print("buy: "+buy+", sell: "+sell+" Time: "+TimeToStr(Time[1]));
         printf("awaiting buy order..");
       }
      
  }
//+------------------------------------------------------------------+




// global variables

int    buyTicket  =   0;
int    sellTicket =   0;
double lot        =   0.01;
int    slipage    =   3;
int    magic      = 321;

1 个答案:

答案 0 :(得分:0)

比较价值是什么意思?我可以看到,您只比较sell>0buy>0。我的建议:紧接着比较添加线
Print(__LINE__," indicator value = "+DoubleToStr(sell,Digits));buy相同。很可能,但当然我们这里没有水晶球,你的指标在一个缓冲区上返回值(例如100或1.16000),在另一个缓冲区上返回EMPTY_VALUE。 EMPTY_VALUE在mql4中是2 ^ 31-1所以它大于零。 如果您将看到指标值为2147483648.00000或类似情况,则需要将sell > 0替换为sell != EMPTY_VALUE或合并。