what parameters to pass to icustom() function ? - page 2

 

I have examine my EA code but cannot pinpoint the bugs.the EA does not open order.Although the code for order opening,order closing etc is freely available codes,the trade criteria is mine which I visually test should be profitable provide one find the correct LRLPeriod value alongwith with correct stoploss management.i compile the EA but it does not show error but it is not opening position.here I am attaching for anyone to correct it and make it working and required that the fully working version may be used freely by all interested.Hoping for contributions from all forum members.Tnx

//+------------------------------------------------------------------+
//|                                                  LRLIndic.mq4 |
//|                      Copyright © 2013, .... 
//|                                       http://www.MirTD.net/ |
//+------------------------------------------------------------------+

//#define MAGICNO=20130728

double TakeProfit = 50;
int LRLPeriod=14;
//int shift;
//int n;
//double sumx,sumy,sumxy,sumx2,sumy2;
//double m,yint,r;

 
double Lots=0.1;
double LRLBuffer[],LRLBuffer_1,LRLBuffer_2;
int TOPB = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
      
      //LRLBuffer[1]=LRLBuffer_1;
      //LRLBuffer[2]=LRLBuffer_2;
    
   int cnt, ticket, total;

   if(Bars<100)
     {
      Print("bars less than 100");
      return(0);  
     }
   if(TakeProfit<10)
     {
      Print("TakeProfit less than 10");
      return(0);  // check TakeProfit
     }
     
     //calling custom indicator with parameter values which are declared at both the indi and EA
//--------------------------------------------------------------------------------------------------icustom 
     //---- input parameters

//int L=LRLPeriod;
//int s=shift;
//int n=n;
//double sx=sumx, sy=sumy, sxy=sumxy, sx2=sumx2, sy2=sumy2;
//double m=m, yi=yint, r=r;
                           //    L,s,n,sx,sy,sxy,sx2,sy2,m,yi,r,
                            
                           
                                    //LRLBuffer_1=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,1);
                                    //LRLBuffer_2=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,2);
                                    
                                    for(int i=4-1;i>=0;i--) //or   (int i=0;i<4;i++)
                                      {
                                         LRLBuffer[i]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,i);
                                      }
//---------------------------------------------------------------------------------------------------     
   total=OrdersTotal();
   if(Bars!=TOPB) // to ensure only one trade per Bar 
     {
        
      // check for long position (BUY) possibility
      if(Close[1]>LRLBuffer[1] && Close[2]<LRLBuffer[2] && Close[1]>Open[1])
        {
         ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"LR EATest1",0,0,Green);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
            TOPB=Bars;
           }
         else Print("Error opening BUY order : ",GetLastError()); 
         return(0); 
        }
      // check for short position (SELL) possibility
      if(Close[1]<=LRLBuffer[1] && Close[2]>LRLBuffer[2] && Close[1]<=Open[1])
        {
         ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"LR EATest1",0,0,Red);
         if(ticket>0)
           {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
            TOPB=Bars;
           }
         else Print("Error opening SELL order : ",GetLastError()); 
         return(0); 
        }
      return(0);
     }
   // it is important to enter the market correctly, 
   // but it is more important to exit it correctly...   
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   // check for opened position 
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position opened
           {
            // closed?
            if(Close[1]<=LRLBuffer[1] && Close[2]>LRLBuffer[2] && Close[1]<=Open[1])
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
             
           }
         else // short position
           {
            //  closed?
            if(Close[1]>LRLBuffer[1] && Close[2]<LRLBuffer[2] && Close[1]>Open[1])
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
             
             
           }
        }
     }
   return(0);
  }
 
 

one more thing to add here.i use this code on the LRL Indicator given on 1st page and the Alert works fine.Why then EA is not working?.you can include this code in the indicator and see for yourself..

 
          //check to buy
            if(Close[1]>LRLBuffer[1] && Close[2]<LRLBuffer[2] && Close[1]>Open[2])
               {
                  if(Bars!=TOPB){
                        Alert("LRSig Buy",Symbol()+"-",Close[1]);
                        Print("LRSig Buy",Symbol()+"-",Close[1]);
                        TOPB=Bars;
                                }
               }
         
         //check to sell
            if(Close[1]<LRLBuffer[1] && Close[2]>LRLBuffer[2] && Close[1]<=Open[2])
              {
                  if(Bars!=TOPB){
                        Alert("LRSig Sell",Symbol()+"-",Close[1]);
                        Print("LRSig Sell",Symbol()+"-",Close[1]);
                        TOPB=Bars;
                                }
              }
 
I gave you a circular link because YOU already provided the code for YOUR question.
LRLBuffer[1]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,1);
LRLBuffer[2]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,2);
 

WHRoeder:

I gave you a circular link because YOU already provided the code for YOUR question.

Yep,you are right but initially there was some confusion on the shift value till deVries point it out.Thats why.btw pls check the EA on why it is not sending order yet.i think

you can find it out.that ll be welcome :D

 

are my comments moderated.i remember putting up the print records on the journal which shows the error when I run the already mentioned EA but I don't see it now.if so why??

 
MirTD:

are my comments moderated.i remember putting up the print records on the journal which shows the error when I run the already mentioned EA but I don't see it now.if so why??

Not by me, perhaps you didn't press the Add your comment button.
 
RaptorUK:
Not by me, perhaps you didn't press the Add your comment button.

ok.lol.but someone must hv done it.i sure see it after pressing the button...im re-putting it up here.RaptorUK,pls llok into the code and tell me where it at fault.is it that the LRLBuffer values are not return by the indicator?.Does indicator need to explicitly return values for icustom to work? or it need not return.Inserting Alert code as given earlier is working and give Alert as expected.so then why replacing the place of Alert code with oredersend code is not working?

2013.07.31 00:37:22     2013.07.10 05:00  Linear Regression Line EURUSD,M5: loaded successfully
2013.07.31 00:37:22     Linear Regression Indicator TestEA1 inputs: LRLPeriod=14; 
2013.07.31 00:37:20     TestGenerator: current spread 12 used
2013.07.31 00:37:20     Linear Regression Line EURUSD,M5: removed
2013.07.31 00:37:20     Linear Regression Indicator TestEA1 EURUSD,M5: loaded successfully
2013.07.31 00:35:39     2013.07.10 05:00  Linear Regression Line EURUSD,M5: loaded successfully
2013.07.31 00:35:39     Linear Regression Indicator TestEA1 inputs: LRLPeriod=14; 
 

I retest it again without changing any code and gives this results!

2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (volume limit 126 at 2013.07.30 22:20 exceeded)
2013.07.31 00:52:17     TestGenerator: unmatched data error (high value 1.32631 at 2013.07.30 22:22 and price 1.32640 mismatched)
2013.07.31 00:52:14     TestGenerator: current spread 11 used
2013.07.31 00:52:14     Linear Regression Line EURUSD,M5: removed
2013.07.31 00:52:14     Linear Regression Indicator TestEA1 EURUSD,M5: loaded successfully
2013.07.31 00:47:06     Linear Regression Indicator TestEA1 EURUSD,M5: removed
 
MirTD:

ok.lol.but someone must hv done it.i sure see it after pressing the button...im re-putting it up here.RaptorUK,pls llok into the code and tell me where it at fault.is it that the LRLBuffer values are not return by the indicator?.Does indicator need to explicitly return values for icustom to work? or it need not return.Inserting Alert code as given earlier is working and give Alert as expected.so then why replacing the place of Alert code with oredersend code is not working?

iCustom() reads the Indicator's buffer(s), in this case, buffer.


double LRLBuffer[]

is an array of size zero elements, so any value you use from that array . . .

for(int i=4-1;i>=0;i--) //or   (int i=0;i<4;i++)
   {
   LRLBuffer[i]=iCustom(NULL,0,"Linear Regression Line",LRLPeriod,0,i);
   }

. . . will be zero. Either declare it with a fixed size or resize it . . .

 
RaptorUK:

iCustom() reads the Indicator's buffer(s), in this case, buffer.

is an array of size zero elements, so any value you use from that array . . .

. . . will be zero. Either declare it with a fixed size or resize it . . .

RaptorUK! thnks to you the EA works now like magic after resizing although I first doubt it!

the graph is not nice though but thts not wht I expect initially.ll need to incorporate

stoploss feature and few filters to make it acceptable atleast.ll come to you when I encounted

roadblock again in future! :D

Reason: