Expert based on a Indicator

 

Hi, sorry to bother you again guys with my questions.

I've been building experts based on the below structure. It worked for one strategy, and so, I was trying to use the same framework to another expert. I always build an indicator to show -1 for the buy trigger and +1 for the sell trigger. Thus, the indicator which will be used to get the buy and sell signals has the same outputs ( -1;0;1).

The problem is: Although the indicator that I am trying to use shows value ( -1;0;1), when I try to use it on my expert, it does not work (doesn't buy or sell). Do you know why it is happening?

Thanks in advance.


extern double Lots = 0.1;
extern double TrailingStop = 30;

//---- Expert Options ----//

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+


int start()
  {
   double Compra, Venda, TakeProfit;
   int total, ticket, cnt;
   
//---- initial data checks----//

if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   
//----Indicator Reference----//

Compra=iCustom(Symbol(),0,"test",1,0); 
Venda=iCustom(Symbol(),0,"test",0,0);
TakeProfit=iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
total=OrdersTotal();

//---- Checking for orders ----//

if(total<1) 
     {
      // no opened orders identified
      if(AccountFreeMargin()<(1000*Lots))
        {
         Print("We have no money. Free Margin = ", AccountFreeMargin());
         return(0);  
        }
//---- check for long position (BUY) possibility ----//
        if(Compra==-1)
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0),"Rodrigo Especulação",0001,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
//---- check for short position (SELL) possibility ----//
       if(Venda==1)
         {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0),"Rodrigo Especulação",0002,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
           

      }
//---- 

//---- Exit the trade ----//

   CheckForClose();


return(0);      
   }
   
   
//---- Separeted Functions ----//

   

//---- Check for an exit ----//

void CheckForClose()
   {
   double TakeProfit = iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,0);
   //-----
   for(int cnt=0; cnt < OrdersTotal(); cnt++)
      {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()==OP_SELL &&   // check for opened SELL position 
      OrderSymbol()==Symbol())  // check for symbol
         {
         OrderModify(OrderTicket(),OrderOpenPrice(),0,TakeProfit,0,Red); 
         }
      if(OrderType()==OP_BUY &&   // check for opened BUY position 
      OrderSymbol()==Symbol())  // check for symbol
         {
         OrderModify(OrderTicket(),OrderOpenPrice(),0,TakeProfit,0,Green); 
         }   
      }

   }
   
// the end

//+------------------------------------------------------------------+ 
 

what error u get?

 

I realize that the problem is: My indicator shows a entry value always when the bar close, but in the expert I'm asking for the bar[0] signal, so, for this reason it'll never get a enter trade signal.


So, I only have to change this:

Thanks for your interest.

Compra=iCustom(Symbol(),0,"test",1,0); 
Venda=iCustom(Symbol(),0,"test",0,0);

//for

Compra=iCustom(Symbol(),0,"test",1,1); 
Venda=iCustom(Symbol(),0,"test",0,1);