Download MetaTrader 5

iCustom values

To add comments, please log in or register
Do you want to deposit to your account? Do this in any convenient way!
franko
53
franko 2014.03.27 16:28 

Hello,

Im writing simple EA code:


extern int MaxOpen=1;
extern double Lots         =1;
extern double StopLoss     =1000;
extern double TakeProfit   =1000;
extern int TrailingStop    =0;
extern int Slippage        =10;
extern int MagicNumber     =10001;
int EURLongUSD=0;
double x=iCustom(NULL,0,"ADXEURMom",0,0,0);


int start()
{

      if(OrdersTotal() < MaxOpen)
     if ((iADX("EURUSD",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,0)>(iADX("EURUSD",PERIOD_M1,28,PRICE_CLOSE,MODE_PLUSDI,0)))&&(x>10))
   
       {
      OrderSend("EURUSD",OP_BUY,Lots,Ask,Slippage,0,0,0,MagicNumber,0,Blue);
      EURLongUSD++;
      }
   
  
 
return(0);
}


The problem is that positions are opened without iCustom value approval ( if x<10)

This is the indicator code:

Maybe you see some simple mistakes. Many thanks.

#property indicator_separate_window   // Indicator is drawn in the main window
#property indicator_buffers 4       // Number of buffers
#property indicator_color1 Red     // Color of the 1st line
#property indicator_color2 Green      // Color of the 2nd line
#property indicator_color3 Blue     // Color of the 1st line
#property indicator_color4 Purple      // Color of the 2nd line

extern int ADXPeriod=28;
 
double EURUSD[],EURGBP[],EURAUD[],EURCAD[];             // Declaring arrays (for indicator buffers)

int init()                          // Special function init()
  {
   SetIndexBuffer(0,EURUSD);         // Assigning an array to a buffer
    SetIndexBuffer(1,EURGBP);         // Assigning an array to a buffer
    SetIndexBuffer(2,EURAUD);         // Assigning an array to a buffer
    SetIndexBuffer(3,EURCAD);         // Assigning an array to a buffer
   

//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ADXEURMom("+IntegerToString(ADXPeriod)+")");
   SetIndexLabel(0,"EURUSD");
   SetIndexLabel(1,"EURGBP");
   SetIndexLabel(2,"EURAUD");
   SetIndexLabel(3,"EURCAD");
   
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1,Red);// Line style
   SetIndexStyle (1,DRAW_LINE,STYLE_SOLID,1,Green);// Line style
   SetIndexStyle (2,DRAW_LINE,STYLE_SOLID,1,Blue);// Line style
   SetIndexStyle (3,DRAW_LINE,STYLE_SOLID,1,Purple);// Line style
   
   
   return;                          // Exit the special funct. init()
  }
  
  
int start()                         // Special function start()
  {
   int i,                           // Bar index
       Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;           // Index of the first uncounted
   if(i>=0)                      // Loop for uncounted bars
     
     {
      EURUSD[i]=(((iADX("EURUSD",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,(i)))-(iADX("EURUSD",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,(i+5)))));
      EURGBP[i]=(((iADX("EURGBP",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,(i)))-(iADX("EURGBP",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,(i+5)))));
      EURAUD[i]=(((iADX("EURAUD",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,(i)))-(iADX("EURAUD",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,(i+5)))));
      EURCAD[i]=(((iADX("EURCAD",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,(i)))-(iADX("EURCAD",PERIOD_M1,28,PRICE_CLOSE,MODE_MAIN,(i+5)))));
     
    
     }
       return;                          // Exit the special funct. start()
  }


Best regards,

Roberts

qjol
3243
qjol 2014.03.27 16:44  

first: you have to put the "double x=iCustom(NULL,0,"ADXEURMom",0,0,0);" inside the start section

second: do some debugging try to Print or Alert the x and see what the result is

franko
53
franko 2014.03.27 16:57  

Values which are coming from Print are matching with indicator ones. Interesting, what could be the problem?


Best regards,

Roberts

franko
53
franko 2014.03.27 16:58  
extern int MaxOpen=1;
extern double Lots         =1;
extern double StopLoss     =1000;
extern double TakeProfit   =1000;
extern int TrailingStop    =0;
extern int Slippage        =10;
extern int MagicNumber     =10001;
int EURLongUSD=0;


int start()
{

      double x=iCustom(NULL,0,"ADXEURMom",Red,0,0);
      Print("Indicator: ", x); 
      if(OrdersTotal() < MaxOpen)
     if ((iADX("EURUSD",PERIOD_M1,28,PRICE_CLOSE,MODE_PLUSDI,0)>(iADX("EURUSD",PERIOD_M1,28,PRICE_CLOSE,MODE_MINUSDI,0)))&&(iCustom(NULL,0,"ADXEURMom",Red,0,0)>10))
   
       {
      OrderSend("EURUSD",OP_BUY,Lots,Ask,Slippage,0,0,0,MagicNumber,0,Blue);
      EURLongUSD++;
      
      }
   
  
 
return(0);
}

franko
53
franko 2014.03.27 17:00  
extern int MaxOpen=1;
extern double Lots         =1;
extern double StopLoss     =1000;
extern double TakeProfit   =1000;
extern int TrailingStop    =0;
extern int Slippage        =10;
extern int MagicNumber     =10001;
int EURLongUSD=0;


int start()
{

      double x=iCustom(NULL,0,"ADXEURMom",Red,0,0);
      Print("Indicator: ", x); 
      if(OrdersTotal() < MaxOpen)
     if ((iADX("EURUSD",PERIOD_M1,28,PRICE_CLOSE,MODE_MINUSDI,0)>(iADX("EURUSD",PERIOD_M1,28,PRICE_CLOSE,MODE_PLUSDI,0)))&&(x>10))
   
       {
      OrderSend("EURUSD",OP_BUY,Lots,Ask,Slippage,0,0,0,MagicNumber,0,Blue);
      EURLongUSD++;
      
      }
   
  
 
return(0);
}
qjol
3243
qjol 2014.03.27 17:05  

is x > 10 ?

I think it's pretty rare that x will be > than 10

franko
53
franko 2014.03.27 17:08  

Thats the main problem, the EA is opening position even if x < 10. When I close it, it opens it again :)


Best regards,

Roberts

franko
53
franko 2014.03.27 17:16  

Found something,

Print shows that indicator values are ok, like 0,8, 0,9, 1,2, 0,7 and then suddenly comes one 7 digit number as x. In indicator window suddenly anly values disapears. Could it be that indicator hangs up?


Best regards,

Roberts

qjol
3243
qjol 2014.03.27 17:26  
double x=iCustom(NULL,0,"ADXEURMom",28,0,0);
franko
53
franko 2014.03.27 17:28  

Simple solution,

30>x>10, everything seems to work.

Thanks gjol!


Best regards,

Roberts

whroeder1
14470
whroeder1 2014.03.28 13:18  
  1. Franko: 30>x>10, everything seems to work.
    I hope you didn't write that literally because it isn't what you think. Int and bool are interchangeable (true=1, false=0) so if X==20 you get
    30 > x > 10
    30 > 20 > 10
       true > 10
          1 > 10
          false

  2. Franko: When I close it, it opens it again :)
    You don't have any OrderClose calls in you code. Opening an order in the opposite direction is NOT a close, that is hedging.
12
To add comments, please log in or register