Martiongale EA using "iCustom "

 

 

 

Because there are a lot of indicators, We are going to try to create an automatic sales program through the open indicator "HalfTrend".

Buy a 'long position' on arrow from the blue arrow and  settlement(liquidation) it to red arrow 

 and buy a 'short positon' on red arrow, liquidation on blue arrrow on and on ... ... 

 teach how to use ordersend and iCustom functions to buy and sell again.

 

 

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

//|                     Half Trend                                             |

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

int init()

  {

   IndicatorBuffers(7); // +1 buffer - trend[]

  

   SetIndexBuffer(0,up);

   SetIndexStyle(0,DRAW_LINE);

   SetIndexBuffer(1,down);

   SetIndexStyle(1,DRAW_LINE);

   SetIndexBuffer(2,atrlo);

   SetIndexBuffer(3,atrhi);

   SetIndexBuffer(6,trend);

   SetIndexBuffer(4,arrup);

   SetIndexBuffer(5,arrdwn);

   SetIndexEmptyValue(0,0.0);

   SetIndexEmptyValue(1,0.0);

   SetIndexEmptyValue(6,0.0);

  

   if(ShowBars)

   {

      SetIndexStyle(2,DRAW_HISTOGRAM, STYLE_SOLID);

      SetIndexStyle(3,DRAW_HISTOGRAM, STYLE_SOLID);

   }

   else

   {

      SetIndexStyle(2,DRAW_NONE);

      SetIndexStyle(3,DRAW_NONE);

   }

   if(ShowArrows)

   {

     SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID); SetIndexArrow(4,233);

     SetIndexStyle(5,DRAW_ARROW,STYLE_SOLID); SetIndexArrow(5,234);

   }

   else

   {

     SetIndexStyle(4,DRAW_NONE);

     SetIndexStyle(5,DRAW_NONE);

   }

          

    

   nexttrend=0;

   minhighprice= High[Bars-1];

   maxlowprice = Low[Bars-1];

   return (0);

  }

 

 

 

########Expert advisor###########





//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double up_signal=iCustom(NULL,0,"HalfTrend",4,0);
   double down_signal=iCustom(NULL,0,"HalfTrend",5,0);

   if(OrdersTotal()==0)
     {
      //--- Buy order
      Open_MarketOrder(OP_BUY);
     }
   else if(OrdersTotal()==0)
     {
      //--- Sell order
      Open_MarketOrder(OP_SELL);
     }
  }
//+------------------------------------------------------------------+
//| Market order function function                                                |
//+------------------------------------------------------------------+
void Open_MarketOrder(int pOrderType)
  {
   if(UseMartingale==true)
     {
      double lot_size=Calculate_Martingale();
      if(lot_size==-1)//first oder
        {
         Lot_Size=Lotsize;
        }
      else //stop_loss
        {
         Lot_Size=lot_size*MartingaleMultiplier;
         //Lot_Size=Verify_LotSize(Lot_Size);
        }
     }
   int ticketNum;
   if(pOrderType==OP_BUY)
     {
      ticketNum=OrderSend(Symbol(),OP_BUY,Lot_Size,Ask,Slippage,0,0,
                          "EA magic number:"+(string)MagicNumber,MagicNumber,0,clrGreen);
      if(ticketNum!=-1)
        {
         if(OrderSelect(ticketNum,SELECT_BY_TICKET)==true)
           {
            double stop_loss=0;
            double take_profit=0;
            if(Stoploss>0) stop_loss=OrderOpenPrice()-Stoploss*_Point;
            if(Takeprofit>0) take_profit=OrderOpenPrice()+Takeprofit*_Point;
            if(OrderModify(ticketNum,0,stop_loss,take_profit,0,clrGreen)==true)
              {
               Print("success modify. Ticket="+(string)ticketNum
                     +", sale loss="+DoubleToStr(stop_loss,_Digits)
                     +", attainment of profit="+DoubleToStr(take_profit,_Digits));
              }
            else //OrderModify error on function
              {
               Handle_Error("OrderModify");
              }
           }
         else //OrderSelect error on function
           {
            Handle_Error("OrderSelect");
           }
        }
      else //OrderSend error on function
        {
         Handle_Error("OrderSend");
        }
     }
   else if(pOrderType==OP_SELL)
     {
      ticketNum=OrderSend(Symbol(),OP_SELL,Lot_Size,Bid,Slippage,0,0,
                          "EA magic number:"+(string)MagicNumber,MagicNumber,0,clrRed);
      if(ticketNum!=-1)
        {
         if(OrderSelect(ticketNum,SELECT_BY_TICKET)==true)
           {
            double stop_loss=0;
            double take_profit=0;
            if(Stoploss>0) stop_loss=OrderOpenPrice()+Stoploss*_Point;
            if(Takeprofit>0) take_profit=OrderOpenPrice()-Takeprofit*_Point;
            if(OrderModify(ticketNum,0,stop_loss,take_profit,0,clrRed)==true)
              {
               Print("success modify="+(string)ticketNum
                     +", sale loss="+DoubleToStr(stop_loss,_Digits)
                     +", attainment of profit="+DoubleToStr(take_profit,_Digits));
              }
            else //OrderModify error on function
              {
               Handle_Error("OrderModify");
              }
           }
         else //OrderSelect error on function
           {
            Handle_Error("OrderSelect");
           }
        }
      else //OrderSend error on function
        {
         Handle_Error("OrderSend");
        }
     }
  }

 

 

 

 

 
What's your problem/question ?
 
cape1354 teach how to use ordersend and iCustom functions to buy and sell again.
  1. Perhaps you should read the manual. OrderSend - Trade Functions - MQL4 Reference
  2. You should write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum
  3. learn to code it, or pay (Freelance) someone to code it. We're not going to code it for you. We are willing to help you when you post your attempt (using SRC) and the nature of your problem.
Reason: