EA with custom indicator - page 2

 
Faat94: double val=iCustom(NULL,0,"super-trend",13,1,0);

Initially asked and answered. What didn't you understand? What value is stored in buffer 1?
 
double downtrend=iCustom(NULL,0,"super-trend",1,0);

double uptrend=iCustom(NULL,0,"super-trend",0,0);

int ticket;
   
   if(OrdersTotal() == 0 && downtrend )
   {
   ticket=OrderSend(Symbol(),OP_SELL,lots, Bid, slippage,0,0, "First Sell Trade", magic,0, CLR_NONE);
   if(ticket>0)
                          {
                           if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                              Print(" Sell order : ",GetLastError());  
                          }
                        else
            
                        Print("Error opening Sell order : ",GetLastError());
   
   }

   if(OrdersTotal() == 0 && uptrend )
   {
   ticket=OrderSend(Symbol(),OP_BUY,lots, Ask, slippage,0,0, "First Buy Trade", magic,0, CLR_NONE);
   if(ticket>0)
                          {
                           if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                              Print(" Buy order : ",GetLastError());
                          }
                        else
            
                        Print("Error opening Buy order : ",GetLastError());
   }

    if(AccountProfit()>= 200)
        {
        closeallorders();
        }

That's how I tried but it open only sell trades. Why it doesen't open a buy trade ? The indicator shows an UPTrend

At the code of the indicator :

 SetIndexBuffer(0, TrendUp);
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexLabel(0, "Trend Up");
   SetIndexBuffer(1, TrendDown);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexLabel(1, "Trend Down");
 
Faat94:

That's how I tried but it open only sell trades. Why it doesen't open a buy trade ? The indicator shows an UPTrend

At the code of the indicator :


Because downtrend is a double, not a boolean variable? Same for uptrend

if(OrdersTotal() == 0 && downtrend )
 

And now ?

Still not works

bool downtrend = iCustom(NULL,0,"super-trend",1,0);

bool uptrend = iCustom(NULL,0,"super-trend",0,0);

int ticket;
  
   
   if(OrdersTotal() == 0 && downtrend == true )
   {
   ticket=OrderSend(Symbol(),OP_SELL,lots, Bid, slippage,0,0, "First Sell Trade", magic,0, CLR_NONE);
   if(ticket>0)
                          {
                           if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                              Print(" Sell order : ",GetLastError());  
                          }
                        else
            
                        Print("Error opening Sell order : ",GetLastError());
   
   }

   if(OrdersTotal() == 0 && uptrend == true )
   {
   ticket=OrderSend(Symbol(),OP_BUY,lots, Ask, slippage,0,0, "First Buy Trade", magic,0, CLR_NONE);
   if(ticket>0)
                          {
                           if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                              Print(" Buy order : ",GetLastError());
                          }
                        else
            
                        Print("Error opening Buy order : ",GetLastError());
   }

    if(AccountProfit()>= 200)
        {
        closeallorders();
        }
 
Faat94:

And now ?

Still not works


They are doubles, not booleans

double downtrend = iCustom(NULL,0,"super-trend",1,0);

double uptrend = iCustom(NULL,0,"super-trend",0,0);

Try

if(OrdersTotal() == 0 && downtrend !=EMPTY_VALUE )
//
//
//
if(OrdersTotal() == 0 && uptrend !=EMPTY_VALUE )
 
GumRai:


They are doubles, not booleans

Try


Thank you, I tried this many times but I had a small mistake ! I solved it like this :

double downtrend; 

double uptrend; 

And it works but now I have another problem, the EA sets every tick the var downtrend to iCustom(NULL,0,"super-trend",1,0); and if I make backtests it runs very slowly. How can I solve that ? Is there a way ? Maybe if a candle closes ?

int ticket;
   downtrend = iCustom(NULL,0,"super-trend",1,0);

   uptrend = iCustom(NULL,0,"super-trend",0,0);
   
   if(OrdersTotal() == 0 && downtrend !=EMPTY_VALUE  )
   {
   ticket=OrderSend(Symbol(),OP_SELL,lots, Bid, slippage,Bid+200*Point,0, "First Sell Trade", magic,0, CLR_NONE);
   if(ticket>0)
                          {
                           if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                              Print(" Sell order : ",GetLastError());  
                          }
                        else
            
                        Print("Error opening Sell order : ",GetLastError());
   
   }

   if(OrdersTotal() == 0 && uptrend !=EMPTY_VALUE  )
   {
   ticket=OrderSend(Symbol(),OP_BUY,lots, Ask, slippage,Bid-200*Point,0, "First Buy Trade", magic,0, CLR_NONE);
   if(ticket>0)
                          {
                           if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
                              Print(" Buy order : ",GetLastError());
                          }
                        else
            
                        Print("Error opening Buy order : ",GetLastError());
   }

    if(AccountProfit()>= 200)
        {
        closeallorders();
        }
       
       
     
  }
 
Faat94:


Thank you, I tried this many times but I had a small mistake ! I solved it like this :

And it works but now I have another problem, the EA sets every tick the var downtrend to iCustom(NULL,0,"super-trend",1,0); and if I make backtests it runs very slowly. How can I solve that ? Is there a way ? Maybe if a candle closes ?

Try to inspect the logic and see where it can be made more efficient.

What if you were a shopkeeper and you had the routine

If I have less than 10,000 eggs in stock and it is a Monday, Wednesday or a Friday, Order enough eggs to make up the shortfall.

Would you count the eggs on a Tuesday?

Your first 2 main if condition blocks have

if(OrdersTotal() == 0)

in common.

So, like the shopkeeper you can cut a lot out of the routine by checking OrdersTotal() first

 
   int ticket;

   if(OrdersTotal()==0)
     {
      downtrend=iCustom(NULL,0,"super-trend",1,0);
      uptrend=iCustom(NULL,0,"super-trend",0,0);
      if(downtrend!=EMPTY_VALUE)
        {
         ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,slippage,Bid+200*Point,0,"First Sell Trade",magic,0,CLR_NONE);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print(" Sell order : ",GetLastError());
           }
         else
            Print("Error opening Sell order : ",GetLastError());
        }

      if(uptrend!=EMPTY_VALUE)
        {
         ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,slippage,Bid-200*Point,0,"First Buy Trade",magic,0,CLR_NONE);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
               Print(" Buy order : ",GetLastError());
           }
         else
            Print("Error opening Buy order : ",GetLastError());
        }
     }

   if(AccountProfit()>=200)
     {
      closeallorders();
     }
 
GumRai:


Great idea, thank you very much !! It works perfectly. Thanks to all you guys
Reason: