My EA only open BUY traders

 
Hi there. I've paid to a coder to make this EA for me and it only open BUY ORDERS.

He doesn't answer me anymore.

May anyone please help me to fix this little issue?


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

//|                                                         HA's.mq4 |

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

   

extern double  Stop_Loss=150;

extern int     SlipPage=3;

extern double  Risco=3;

extern string  Take_Profit_em_Pips="---------";

extern double  Tp1=50;

extern double  Tp2=50;

extern double  Tp3=50;

extern double  Tp4=50;

extern string  Porção_da_Ordem="---em (%)----";

extern int     Tp_1=50;

extern int     Tp_2=20;

extern int     Tp_3=20;

extern int     Tp_4=10;





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

//| expert initialization function                                   |

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

int init()

  {

   return(0);

  }

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

//| expert deinitialization function                                 |

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

int deinit()

  {

   return(0);

  }

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

//| expert start function                                            |

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

int x,y,ticket,modbuy,modsell,z,ordem,i,b,Q,W,E,R,T,Y,sl;

double lot,open,bid_anterior;

double lote1,lote2,lote3,lote4;

int start()

{

  

   //--------------IDENTIFICAR ORDENS AO REINICIAR O EA ---------------------------

   if(OrdersTotal()>0 && OrderType()==OP_BUY)y=1; 

   if(OrdersTotal()>0 && OrderType()==OP_SELL)x=1;

    

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

//| ---------- DEFINIR TAMANHO DOS LOTES -------------------                            |

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

   

   //-- IDENTIFICAR A MENOR DISTANCIA ENTRE LOTES -- DEFINIR MINI OU MICRO ------

   if(MarketInfo(Symbol(),MODE_LOTSTEP)==0.1)i=1;  //BROKER TRABALHA COM MINILOTES, 0.1

   if(MarketInfo(Symbol(),MODE_LOTSTEP)==0.01)i=2; //BROKER TRABALHA COM MICROLOTES, 00.1

   

   //---- CALCULO DOS LOTES DE ACORDO COM "STOP LOSS" E "RISCO" -----------

   double lots = NormalizeDouble((AccountBalance()*Risco/Stop_Loss/100),i);

   

   //---SE VALOR DO STOP EM $$ FOR MAIOR QUE RISCO EM $$, ARRENDONDA PARA BAIXO ---------

   if(lots<1 && ((MarketInfo(Symbol(),15)*Point*lots*Stop_Loss)>(AccountBalance()*Risco/100)))

   {lots=lots-0.1;}

   

   //----SE LOTE FOR MENOR QUE 0.1 NAO ABRE ORDEM-------------------------------

   if(lots<0.1)

   {

      lots=0;

      Comment(

      "\n","------------------------------------------",

      "\n","Lote menor que 0.1 --> Não Abrir Ordens",

      "\n","------------------------------------------");

      return(0);

   }

   

   //----SE LOTE FOR MAIOR QUE O MAXIMO PERMITIDO, IGUALA AO MAXIMO ------------

   if(lots>MarketInfo(Symbol(),MODE_MAXLOT))lots=MarketInfo(Symbol(),MODE_MAXLOT);

      

     

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

//| ----------- INDICADORES ---------------                                            |

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

   

   //------------- HA MENOR ---------------

   double ha1=iCustom(Symbol(),0,"HAS",0,1);  

   double ha2=iCustom(Symbol(),0,"HAS",1,1);

         

   //------------- HA MEDIO ---------------

   double ha3=iCustom(Symbol(),0,"HAS1",0,1);  

   double ha4=iCustom(Symbol(),0,"HAS1",1,1);  

   

   //------------- HA MAIOR ---------------

   double ha5=iCustom(Symbol(),0,"HAS2",0,1);   

   double ha6=iCustom(Symbol(),0,"HAS2",1,1); 



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

//|-- SÓ ABRIR A 1º ORDEM APÓS IDENTIFICAR A 1º MUDANÇA DE LADO DE UM DOS INDICADORES -|

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

   

   if(OrdersTotal()==0)

   {

      if((ha1>ha2&&ha3>ha4&&ha5>ha6) || (ha1<ha2&&ha3<ha4&&ha5<ha6) && z==0 && ordem==0)

      {

         Comment(

         "\n","______________________",

         "\n",

         "\n","  Aguardando mudança nos Indicadores...",

         "\n","______________________");

         return(0);

      }

      else {z=1;sl=0;}

   }

   

   if(OrdersTotal()==0 && z==1 && ordem==1){z=0;ordem=0;sl=1;}

   

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

//| ---------- SINAIS DE ENTRADA -----------                                         |

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

   

   if(OrdersTotal()==0 && sl==0)

   {

      RefreshRates();

      x=0;y=0;Q=0;W=0;E=0;R=0;

      lote1=0;lote2=0;lote3=0;lote4=0;

      

      //-----SELL----   

      if(x==0 && ha1>ha2 && ha3>ha4 && ha5>ha6)

      {

         ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,SlipPage,0,0,NULL,0,0,Magenta);

         if(GetLastError()==0){Print("ORDEM SELL");x=1;y=0;modsell=1;ordem=1;} 

         else Print("ERRO ORDEM SELL:"+GetLastError());

      }

    

      //-----BUY-----  

      if(y==0 && ha1<ha2 && ha3<ha4 && ha5<ha6)

      {

         ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,SlipPage,0,0,NULL,0,0,Blue);

         if(GetLastError()==0){Print("ORDEM BUY");y=1;x=0;modbuy=1;ordem=1;}

         else Print("ERRO ORDEM BUY:"+GetLastError());

      }

   }

   

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

//| SINAL DE SAIDA                                                   |

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

   

   OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

   lot=OrderLots();

   open=OrderOpenPrice();

   ticket=OrderTicket();

   RefreshRates();

   

   //-----SELL----     

   if(x==1 && (ha1<ha2 || ha3<ha4 || ha5<ha6))

   {

      OrderClose(ticket,lot,Ask,SlipPage,White);

      if(GetLastError()==0){Print("CLOSE SELL");x=0;}

      else Print("ERRO CLOSE SELL:"+GetLastError());

   }

   

   //-----BUY-----  

   if(y==1 && (ha1>ha2 || ha3>ha4 || ha5>ha6))

   {

      OrderClose(ticket,lot,Bid,SlipPage,White);

      if(GetLastError()==0){Print("CLOSE BUY");y=0;}

      else Print("ERRO CLOSE BUY:"+GetLastError());

   }



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

//| ATRIBUIR STOP LOSS                                               |

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

 

   //-----SELL----

   if(modsell==1)

   {   

      RefreshRates();

      if(OrderModify(ticket,open,open+Stop_Loss*Point,0,0)==true)

      {modsell=0;Print("SELL MODIFICADO");}

      else Print("ERRO AO MODIFICAR SELL");

   }



   //-----BUY----- 

   if(modbuy==1)

   {

      RefreshRates();

      if(OrderModify(ticket,open,open-Stop_Loss*Point,0,0)==true)

      {modbuy=0;Print("BUY MODIFICADO");}

      else Print("ERRO AO MODIFICAR BUY");

   }

   

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

//| Definir Lotes para Fechamento                                    |

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

   

   if(lote1==0)lote1=NormalizeDouble((lot*Tp_1/100),1);

   if(lote2==0)lote2=NormalizeDouble((lot*Tp_2/100),1);

   if(lote3==0)lote3=NormalizeDouble((lot*Tp_3/100),1);

   if(lote4==0)lote4=NormalizeDouble(lot-lote1-lote2-lote3,1);

      

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

//| Monitorar Fechamento Buy                                         |

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



   RefreshRates();

   

   //-----TP 50 PIPS-----20% DA ORDEM------------

   if(OrderType()==OP_BUY && Bid>=open+(Tp1*Point) && Q==0)

   {

      Q=1;

      OrderClose(ticket,lote1,Bid,SlipPage,White); 

      if(GetLastError()==0){Print("CLOSE BUY");Q=1;}

      else Print("ERRO CLOSE BUY:"+GetLastError());

   }

   

   //-----TP 50 PIPS-----40% DA ORDEM------------

   if(OrderType()==OP_BUY && Bid>=open+((Tp2+Tp1)*Point) && W==0)

   {

      W=1;

      OrderClose(ticket,lote2,Bid,SlipPage,White); 

      if(GetLastError()==0){Print("CLOSE BUY");W=1;}

      else Print("ERRO CLOSE BUY:"+GetLastError());

   }

   

   //-----TP 50 PIPS-----30% DA ORDEM------------

   if(OrderType()==OP_BUY && Bid>=open+((Tp3+Tp2+Tp1)*Point) && E==0)

   {

      E=1;

      OrderClose(ticket,lote3,Bid,SlipPage,White); 

      if(GetLastError()==0){Print("CLOSE BUY");E=1;}

      else Print("ERRO CLOSE BUY:"+GetLastError());

   }

   

   //-----TP 50 PIPS-----10% DA ORDEM------------

   if(OrderType()==OP_BUY && Bid>=open+((Tp4+Tp3+Tp2+Tp1)*Point) && R==0)

   {

      R=1;

      OrderClose(ticket,lote4,Bid,SlipPage,White); 

      if(GetLastError()==0){Print("CLOSE BUY");R=1;z=0;ordem=0;}

      else Print("ERRO CLOSE BUY:"+GetLastError());

   }

      

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

//| Monitorar Fechamento Sell                                        |

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

   

   RefreshRates();

   

   //-----TP 50 PIPS-----20% DA ORDEM------------

   if(OrderType()==OP_SELL && Ask<=open-Tp1*Point && Q==0)

   {

      Q=1;

      OrderClose(ticket,lote1,Ask,SlipPage,White);

      if(GetLastError()==0){Print("CLOSE SELL");Q=1;}

      else Print("ERRO CLOSE SELL:"+GetLastError());

   }

   

   //-----TP 50 PIPS-----40% DA ORDEM------------

   if(OrderType()==OP_SELL && Ask<=open-((Tp2+Tp1)*Point) && W==0)

   {

      W=1;

      OrderClose(ticket,lote2,Ask,SlipPage,White);

      if(GetLastError()==0){Print("CLOSE SELL");W=1;}

      else Print("ERRO CLOSE SELL:"+GetLastError());

   }

   

   //-----TP 50 PIPS-----30% DA ORDEM------------

   if(OrderType()==OP_SELL && Ask<=open-((Tp3+Tp2+Tp1)*Point) && E==0)

   {

      E=1;

      OrderClose(ticket,lote3,Ask,SlipPage,White);

      if(GetLastError()==0){Print("CLOSE SELL");E=1;}

      else Print("ERRO CLOSE SELL:"+GetLastError());

   }

   

   //-----TP 50 PIPS-----10% DA ORDEM------------

   if(OrderType()==OP_SELL && Ask<=open-((Tp4+Tp3+Tp2+Tp1)*Point) && R==0)

   {

      R=1;

      OrderClose(ticket,lote4,Ask,SlipPage,White);

      if(GetLastError()==0){Print("CLOSE SELL");R=1;z=0;ordem=0;}

      else Print("ERRO CLOSE SELL:"+GetLastError());

   }

      

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

//| -----------FIM----------------                                   |

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

   

   //-----Comentarios-------

   

   string r=DoubleToStr(Risco,2);

   string stop=DoubleToStr((Stop_Loss/10),1);

   string tp11=DoubleToStr((Tp1/10),1);

   string tp12=DoubleToStr((Tp2/10),1);

   string tp13=DoubleToStr((Tp3/10),1);

   string tp14=DoubleToStr((Tp4/10),1);  

   string l=DoubleToStr(lots,2);

   string p=DoubleToStr((MarketInfo(Symbol(),MODE_LOTSIZE)*Point*lots*10),2);//x10 para broker de 5 dig

   string saldo=DoubleToStr(AccountBalance(),2);

   string aberto=DoubleToStr(AccountEquity(),2);

   string sl=DoubleToStr((MarketInfo(Symbol(),MODE_LOTSIZE)*Point*lots*10)*(Stop_Loss/10),2);

   string porcento=DoubleToStr( (MarketInfo(Symbol(),MODE_LOTSIZE)*Point*lots*Stop_Loss/AccountBalance()*100),2);

   

   if(OrdersTotal()==0)

   {

      Comment(

      "\n","------------------------------------",

      "\n","  EA Preparado para Abrir Ordem...",

      "\n","------------------------------------",

      "\n","  Stop_Loss= "+stop," pips",

      "\n","  Take_Profit 1 = "+tp11," pips, "+Tp_1,"%",

      "\n","  Take_Profit 2 = "+tp12," pips, "+Tp_2,"%",

      "\n","  Take_Profit 3 = "+tp13," pips, "+Tp_3,"%",

      "\n","  Take_Profit 4 = "+tp14," pips, "+Tp_4,"%",

      "\n","  Fator de Risco= "+r,"%",

      "\n","  Lotes= "+l,

      "\n","------------------------------------",

      "\n","  Saldo Fechado= $"+saldo,

      "\n","  Saldo em Aberto= $"+aberto,

      "\n","------------------------------------");

   }

   

   if(OrdersTotal()>0)

   {

      if(OrderType()==OP_SELL)

      {

         Comment(

         "\n","------------------------------------",

         "\n","  Ordem Sell Aberta...",

         "\n","------------------------------------",

         "\n","  Stop_Loss= "+stop," pips",

         "\n","  Take_Profit 1 = "+tp11," pips, ",+Tp_1,"%",

         "\n","  Take_Profit 2 = "+tp12," pips, ",+Tp_2,"%",

         "\n","  Take_Profit 3 = "+tp13," pips, ",+Tp_3,"%",

         "\n","  Take_Profit 4 = "+tp14," pips, ",+Tp_4,"%",

         "\n","  Fator de Risco= "+r,"%",

         "\n","  Lotes= "+l,

         "\n","------------------------------------",

         "\n","  Valor do Pip= $"+10,

         "\n","  Valor do Stop Loss= $"+sl,

         "\n","  Stop Loss Equivale a "+porcento,"% do Saldo", 

         "\n","------------------------------------",

         "\n","  Saldo Fechado= $"+saldo,

         "\n","  Saldo em Aberto= $"+aberto,

         "\n","------------------------------------");          

      }

      

      if(OrderType()==OP_BUY)

      {

         Comment(

         "\n","------------------------------------",

         "\n","  Ordem Buy Aberta...",

         "\n","------------------------------------",

         "\n","  Stop_Loss= "+stop," pips",

         "\n","  Take_Profit 1 = "+tp11," pips, "+Tp_1,"%",

         "\n","  Take_Profit 2 = "+tp12," pips, "+Tp_2,"%",

         "\n","  Take_Profit 3 = "+tp13," pips, "+Tp_3,"%",

         "\n","  Take_Profit 4 = "+tp14," pips, "+Tp_4,"%",

         "\n","  Fator de Risco= "+r,"%",

         "\n","  Lotes= "+l,

         "\n","------------------------------------",

         "\n","  Valor do Pip= $"+p,

         "\n","  Valor do Stop Loss= $"+sl,

         "\n","  Stop Loss Equivale a "+porcento,"% do Saldo", 

         "\n","------------------------------------",

         "\n","  Saldo Fechado= $"+saldo,

         "\n","  Saldo em Aberto= $"+aberto,

         "\n","------------------------------------");

      }

   }

     

   return(0);

  }

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


 
Please edit your post and use code tags, see the </> symbol in the editor panel.
 
lippmaje:
Please edit your post and use code tags, see the </> symbol in the editor panel.

Thanks lippmaje.


Is that correct now?


If anyone could help me , i appreciate.


The EA does NOT open SELL trades.

 

There's an operator precedence issue on this line:

if((ha1>ha2&&ha3>ha4&&ha5>ha6) || (ha1<ha2&&ha3<ha4&&ha5<ha6) && z==0 && ordem==0)

I suggest to change it to:

if(((ha1>ha2&&ha3>ha4&&ha5>ha6) || (ha1<ha2&&ha3<ha4&&ha5<ha6)) && z==0 && ordem==0)
 
lippmaje:

There's an operator precedence issue on this line:

I suggest to change it to:

Thank you a lot!


If possible, can you help me to imput a simple "hour trading period" filter on this code ( "extern int" ) ?

 

Add this to the top:

extern int TradingFrom=00;
extern int TradingTill=24;

And replace this line:

if(OrdersTotal()==0 && sl==0)

with:

MqlDateTime currtime;
TimeCurrent(currtime);

if(OrdersTotal()==0 && sl==0 && currtime.hour>=TradingFrom && currtime.hour<TradingTill)
 
Hi my name is Syed! may I firstly thank you for your time and effort go read my message. I have been proactively researching your articles which I thoroughly  enjoy reading. I was wondering if any of you could please guide me with regards to the steps one should take when evaluating as to whether or not to enter a trade... so this is how I do it..
How I trade when buying, same for sell but opposite:

Ok so I start off by,
1) looking for tk cross (weak signal)
2) check if tenkenshen is above kijunsen above bullish cloud also check if price is above cloud too
3) check to see if chickouspan is level or greater than bullish cloud 
4) Furthermore check if chikouspan has hit price line recently ie is it giving a weak/neutral/strong bullish signal?
5) Lastly check if the same readings are on H1 and M1 (steps 1 - 3) (I trade only on H1 and M1)
6) Continuously keep checking M1 chart, the moment to ‘exit a trade signal’ comes I then end the trade.

So are there any more or other signals I should lookout for? Before a trade and within a trade that will help me be...thanks.


 
Syed110786:
Hi my name is Syed! may I firstly thank you for your time and effort go read my message. I have been proactively researching your articles which I thoroughly  enjoy reading. I was wondering if any of you could please guide me with regards to the steps one should take when evaluating as to whether or not to enter a trade... so this is how I do it..
You may want to open a new topic for this to reach a wider audience. Use the 'New topic' button next to 'Trading Systems' in the forum page.
Reason: