Capturing a lagging indicator

 

Hi,

 

I'm new to mql4 coding and I understand the basics (very basic).

 

 

How do you capture a lagging indicator with iCustom?

 

i have been playing with the code inside the indicator tester and it seems to work fine. However when on live it never trades.

 

For example fractals will not always be generated on the previous bar it can take up to 5 bars (only an example) 

 

now the "double" declarations are very static you have to specify which bar you want to look at "current bar + 1".

 

What happens if the fractal occurs on + 3. I still want to capture this and make a trade as it could of been a valid signal. 

 

How do you code the logic to look back from +1 to +5 bars. If a fractal occurs in this period make a trade on the next bar??

 

along the lines of

 

IF Fractal occurs =< current bar + 5 - BUY 

 

 

I hope that makes sense. 

 
Have you read in the editor's reference the usage and the example of iCustom(...) ?
 

Run a loop through iFractals (or any indicator you call through iCustom). If you get a match, off you go. 

Example:

   bool FracUp=false;
   for(int i=0; i<5; i++)
     {
      if(iFractals(NULL,0,MODE_UPPER,i)>0)
        {
         FracUp=true;
         break;
        }
     }
   if(FracUp)
     {
      //do your thing
     }
 

Ok now I'm stuck. When I compile it keeps saying fracup is an "undeclared identidier"

 

I assume I need to make a "double" called FracUp? 

 

Nope, FracUp is already declared as a bool (in this example, but you could store the value if you prefer).

Compiles fine my end... I think you might have missed something. 

 
marine1983:

Ok now I'm stuck. When I compile it keeps saying fracup is an "undeclared identidier"

 

I assume I need to make a "double" called FracUp

If you declare a variable that starts with a capital F, you must use a capital F when accessing it.
 

Arrrrghhh Im so lost. Thanks for all your input my code is below but I cant get it to compile.

 

 

 

 

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

//                        DO NOT DELETE THIS HEADER

//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT 

//

//                   Copyright ©2011, ForexEAdvisor.com

//                 ForexEAdvisor Strategy Builder version 0.2

//                        http://www.ForexEAdvisor.com 

//

// THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.2 

// on: 11/3/2015 11:10:26 PM

// Disclaimer: This EA is provided to you "AS-IS", and ForexEAdvisor disclaims any warranty

// or liability obligations to you of any kind. 

// UNDER NO CIRCUMSTANCES WILL FOREXEADVISOR BE LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY,

// FOR ANY LOSS OF USE, REVENUE OR PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR

// ECONOMIC LOSS OR FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, STATUTORY, PUNITIVE,

// EXEMPLARY OR CONSEQUENTIAL DAMAGES WHATSOEVER RELATED TO YOUR USE OF THIS EA OR 

// FOREXEADVISOR STRATEGY BUILDER     

// Because software is inherently complex and may not be completely free of errors, you are 

// advised to verify this EA. Before using this EA, please read the ForexEAdvisor Strategy Builder

// license for a complete understanding of ForexEAdvisor' disclaimers.  

// USE THIS EA AT YOUR OWN RISK. 

//  

// Before adding this expert advisor to a chart, make sure there are NO

// open positions.

//                      DO NOT DELETE THIS HEADER

//             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT 

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



extern int MagicNumber=10001;

extern double Lots =0.1;

extern double StopLoss=100;

extern double TakeProfit=100;

extern int TrailingStop=0;

extern int Slippage=3;




// Global variables

int LastBars = 0;




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

//    expert start function

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





int start()

{


   int NeedBarsCounted;


   if (LastBars == Bars) return(0);

   NeedBarsCounted = Bars - LastBars;

   LastBars = Bars;

   if (NeedBarsCounted == Bars) 


   NeedBarsCounted--;


  for (int i = NeedBarsCounted; i >= 1; i--)

  

  int Current = i;

  if (Current==0) return(0);

      

  double MyPoint=Point;

  if(Digits==3 || Digits==5) MyPoint=Point*10;

  

  double TheStopLoss=0;

  double TheTakeProfit=0;

  double CCI0 = iCCI(NULL, 0, 14, PRICE_CLOSE, Current); 

  double CCI1 = iCCI(NULL, 0, 14, PRICE_CLOSE, Current + 1); 

  double CCI2 = iCCI(NULL, 0, 14, PRICE_CLOSE, Current + 2);

  double CCI3 = iCCI(NULL, 0, 14, PRICE_CLOSE, Current + 3);

  double ZIGZAG = iCustom(NULL,0,"FractalZigZagNoRepaint",0, Current +1);

  

  if( TotalOrdersCount()==0 ) 

  {

     int result=0;

     

     bool FracUP=false;

    for( int current=0 ; Current <5; Current++)

     {

      if(iFractals(NULL,0,MODE_LOWER,Current)>0)

        {

         FracUP=true;

         break;

        }

     }

   if(FracUP)

      

      ((ZIGZAG > 0.000000001 && ZIGZAG< 9999999999999 && CCI1 < -100)) // Here is your open buy rule (This is the logic. If fracup == true and ZIG ZAG is shwoing a value and CCI1 < 100 then buy. I just cant get my head around it.)

     {

        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",MagicNumber,0,Blue);

        if(result>0)

        {

         TheStopLoss=0;

         TheTakeProfit=0;

         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;

         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;

         OrderSelect(result,SELECT_BY_TICKET);

         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);

        }

        return(0);

     }

  }

  

  

   return(0);

}


int TotalOrdersCount()

{

  int result=0;

  for(int i=0;i<OrdersTotal();i++)

  {

     OrderSelect(i,SELECT_BY_POS ,MODE_TRADES);

     if (OrderMagicNumber()==MagicNumber) result++;


   }

  return (result);

 

Using an EA builder is a bad idea, they generally turn out very low quality code.

   if(FracUP)

      

      ((ZIGZAG > 0.000000001 && ZIGZAG< 9999999999999 && CCI1 < -100)) 

 What is this supposed to do?

 
if(FracUP && ZIGZAG>0 && ZIGZAG<EMPTY_VALUE && CCI1<-100)
 

I understand an EA builder is not the way to go but at least it creates a basic code so I can manipulate it, just how I learn I suppose.

 

Its basically meant to open a buy if CCI is below -100 and  fractal appears. I thought it would be easy but its getting difficult very fast ha. 

 
//                 ForexEAdvisor Strategy Builder version 0.2
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

    • We hate EA builder
    • You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
    • There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
    • EA builder makes bad code counting up while closing multiple orders.
    • EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
    • EA builder makes bad code Not adjusting for 4/5 digit brokers
    • EA builder makes bad code not adjusting for ECN brokers.
    • EA builder makes bad code not checking return codes.
    • EATree uses objects on chart to save values - not persistent storage (files or GV+Flush.) No recovery (crash/reboot.)
Reason: