HA longs but no shorts?

 

Hi guys,

 

i´m a newbie in code. But i´m studying hard.

I´ve been experimenting an EA with heiken ashi and i´m running into some trouble that i´m not able to fix. 

All I want it to do is:

if it turns red go short;

if it turns blue (or green whatever) go long;

Maybe this is something i´m not aproaching the right way but:

 

- here I´m calling the indicator  

for(int i=1;i<=limit;i++)

double HA1=iCustom(Symbol(),0,"Heiken_Ashi",2,i);  //open
double HA2=iCustom(Symbol(),0,"Heiken_Ashi",3,i); //close
double HA1a=iCustom(Symbol(),0,"Heiken_Ashi",2,i+1);  //open+1
double HA2a=iCustom(Symbol(),0,"Heiken_Ashi",3,i+1);  //close+1

- here are the buy and sell conditions. As it was not opening short orders I replaced the open orders with Print to get any errors:

 

//--- buy conditions

   if (HA2>HA1 && HA2a<HA1a)
   Print("HA LONG","  error =",GetLastError());
  /* {
   
      res=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,SLlong,TPlong,"",MAGICMA,0,Blue);
      return;
    
     }
   */ 
    
//--- sell conditions
  if (HA2<HA1 && HA2a>HA1a)
  Print("HA SHORT","  error =",GetLastError());
 /*  {
  
      res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,SLshort,TPshort,"",MAGICMA,0,Red);
      return;
     
     }
*/

 

this is what i get: 

2014.07.21 11:38:17.545 2014.05.29 10:45  HA proj EA 02_2_4 EURUSD,M15: HA LONG  error =0

so, no errors on the long side.

but for shorts it won´t even get a message! I even bypassed the code on buy conditions, leaving only short conditions and... nothing! I don´t get it! shouldn´t it work? it´s the same code as the longs but only with signals (<>) reversed!

 can anyone see what´s wrong?  

 

thank you 

 
is it an indicator or an EA ?

if it's an indicator indicators can't place or close ... a trade !

if it's an EA why all the trouble using a for loop ... ?

after all you don't care what happens on bar shift 2 or 200...

the only thing that matters is the present

use it simple (something like:)

double HA1=iCustom(Symbol(),0,"Heiken_Ashi",2,0);  //last bar open 
double HA2=iCustom(Symbol(),0,"Heiken_Ashi",3,0); //last bar close
double HA1a=iCustom(Symbol(),0,"Heiken_Ashi",2,1);  //1 before last bar open
double HA2a=iCustom(Symbol(),0,"Heiken_Ashi",3,1);  //1 before last bar close
  if (HA2>HA1 && HA2a<HA1a)
  Print("HA LONG","  error =",GetLastError()); //(or trade or whatever)
  if (HA2<HA1 && HA2a>HA1a)
  Print("HA SHORT","  error =",GetLastError()); // (or trade or whatever)
 
sky_lc: so, no errors on the long side.
  1. There's no error because you didn't do anything. Don't check GLE unless you do have an error
  2. What are Function return values ? How do I use them ? - MQL4 forum
 

thank you qjol! As always you nail my questions perfectly. Yes this is meant for an EA. Removing the loop solved it... 

 WHRoeder, thank you for your observation. That is quite an interesting read... now i know there´s no reason to call GLE. 

 

This way i´m learning, so thank you both for your patience and observations.  

Reason: