Can't buy with alligator?

 

Hello,

I've decided to play around with the alligator indicator after having a look at it over the past week or so. I slotted in the parameters for this indicator into a pre-existing EA from Meta-Quotes (which, unmodified, works).

The EA opens SELL positions, modifies them appropriately and closes them as instructed.

However, it doesn't open any buy orders. This is true even if the SELL open conditions are /*commented out*/.

Is there something wrong with the following iAlligator settings and the conditions for BUY entry?

Cheers

double lips = iAlligator(NULL,0,13,3,8,0,5,-2,MODE_SMMA,PRICE_MEDIAN,MODE_GATORLIPS,0);
double teeth = iAlligator(NULL,0,13,3,8,0,5,-2,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,0);
double jaw = iAlligator(NULL,0,13,3,8,0,5,-2,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,0);


if(lips> teeth > jaw) 
  {
   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*MyPoint,"Alligator_V1",MagicNumber,0,Green);
   if(ticket>0)
     {
      if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("Buy Order Opened: ", OrderOpenPrice());
     }   
   else Print ("Error Opening Buy Order: ", GetLastError());
   return(0);
  }
 
if(lips> teeth > jaw) { /* buy */ }

Is that even valid code in MQL? I have never used such syntax!

I could be wrong but should it not be like this ...

if( ( lips > teeth ) && ( teeth > jaw ) ) { /* buy */ }
 
FMIC:

Is that even valid code in MQL? I have never used such syntax!

I could be wrong but should it not be like this ...


Hi FMIC,

Mmm, I'm sure I'd seen that type of statement before. I'm not really one to comment on it's validity (I'm pretty new to MQL4).

Also, the SELL open statement is also made in this format (lips<teeth<jaw) and seems to trade ok. I tried your suggestion anyways (with the SELL operations operating and commented out) and it makes no difference to the lack of BUY placement.

Anyone have any ideas. I'm sure its something completely noobish that I have overlooked but I've looked, over and under, and can't seem to figure this one out.

Cheers

 

I can only comment on the Code. I do not know the "Alligator" well enough to comment on its functionality.

However, why don't you insert some "Print" statements in your code, so as to print out to the Journal/Experts log various variables and states and see where the code is going (or not going).

It is called "debugging" and is how most programmers, including MQL, analyse the logic and see where the bugs are.

I am not being sarcastic! Since you stated that you are new to MQL, I am assuming you're are also new to programming and might not know that.

Ref. for Print function is https://docs.mql4.com/common/Print

double lips = iAlligator(NULL,0,13,3,8,0,5,-2,MODE_SMMA,PRICE_MEDIAN,MODE_GATORLIPS,0);
double teeth = iAlligator(NULL,0,13,3,8,0,5,-2,MODE_SMMA,PRICE_MEDIAN,MODE_GATORTEETH,0);
double jaw = iAlligator(NULL,0,13,3,8,0,5,-2,MODE_SMMA,PRICE_MEDIAN,MODE_GATORJAW,0);

Print( "Lips: ", DoubleToStr( lips, Digits ),
        "; Teeth: ", DoubleToStr( teeth, Digits ),
        "; Jaw: ", DoubleToStr( jaw, Digits ) );

if( ( lips > teeth ) && ( teeth > jaw ) ) 
  {
   Print( "Buy Condition is valid!"  );
   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*MyPoint,"Alligator_V1",MagicNumber,0,Green);
   Print( "Buy Ticket: ", ticket  );
   if(ticket>0)
     {
      if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("Buy Order Opened: ", OrderOpenPrice());
     }   
   else Print ("Error Opening Buy Order: ", GetLastError());
   return(0);
  }
 
SteepCurve:

Hello,

I've decided to play around with the alligator indicator after having a look at it over the past week or so. I slotted in the parameters for this indicator into a pre-existing EA from Meta-Quotes (which, unmodified, works).

The EA opens SELL positions, modifies them appropriately and closes them as instructed.

However, it doesn't open any buy orders. This is true even if the SELL open conditions are /*commented out*/.

Is there something wrong with the following iAlligator settings and the conditions for BUY entry?

Cheers


Place the alligator indicator on a chart with the settings you have chosen here

what value has lips at bar 0 ???

you can see the values also if you view data window (CTRL + D)

and move with mouse over the bars

 
FMIC:

Is that even valid code in MQL? I have never used such syntax!

I could be wrong but should it not be like this ...

Been through all this before . . .

https://www.mql5.com/en/forum/141790

 

Thank you everyone for their replies.

FMIC and deVries, you both demonstrated very different ways of solving a problem that had the same answer. That is, a shift of -2 on the Jaws line means no value on either the 0 or 1 bar (seems obvious in hindsight)

.


RaptorUK, thank you for the link. Even with the help of those above i would still be lost. The logic makes sense.


Cheers.

 
if(lips> teeth > jaw) { /* buy */ }
FMIC: Is that even valid code in MQL? I have never used such syntax!
RaptorUK: Been through all this before . . . https://www.mql5.com/en/forum/141790
Yes we have "1.8<1.7<1.6<1.5 is TRUE?"
Reason: