Can't get this function to run.

 

Hello guys, I was working in an EA for binary option and i've tried to implement a martingale system. But, it doesnt work, i've tried a lot of different ways, and, couldn't get there.

Can someone tell me why is this not working?

double up[],dw[],up2[],dw2[];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
  SetIndexBuffer(0,up);
  SetIndexBuffer(1,dw);
  SetIndexBuffer(2,up2);
  SetIndexBuffer(3,dw2);
//----
   Comment("Configurações do EA - Investimento: "+IntegerToString(lots)+", Tempo de expiração: "+IntegerToString(expiracao)); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   int order, total,cnty;
   
   
   double call = iCustom(NULL,0,"MAD CNT FV Histograma+StDeviation",fper,fmode,fprice,distancia,stdevp,desvio,repaintfactor,0,false,false,false,1440,0,1);
   double put = iCustom(NULL,0,"MAD CNT FV Histograma+StDeviation",fper,fmode,fprice,distancia,stdevp,desvio,repaintfactor,0,false,false,false,1440,1,1);
   
   string bo=IntegerToString(expiracao);
   
   total=OrdersTotal();
   if(total<totaldeordens) 
   {
      for(cnty=0; cnty < totaldeordens - total;cnty++)
      {
      
      up[0]=EMPTY_VALUE;
      dw[0]=EMPTY_VALUE;
      up2[0]=EMPTY_VALUE;
      dw2[0]=EMPTY_VALUE;
         //if((cnty%2) == 0 && time0!=Time[0])
            
         if(call!=0.0)// && Open[0]>=filter)
         {
            order=OrderSend(Symbol(),OP_BUY,lots,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,Green);
            //Sleep(sleep);
            if(order==0)
               {
                  Print("Erro ao executar operação de compra: ",GetLastError());
               }
            else if(order>0)
               {
                  Print("Operação de compra executada com sucesso");
                  up[0]=1;
                  //--martin1
                     if(usamartingale==true && up[1]!=0.0 && Close[1]<Open[1])// && Open[0]>=filter)
                      {
                          order=OrderSend(Symbol(),OP_BUY,lots*multip1,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,Green);
                          if(order==0)
                          {
                              Print("Erro ao executar martingale(1) de compra: ",GetLastError());
                          }
                          else if(order>0)
                          {
                              Print("Martingale(1) de compra executada com sucesso");
                              up2[0]=1;
                              ///---martin2
                              if(usamartingale2==true && up2[1]!=0.0 && Close[1]<Open[1])// && Open[0]>=filter)
                              {
                                 order=OrderSend(Symbol(),OP_BUY,lots*multip2,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,Green);
                                 if(order==0)
                                 {
                                    Print("Erro ao executar martingale(2) de compra: ",GetLastError());
                                 }
                                 else if(order>0)
                                 {
                                    Print("Martingale(2) de compra executada com sucesso");
                                    up2[0]=0;
                                 }
                              }
                          }
                       }
                  }
          }
               
                  
         
      if(put!=0.0)// && Close[0]<=filter)
         {
            order=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,SaddleBrown);
            //Sleep(sleep);
            if(order==0)
               {
                  Print("Erro ao executar operação de venda: ",GetLastError());
               }
            else if(order>0)
               {
                  Print("Operação de venda executada com sucesso");
                  dw[0]=1;
                   ///martin1
                   if(usamartingale==true && dw[1]!=0.0 && Close[1]>Open[1])// && Close[0]<=filter)
                   {
                        order=OrderSend(Symbol(),OP_SELL,lots*multip1,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,SaddleBrown);
          
                        if(order==0)
                        {
                           Print("Erro ao executar martingale(1) de venda: ",GetLastError());
                        }
                        else if(order>0)
                        {
                           Print("Martingale(1) de venda executada com sucesso");
                           dw2[0]=1;
                           //---martin2
                            if(usamartingale2==true && dw2[1]!=0.0 && Close[1]>Open[1])// && Close[0]<=filter)
                            {
                               order=OrderSend(Symbol(),OP_SELL,lots*multip2,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,SaddleBrown);
                   
                               if(order==0)
                                {
                                    Print("Erro ao executar martingale(2) de venda: ",GetLastError());
                                }
                               else if(order>0)
                                {
                                    Print("Martingale(2) de venda executada com sucesso");
                                    dw2[0]=0;
                                }
                            }
                        }
                    }
               }
         }
//end                    
      }
   } 
   return(0);
  }

 Thanks in advance for your help guys.

 

Did you try as Indicator or Expert?

These are two different things.

If you worked that out chk custom indicator output by dropping in the print function:

int start()
  {
   int order, total,cnty;
   
   
   double call = iCustom(NULL,0,"MAD CNT FV Histograma+StDeviation",fper,fmode,fprice,distancia,stdevp,desvio,repaintfactor,0,false,false,false,1440,0,1);
   double put = iCustom(NULL,0,"MAD CNT FV Histograma+StDeviation",fper,fmode,fprice,distancia,stdevp,desvio,repaintfactor,0,false,false,false,1440,1,1);
   
   Print("CALL: ",call);
   Print("PUT: ",put);
   
   string bo=IntegerToString(expiracao);
   
   total=OrdersTotal();
 
Marco vd Heijden:

Did you try as Indicator or Expert?

These are two different things.

If you worked that out chk custom indicator output by dropping in the print function:

The first position is being opened fine, the martingales are the ones who are not working. 

 

It should open a new order with double lot size, if the last order moved to the oposite direction that was supposed to. 

 

OP_BUY = Ask = error 138

   total=OrdersTotal();
   if(total<totaldeordens) 
   {
      for(cnty=0; cnty < totaldeordens - total;cnty++)
      {
            
         if(call!=0.0)
         {
            order=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,"BO exp:"+bo+"",magicnumber,0,Green);
           
            if(order==0)
               {
                  Print("Erro ao executar operação de compra: ",GetLastError());
               }
            else if(order>0)
               {
                  Print("Operação de compra executada com sucesso");
                  up[0]=1;
                  //--martin1
                     if(usamartingale==true && up[1]!=0.0 && Close[1]<Open[1])// && Open[0]>=filter)
                      {
                          order=OrderSend(Symbol(),OP_BUY,lots*multip1,Ask,0,0,0,"BO exp:"+bo+"",magicnumber,0,Green);
                          if(order==0)
                          {
                              Print("Erro ao executar martingale(1) de compra: ",GetLastError());
                          }
                          else if(order>0)
                          {
                              Print("Martingale(1) de compra executada com sucesso");
                              up2[0]=1;
                              ///---martin2
                              if(usamartingale2==true && up2[1]!=0.0 && Close[1]<Open[1])// && Open[0]>=filter)
                              {
                                 order=OrderSend(Symbol(),OP_BUY,lots*multip2,Ask,0,0,0,"BO exp:"+bo+"",magicnumber,0,Green);
                                 if(order==0)
                                 {
                                    Print("Erro ao executar martingale(2) de compra: ",GetLastError());
                                 }
                                 else if(order>0)
                                 {
                                    Print("Martingale(2) de compra executada com sucesso");
                                    up2[0]=0;
                                 }
                              }
                          }
                       }
                  }
          }
 
Marco vd Heijden:

OP_BUY = Ask = error 138

I don't think this error have any influence on the binary options charts Marco, both buy and sell, are being executed properly, the problem is with the trades that should be executed after this first open position reachs an end and the total trades are equal to 0.

I have tried this way and also  didn't worked:

 int order, total,cnty;
   
   
   double call = iCustom(NULL,0,"MAD CNT FV Histograma+StDeviation",fper,fmode,fprice,distancia,stdevp,desvio,repaintfactor,0,false,false,false,1440,0,1);
   double put = iCustom(NULL,0,"MAD CNT FV Histograma+StDeviation",fper,fmode,fprice,distancia,stdevp,desvio,repaintfactor,0,false,false,false,1440,1,1);
   
   string bo=IntegerToString(expiracao);
   
   up[0]=EMPTY_VALUE;
   dw[0]=EMPTY_VALUE;
   up2[0]=EMPTY_VALUE;
   dw2[0]=EMPTY_VALUE;
   
   total=OrdersTotal();
   if(total<totaldeordens) 
   {
      for(cnty=0; cnty < totaldeordens - total;cnty++)
      {
        //if((cnty%2) == 0 && time0!=Time[0])
        if(call!=0.0)// && Open[0]>=filter)
         {
            order=OrderSend(Symbol(),OP_BUY,lots,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,Green);
            //Sleep(sleep);
            if(order==0)
               {
                  Print("Erro ao executar operação de compra: ",GetLastError());
               }
            else if(order>0)
               {
                  Print("Operação de compra executada com sucesso");
                  up[0]=1;
               }
          }
         
                          
      if(put!=0.0)// && Close[0]<=filter)
         {
            order=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,SaddleBrown);
            //Sleep(sleep);
            if(order==0)
               {
                  Print("Erro ao executar operação de venda: ",GetLastError());
               }
            else if(order>0)
               {
                  Print("Operação de venda executada com sucesso");
                  dw[0]=1;
               }
            }
         }
      }           
//--martin1
      if(total<totaldeordens && usamartingale && order==0)
        {
         for(cnty=0; cnty < totaldeordens - total;cnty++)
            {
                     if(up[1]==1 && Close[1]<Open[1])// && Open[0]>=filter)
                      {
                          order=OrderSend(Symbol(),OP_BUY,lots*multip1,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,Green);
                          if(order==0)
                          {
                              Print("Erro ao executar martingale(1) de compra: ",GetLastError());
                          }
                          else if(order>0)
                          {
                              Print("Martingale(1) de compra executada com sucesso");
                              up2[0]=1;
                          }        
                       }

                      if(dw[1]==1 && Close[1]>Open[1])// && Close[0]<=filter)
                      {
                           order=OrderSend(Symbol(),OP_SELL,lots*multip1,Bid,0,0,0,"BO exp:"+bo+"",magicnumber,0,SaddleBrown);
          
                           if(order==0)
                           {
                              Print("Erro ao executar martingale(1) de venda: ",GetLastError());
                           }
                           else if(order>0)
                           {
                              Print("Martingale(1) de venda executada com sucesso");
                              dw2[0]=1;
                           }
                       }
                }
          }             
 

Here is working just fine.

You are buying and selling at bid price and the server will not accept it it will only accept your sell orders and because of the boolean flip flop like functions your robot runs stuck after the first order,the second order get's rejected and that's about it.

 
Marco vd Heijden:

Here is working just fine.

You are buying and selling at bid price and the server will not accept it it will only accept your sell orders and because of the boolean flip flop like functions your robot runs stuck after the first order,the second order get's rejected and that's about it.

With BO all orders are executed at Bid price.
 
Gabriel Viali:

I don't think this error have any influence on the binary options charts Marco, both buy and sell, are being executed properly, the problem is with the trades that should be executed after this first open position reachs an end and the total trades are equal to 0.

I have tried this way and also  didn't worked:

What did not work ? Show what you get and what you are expecting.

The function SetIndexBuffer() is intended for indicator, not for EA.

 
Alain Verleyen:

What did not work ? Show what you get and what you are expecting.

The function SetIndexBuffer() is intended for indicator, not for EA.

Alain, the intended purpose is, if there was a BUY order, and the candle in wich this order was triggered had its Close lower then the Open, the Ea should open a new buy position with the double of the first lot. To specify that condition, I added that buffer (that I shall take it of), that says that if was an open order and the price didn't gone in the expected direction the value of this buffer is 1. In the opening of the next candle and if there is no order open, if this value was 1, i should trigger a new order in the same direction than before.
 
Gabriel Viali:
Alain, the intended purpose is, if there was a BUY order, and the candle in wich this order was triggered had its Close lower then the Open, the Ea should open a new buy position with the double of the first lot. To specify that condition, I added that buffer (that I shall take it of), that says that if was an open order and the price didn't gone in the expected direction the value of this buffer is 1. In the opening of the next candle and if there is no order open, if this value was 1, i should trigger a new order in the same direction than before.

An error occurs when the return value of OrderSend is -1 not 0.

            if(order==0)

Why this loop ?

      for(cnty=0; cnty < totaldeordens - total;cnty++)

This up[1] is not initialized, which value it is ?

                     if(usamartingale==true && up[1]!=0.0 && Close[1]<Open[1])// && Open[0]>=filter)

You are sending an order and immediately try to send a "martingale" order, that doesn't make much sense.

Forum on trading, automated trading systems and testing trading strategies

Can't get this function to run.

Alain Verleyen, 2015.05.07 20:01

What did not work ? Show what you get and what you are expecting.

The function SetIndexBuffer() is intended for indicator, not for EA.