iAlligator signal gone wrong

 

Hello all, I'm new to this forum and MQL4 in general.


While practicing with the code, I have created a custom signal based on Bill Williams' Alligator indicator for EA testing purposes (Jaws 13/1, Teeth 8/1, Lips 5/1).


But it looks like I have forgot something...

Can you help me?


The code for OPEN BUY / CLOSE SELL is as follows:

(iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORLIPS,0)>iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORTEETH,0))
&&
(iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORTEETH,0)>iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORJAW,0))


While the code for OPEN SELL / CLOSE BUY is:

(iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORJAW,0)<iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORTEETH,0))
&&
(iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORTEETH,0)<iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORLIPS,0))


Looks like I forgot to insert the teeth period/shift.

To fix it, I should correct it to:

iAlligator(NULL,0,13,1,8,1,5,1,<...>,0)


Is it correct? Or I am wrong?

Thanks in advance.

 
WildCard578: Is it correct? Or I am wrong?
  1. You are wrong. The call has 13 parameters, none are optional. Compare the documentation to iCustom.
  2. You should encapsulate the call as outlined in Detailed explanation of iCustom - MQL4 forum
 

whroeder1, thank you for your detailed answers.

I've peeked at the links and looks like the answers are there.

I will check them again later on, amend my errors and post the new indicator for further comments.

Also, I failed to mention that <...> was meant to be an omissis of the parameters already given (MODE_EMA,PRICE_MEDIAN,MODE_GATORTEETH,).

Anyway, I recognize I only wrote 10 parameters out of 13 so I think of breaking it down into multiple lines (as per the examples given in the links) to double check that all the parameters are present.


PS what do you mean by "encapsulate the call"?

At the moment I am (re)writing a simple buy/sell EA (nothing fancy) with no options or external values.

My aim is to check how it works on raw indicator readings before proceeding to add more functions.

I will not use an iCustom indicator as of now so I am a bit puzzled by the encapsulation.

 

While checking on the proper indicator settings,  I counted 12 parameters and not 13.

double  iAlligator(
   string       symbol,            // symbol
   int          timeframe,         // timeframe
   int          jaw_period,        // Jaw line averaging period
   int          jaw_shift,         // Jaw line shift
   int          teeth_period,      // Teeth line averaging period
   int          teeth_shift,       // Teeth line shift
   int          lips_period,       // Lips line averaging period
   int          lips_shift,        // Lips line shift
   int          ma_method,         // averaging method
   int          applied_price,     // applied price
   int          mode,              // line index
   int          shift              // shift
   );

Anyway, looks like I was right when saying I skipped the teeth's data.

The new code is:

OPEN SELL / CLOSE BUY

(iAlligator(
   string       NULL,              // symbol
   int          0,                 // timeframe
   int          13,                // Jaw line averaging period
   int          1,                 // Jaw line shift
   int          8,                 // Teeth line averaging period
   int          1,                 // Teeth line shift
   int          5,                 // Lips line averaging period
   int          1,                 // Lips line shift
   int          MODE_EMA,          // averaging method
   int          PRICE_MEDIAN,      // applied price
   int          MODE_GATORJAW,     // line index
   int          0                  // shift
   )>iAlligator(
      string       NULL,              // symbol
      int          0,                 // timeframe
      int          13,                // Jaw line averaging period
      int          1,                 // Jaw line shift
      int          8,                 // Teeth line averaging period
      int          1,                 // Teeth line shift
      int          5,                 // Lips line averaging period
      int          1,                 // Lips line shift
      int          MODE_EMA,          // averaging method
      int          PRICE_MEDIAN,      // applied price
      int          MODE_GATORTEETH,   // line index
      int          0                  // shift
      );
&&
(iAlligator(
   string       NULL,              // symbol
   int          0,                 // timeframe
   int          13,                // Jaw line averaging period
   int          1,                 // Jaw line shift
   int          8,                 // Teeth line averaging period
   int          1,                 // Teeth line shift
   int          5,                 // Lips line averaging period
   int          1,                 // Lips line shift
   int          MODE_EMA,          // averaging method
   int          PRICE_MEDIAN,      // applied price
   int          MODE_GATORTEETH,   // line index
   int          0                  // shift
   )>iAlligator(
      string       NULL,              // symbol
      int          0,                 // timeframe
      int          13,                // Jaw line averaging period
      int          1,                 // Jaw line shift
      int          8,                 // Teeth line averaging period
      int          1,                 // Teeth line shift
      int          5,                 // Lips line averaging period
      int          1,                 // Lips line shift
      int          MODE_EMA,          // averaging method
      int          PRICE_MEDIAN,      // applied price
      int          MODE_GATORLIPS,    // line index
      int          0                  // shift
      );

OPEN BUY / CLOSE SELL

(iAlligator(
   string       NULL,              // symbol
   int          0,                 // timeframe
   int          13,                // Jaw line averaging period
   int          1,                 // Jaw line shift
   int          8,                 // Teeth line averaging period
   int          1,                 // Teeth line shift
   int          5,                 // Lips line averaging period
   int          1,                 // Lips line shift
   int          MODE_EMA,          // averaging method
   int          PRICE_MEDIAN,      // applied price
   int          MODE_GATORLIPS,    // line index
   int          0                  // shift
   )>iAlligator(
      string       NULL,              // symbol
      int          0,                 // timeframe
      int          13,                // Jaw line averaging period
      int          1,                 // Jaw line shift
      int          8,                 // Teeth line averaging period
      int          1,                 // Teeth line shift
      int          5,                 // Lips line averaging period
      int          1,                 // Lips line shift
      int          MODE_EMA,          // averaging method
      int          PRICE_MEDIAN,      // applied price
      int          MODE_GATORTEETH,   // line index
      int          0                  // shift
      );
&&
(iAlligator(
   string       NULL,              // symbol
   int          0,                 // timeframe
   int          13,                // Jaw line averaging period
   int          1,                 // Jaw line shift
   int          8,                 // Teeth line averaging period
   int          1,                 // Teeth line shift
   int          5,                 // Lips line averaging period
   int          1,                 // Lips line shift
   int          MODE_EMA,          // averaging method
   int          PRICE_MEDIAN,      // applied price
   int          MODE_GATORTEETH,   // line index
   int          0                  // shift
   )>iAlligator(
      string       NULL,              // symbol
      int          0,                 // timeframe
      int          13,                // Jaw line averaging period
      int          1,                 // Jaw line shift
      int          8,                 // Teeth line averaging period
      int          1,                 // Teeth line shift
      int          5,                 // Lips line averaging period
      int          1,                 // Lips line shift
      int          MODE_EMA,          // averaging method
      int          PRICE_MEDIAN,      // applied price
      int          MODE_GATORJAW,     // line index
      int          0                  // shift
      );

Aside from my previous question about encapsulation, I am also unsure whether to declare it a double or leave it as it is.

 
WildCard578: PS what do you mean by "encapsulate the call"?
  1. (iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORLIPS,0)>iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORTEETH,0))
    &&
    (iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORTEETH,0)>iAlligator(NULL,0,13,1,5,1,MODE_EMA,PRICE_MEDIAN,MODE_GATORJAW,0))
    This is unreadable.
    • Not counting that the teeth are missing.
    • Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read it.
    • And verifying that they are all the same except for the line selector.
    • Did you read the link provided in Detailed explanation of iCustom - MQL4 forum? What part of "encapsulating in a function #26," was unclear? The iCustom is irrelevant. Stop cutting and pasting the same thing over and over.

  2. double   alligator(int line, int shift=0){
       return alligator(_Symbol, PERIOD_CURRENT, line, shift);
    }
    double   alligator(ENUM_TIMEFRAMES tf, int line, int shift=0){
       return alligator(_Symbol, tf, line, shift);
    }
    double   alligator(string sym, ENUM_TIMEFRAMES tf, int line, int shift=0){
       int                  jawPeriod         = 13;
       int                  jawShift          = 1;
       int                  teethPeriod       = 5;
       int                  teethShift        = 1;
       int                  lipsPeriod        = 5;
       int                  lipsShift         = 1;
       ENUM_MA_METHOD       averagingMethod   = MODE_EMA;
       ENUM_APPLIED_PRICE   appliedPrice      = PRICEMEDIAN;
       return iAlligator(sym, tf, jawPeriod, jawShift, lipsPeriod, lipsShift,
                         teethPeriod, teethShift, averagingMethod, appliedPrice,
                         line, shift);
    }
    ////////////////////////////////////////////////////////////////////////////
    double   lip   = alligator(MODE_GATORLIPS);  // \
    double   teeth = alligator(MODE_GATORTEETH); //  > Encapsulated calls.
    double   jaw   = alligator(MODE_GATORJAW);   // /
    (lip>teeth)                                  // \
    &&                                           //  > This is readable
    (teeth>jaw)                                  // /
    
  3. If you ever want to change the periods, etc., of if you want them set from extern/inputs, it's at one place, just above the one iAlligator call.
 

You are totally right about books, a nice and clean example.

Yet, as one learns reading and writing, they do not teach him/her how to write with a Gutenberg bible layout style.

That comes much later, after years of school.


As I said in the OP, I am very new to MQL4 (and coding in general), so forgive me as I scribble on paper (i.e. code) like a six-years-old child at school.

But we all gotta start somewhere and learn from there onward, right?


I confess I was reading for the third time (not a charm though) the post you linked without really understanding what you were showing me (guess I was focusing too hard on the topic in general rather than focusing only on #26).

That kind of coding is a bit out of my reach at the moment as I am still wrapping my head around the base code.

Thankfully you went on to provide me an example that I could recognize and understand much more easily.


It is my understanding that by "encapsulate" you mean writing a dedicated function, structured in such a way that eliminates redundant code (no doubles), streamlines execution of the code and makes signal behavior selection much easier (lip>teeth & teeth > jaw).

Am I correct in understanding this?

 

whroeder1, thank you for your detailed answers.

I've peeked at the links and looks like the answers are there.

I will check them again later on, amend my errors and post the new indicator for further comments.

Also, I failed to mention that <...> was meant to be an omissis of the parameters already given (MODE_EMA,PRICE_MEDIAN,MODE_GATORTEETH,).

That's right

Reason: