Tuesday 18 December 2012

ContohEA3.mq4


//+------------------------------------------------------------------+
//|                                                    ContohEA3.mq4 |
//|                                      Copyright © 2008, Forexindo |
//|                                         http://www.forexindo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Forexindo"
#property link      "http://www.forexindo.com"

extern double RiskPercent=5;
extern int StopLoss=3000;
extern int TakeProfit=3000;
extern string txComment="Order EA1";
extern int MagicNumber=12345;
extern double Lots=0.1;
extern int Slippage=5;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
         if (BuySignal() ) //kalau ada signal buy
         {
            Print("Switch to buy");
            
            //1=sell
            closePos(1);
            if (bolehTrade())
            {
               OrderSend(Symbol(),OP_BUY,itungLot(),Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,txComment,MagicNumber,Blue);
            }
         }
         else if (SellSignal() ) //kalau ada signal sell
         {
            Print("Switch to sell");
            
            //0=buy
            
            closePos(0);
            if (bolehTrade())
            {
               OrderSend(Symbol(),OP_SELL,itungLot(),Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,txComment,MagicNumber,Red);
            }
         }
         
      
//----
   return(0);
  }
//+------------------------------------------------------------------+

bool BuySignal()
{
   //kalau harga close candle sebelumnya lebih besar/diatas EMA 10 pada candle sebelumnya 
   if (iClose(Symbol(),0,1) > iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1) )
   {
      return(true);
   }
   else
   {
      return(false);
   }
}

bool SellSignal()
{
   //kalau harga close candle sebelumnya lebih kecil/dibawah EMA 10 pada candle sebelumnya 
   if (iClose(Symbol(),0,1) < iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1) )
   {
      return(true);
   }
   else
   {
      return(false);
   }
}

bool bolehTrade()
{
   //kalau jumat, EA ga trade ; atau kalau ada order terbuka, EA juga ga trade
   if (DayOfWeek()==5 || OrdersTotal()>0) { return (false); } else { return(true); }
}

double itungLot()
{
   //ini untuk itung lot secara otomatis berdasarkan SL dan persen risk
   double xLots=Lots;
   //xLots=NormalizeDouble(AccountBalance()*RiskPercent/100 /StopLoss / 10,1);
   return (xLots);
}

int closePos(int otype)
{
   
   for (int a=0; a<OrdersTotal(); a++)
   {
      Print("Order found");
      OrderSelect(a,SELECT_BY_POS,MODE_TRADES);
      if (OrderMagicNumber()==MagicNumber)
      {
         if (otype==0)
         {
            if (OrderType()==OP_BUY)
            {
            Print("Closing buy");
            OrderClose(OrderTicket(),OrderLots(),Bid,Slippage);
            }
         }
         else if (otype==1)
         {
            if (OrderType()==OP_SELL)
            {
            Print("Closing sell");
            OrderClose(OrderTicket(),OrderLots(),Ask,Slippage);
            }
         }
      }
   }
}

2 comments:

  1. Hey Everyone,

    I've created a list of the most recommended forex brokers:
    1. Most Recommended Forex Broker
    2. eToro - $50 min. deposit.

    Here is a list of top forex instruments:
    1. ForexTrendy - Recommended Probability Software.
    2. EA Builder - Custom Strategies Autotrading.
    3. Fast FX Profit - Secret Forex Strategy.

    Hopefully these lists are benificial to you.

    ReplyDelete
  2. GPS robot [10x increase of the deposit amount]

    I just finished a webinar with Mark and his partner, Antony, two days ago and it was GREAT.

    During the webinar MARK and ANTONY shared their stories to success and answered questions about their new version of the GPS Forex Robot that came out TODAY!

    ReplyDelete