double MACD combination ea

 

hello   everybody. I try to learn mql programming with your site. İt is very useful . 

 

 I  made  ea  but need your help.

with macd 24.400.20 and  macd 12.26.13. (  only  buy no sell   at macd 24.400.20  >0  )

Buy rule:a)   macd 24.400.20 shift2 <=0   ,macd 24.400.20 shift1 >0

b) macd 24.400.20 shift 0  >0 , macd 12.26.13. shift 1<=0 , macd 12.26.13. shift 0 >0     

 it closes at  reverse condition.


  it is logically good ea but there is a fault. It doesnt open position on condition b. ı read mql book but ı couldnt find the solution. is there a return problem how can solve this mistake. could you help me

 I tried to  rearrange my message.

extern int MagicNumber=10001;
extern double Lots =0.1;
extern double StopLoss=20;
extern double TakeProfit=50;
extern int TrailingStop=0;
extern int Slippage=3;
//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+
int start()
{
  double MyPoint=Point;
  if(Digits==3 || Digits==5) MyPoint=Point*10;
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 ) 
  {
     int result=0;
     if((iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,2)<=0)&&(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,1)>0)||(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,0)>0)&&(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,2)<=0)&&(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,1)>0)) // Here is your open buy rule
     {
        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,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);
     }
     if((iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,2)>=0)&&(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,1)<0)||(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,0)<0)&&(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,2)>=0)&&(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,1)<0)) // Here is your open Sell rule
     {
        result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,MagicNumber,0,Red);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Bid-TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Bid+StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
     }
  }
  
  for(int cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL &&   
         OrderSymbol()==Symbol() &&
         OrderMagicNumber()==MagicNumber 
         )  
        {
         if(OrderType()==OP_BUY)  
           {
              if((iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,2)>=0)&&(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,1)<0)||(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,1)>=0)&&(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,0)<0)&&(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,0)>0)) //here is your close buy rule
              {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
              }
            if(TrailingStop>0)  
              {                 
               if(Bid-OrderOpenPrice()>MyPoint*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-MyPoint*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MyPoint,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         else 
           {
                if((iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,2)<=0)&&(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,1)>0)||(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,1)<=0)&&(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,0)>0)&&(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,0)<0)) // here is your close sell rule
                {
                   OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),Slippage,Red);
                }
            if(TrailingStop>0)  
              {                 
               if((OrderOpenPrice()-Ask)>(MyPoint*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+MyPoint*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+MyPoint*TrailingStop,OrderTakeProfit(),0,Red);
                     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);
}
 
aliuzun:

hello   everybody. I try to learn mql programming with your site. İt is very useful . 

 

 I  made  ea  but need your help.

<CODE REMOVED>

Please read some other posts before posting . . .

Please edit your post . . .    please use the   SRC   button to post code: How to use the   SRC   button. 

 
  1. Use SRC
  2. Check your return codes and Print errors so you find out why
  3.      if((iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,2)<=0)&&(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,1)>0) ||(iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,0)>0)&&(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,2)<=0)&&(iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,1)>0)) // Here is your open buy rule
    Don't write unreadable, non-understandable likely typo-error filled code.
    double MACD1(int iBar){
       return( iMACD(NULL,0,24,400,20,PRICE_CLOSE,MODE_MAIN,iBar) ); 
    }
    double MACD2(int iBar){
       return( iMACD(NULL,0,12,26,13,PRICE_CLOSE,MODE_MAIN,iBar) ); 
    }
    :
       double macd12 = MACD1(2), macd22 = MACD2(2),
              macd11 = MACD1(1), macd21 = MACD2(1),
              macd10 = MACD1(0);
       bool isBuy1 = macd12 <= 0 && macd11 >  0,
            isBuy2 = macd10 >  0 && macd22 <= 0 && macd21 > 0;
       if(isBuy1 || isBuy) // Here is your open buy rule
    Now you can print the values and the test variables and find out WHY it doesn't open.
  4. When closing, you MUST count down. Get in the habit of always counting down.
Reason: