Open Forex4you Account

Server รัน EA 1000 / ปี

สั่งชื้อคู่มือการโปรแรกม MQL4

Author Topic: ถามเอ็ดมินครับ ผมจะสามารถแก้ ea ตัวนี้ให้ใช้กับโบรกเกอร์ 4 จุดได้ไหมครับ  (Read 15094 times)

ruddy01

  • Newbie
  • *
  • Posts: 38
--------------------------------------------------------------------------------------------------------------

//+------------------------------------------------------------------+
//|                                                 Navin Prithyani  |
//|                      Copyright ฉ 2009, MetaQuotes Software Corp. |
//|                                               www.urbanforex.com |
//+------------------------------------------------------------------+
#property copyright "Copyright ฉ 2009, MetaQuotes Software Corp."
#property link      "www.urbanforex.com"

//pairs. (EURUSD, USDJPY, GBPUSD, USDCHF, USDCAD)
//TF = M5
extern int TakeProfit = 3;
extern int InitialStop = 20;
extern double Lots = 0.1;
extern int MaxOrder=1;
double sl=0, tp=0;
int         OpenOrders=0, cnt=0;
int         mode=0;
double      BuyPrice=0, SellPrice=0;
double      PriceOpenPrev,PriceOpenCurr,PriceClosePrev,PriceCloseCurr ;
double      EmaHight, EmaClose, EmaLow, Sma;
double      BarsDownH1,BarsDownM30,BarsDownM15,BarsDownM5;
double      BarsUpH1,BarsUpM30,BarsUpM15,BarsUpM5;
double      BollingerUP, BollingerLow , BollingerMiddle;
double      RSICURR, RSIPREV, StochCURR, StochPREV;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   OpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol())
     {           
          OpenOrders++;
     }
   }     

   PriceOpenPrev  = iOpen(NULL,0,1);
   PriceClosePrev = iClose(NULL,0,1);
   PriceOpenCurr  = iOpen(NULL,0,0);
   PriceCloseCurr = iClose(NULL,0,0);
   
   EmaHight       = iMA(NULL,0,80,0,MODE_EMA,PRICE_HIGH,0);
   EmaClose       = iMA(NULL,0,80,0,MODE_EMA,PRICE_CLOSE,0);
   EmaLow         = iMA(NULL,0,80,0,MODE_EMA,PRICE_LOW,0);
   Sma            = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
   
   BarsUpH1         = iCustom(NULL,0,"ForexFreedomBars",1,0);
   BarsUpM30        = iCustom(NULL,0,"ForexFreedomBars",3,0);   
   BarsUpM15        = iCustom(NULL,0,"ForexFreedomBars",5,0);
   BarsUpM5         = iCustom(NULL,0,"ForexFreedomBars",7,0);
   
   BarsDownH1         = iCustom(NULL,0,"ForexFreedomBars",0,0);
   BarsDownM30        = iCustom(NULL,0,"ForexFreedomBars",2,0);
   BarsDownM15        = iCustom(NULL,0,"ForexFreedomBars",4,0);
   BarsDownM5         = iCustom(NULL,0,"ForexFreedomBars",6,0);
   
   BollingerUP    = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
   BollingerLow   = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
   BollingerMiddle= (BollingerUP + BollingerLow) / 2;
   
   RSICURR        = iRSI(NULL,0,14,PRICE_CLOSE,0);     
   RSIPREV        = iRSI(NULL,0,14,PRICE_CLOSE,1);
   StochCURR      = iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_MAIN,0);
   StochPREV      = iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_MAIN,1);
   
   
/*         
   Comment  ("EmaHight = ",EmaHight,
            "\nEmaClose = ",EmaClose,
            "\nEmaLow = ",EmaLow,
            "\nSma = ",Sma,
            "\nBarsUpH1 = ",BarsUpH1,
            "\nBarsUpM30 = ",BarsUpM30,
            "\nBarsUpM15 = ",BarsUpM15,
            "\nBarsUpM5 = ",BarsUpM5,
            "\nBarsDownH1 = ",BarsDownH1,
            "\nBarsDownM30 = ",BarsDownM30,
            "\nBarsDownM15 = ",BarsDownM15,
            "\nBarsDownM5 = ",BarsDownM5);   
*/           
if (OpenOrders<1)
{           
      if (PriceOpenCurr > EmaHight  && PriceOpenCurr > EmaClose && PriceOpenCurr > EmaLow && PriceOpenCurr > Sma && BarsUpH1 !=0 && BarsUpM30 !=0 && BarsUpM15 !=0 && BarsUpM5 !=0 && (PriceOpenCurr-Sma <=10*Point || PriceOpenCurr-EmaHight <=10*Point) && Sma-EmaHight<10*Point && BollingerUP-BollingerLow>15*Point && RSICURR>RSIPREV && StochCURR>StochPREV  )
      {
          BuyPrice=Ask;
          if (TakeProfit==0) { tp=0; }
          else { tp=BuyPrice+TakeProfit*Point; }   
          if (InitialStop==0)  { sl=0; }
          else { sl=BuyPrice-InitialStop*Point; }
          OrderSend(Symbol(),OP_BUY,Lots,BuyPrice,3,sl,tp,NULL,0,0,Blue);
      }   
      if (PriceOpenCurr < EmaHight  && PriceOpenCurr < EmaClose && PriceOpenCurr < EmaLow && PriceOpenCurr < Sma && BarsDownH1 !=0 && BarsDownM30 !=0 && BarsDownM15 !=0 && BarsDownM5 !=0 && (Sma-PriceOpenCurr <=10*Point || EmaLow-PriceOpenCurr <=10*Point) && EmaLow-Sma<10*Point && BollingerUP-BollingerLow>15*Point && RSICURR<RSIPREV && StochCURR<StochPREV )
      {
          SellPrice=Bid;           
          if (TakeProfit==0) { tp=0; }
          else { tp=SellPrice-TakeProfit*Point; }   
          if (InitialStop==0) { sl=0; }
          else { sl=SellPrice+InitialStop*Point;  }
          OrderSend(Symbol(),OP_SELL,Lots,SellPrice,3,sl,tp,NULL,0,0,Red);
      }   
}

//----
if(OpenOrders!=0 && PriceOpenCurr<Sma)
  {
     for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          mode=OrderType();
        if (OrderSymbol()==Symbol())
        {
         if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Blue); }
        }
     }
  }

if(OpenOrders!=0 && PriceOpenCurr>Sma)
  {
     for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          mode=OrderType();
        if (OrderSymbol()==Symbol())
        {
         if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red); }
        }
     }
  }
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+

admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
ได้ลองเปิด Demo กับ 4 จุดดูหรือยังครับ

ruddy01

  • Newbie
  • *
  • Posts: 38
ได้ลองเปิด Demo กับ 4 จุดดูหรือยังครับ

ลองเปิดกับ 4 จุด มันขึ้นแบบนี้ครับ


admin

  • Administrator
  • Hero Member
  • *****
  • Posts: 2386
#property copyright "Copyright ฉ 2009, MetaQuotes Software Corp."
#property link      "www.urbanforex.com"

//pairs. (EURUSD, USDJPY, GBPUSD, USDCHF, USDCAD)
//TF = M5
extern int TakeProfit = 3;
extern int InitialStop = 20;
extern double Lots = 0.1;
extern int MaxOrder=1;
double sl=0, tp=0;
int         OpenOrders=0, cnt=0;
int         mode=0;
double      BuyPrice=0, SellPrice=0;
double      PriceOpenPrev,PriceOpenCurr,PriceClosePrev,PriceCloseCurr ;
double      EmaHight, EmaClose, EmaLow, Sma;
double      BarsDownH1,BarsDownM30,BarsDownM15,BarsDownM5;
double      BarsUpH1,BarsUpM30,BarsUpM15,BarsUpM5;
double      BollingerUP, BollingerLow , BollingerMiddle;
double      RSICURR, RSIPREV, StochCURR, StochPREV;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   OpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol())
     {           
          OpenOrders++;
     }
   }     

   PriceOpenPrev  = iOpen(NULL,0,1);
   PriceClosePrev = iClose(NULL,0,1);
   PriceOpenCurr  = iOpen(NULL,0,0);
   PriceCloseCurr = iClose(NULL,0,0);
   
   EmaHight       = iMA(NULL,0,80,0,MODE_EMA,PRICE_HIGH,0);
   EmaClose       = iMA(NULL,0,80,0,MODE_EMA,PRICE_CLOSE,0);
   EmaLow         = iMA(NULL,0,80,0,MODE_EMA,PRICE_LOW,0);
   Sma            = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,0);
   
   BarsUpH1         = iCustom(NULL,0,"ForexFreedomBars",1,0);
   BarsUpM30        = iCustom(NULL,0,"ForexFreedomBars",3,0);   
   BarsUpM15        = iCustom(NULL,0,"ForexFreedomBars",5,0);
   BarsUpM5         = iCustom(NULL,0,"ForexFreedomBars",7,0);
   
   BarsDownH1         = iCustom(NULL,0,"ForexFreedomBars",0,0);
   BarsDownM30        = iCustom(NULL,0,"ForexFreedomBars",2,0);
   BarsDownM15        = iCustom(NULL,0,"ForexFreedomBars",4,0);
   BarsDownM5         = iCustom(NULL,0,"ForexFreedomBars",6,0);
   
   BollingerUP    = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_UPPER,0);
   BollingerLow   = iBands(NULL,0,20,2,0,PRICE_CLOSE,MODE_LOWER,0);
   BollingerMiddle= (BollingerUP + BollingerLow) / 2;
   
   RSICURR        = iRSI(NULL,0,14,PRICE_CLOSE,0);     
   RSIPREV        = iRSI(NULL,0,14,PRICE_CLOSE,1);
   StochCURR      = iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_MAIN,0);
   StochPREV      = iStochastic(NULL,0,10,3,3,MODE_SMA,0,MODE_MAIN,1);
   
   
/*         
   Comment  ("EmaHight = ",EmaHight,
            "\nEmaClose = ",EmaClose,
            "\nEmaLow = ",EmaLow,
            "\nSma = ",Sma,
            "\nBarsUpH1 = ",BarsUpH1,
            "\nBarsUpM30 = ",BarsUpM30,
            "\nBarsUpM15 = ",BarsUpM15,
            "\nBarsUpM5 = ",BarsUpM5,
            "\nBarsDownH1 = ",BarsDownH1,
            "\nBarsDownM30 = ",BarsDownM30,
            "\nBarsDownM15 = ",BarsDownM15,
            "\nBarsDownM5 = ",BarsDownM5);   
*/           
if (OpenOrders<1)
{           
      if (PriceOpenCurr > EmaHight  && PriceOpenCurr > EmaClose && PriceOpenCurr > EmaLow && PriceOpenCurr > Sma && BarsUpH1 !=0 && BarsUpM30 !=0 && BarsUpM15 !=0 && BarsUpM5 !=0 && (PriceOpenCurr-Sma <=10*Point || PriceOpenCurr-EmaHight <=10*Point) && Sma-EmaHight<10*Point && BollingerUP-BollingerLow>15*Point && RSICURR>RSIPREV && StochCURR>StochPREV  )
      {
          BuyPrice=Ask;
          if (TakeProfit==0) { tp=0; }
          else { tp=BuyPrice+TakeProfit*Point; }   
          if (InitialStop==0)  { sl=0; }
          else { sl=BuyPrice-InitialStop*Point; }
          OrderSend(Symbol(),OP_BUY,Lots,BuyPrice,3,sl,tp,NULL,0,0,Blue);
      }   
      if (PriceOpenCurr < EmaHight  && PriceOpenCurr < EmaClose && PriceOpenCurr < EmaLow && PriceOpenCurr < Sma && BarsDownH1 !=0 && BarsDownM30 !=0 && BarsDownM15 !=0 && BarsDownM5 !=0 && (Sma-PriceOpenCurr <=10*Point || EmaLow-PriceOpenCurr <=10*Point) && EmaLow-Sma<10*Point && BollingerUP-BollingerLow>15*Point && RSICURR<RSIPREV && StochCURR<StochPREV )
      {
          SellPrice=Bid;           
          if (TakeProfit==0) { tp=0; }
          else { tp=SellPrice-TakeProfit*Point; }   
          if (InitialStop==0) { sl=0; }
          else { sl=SellPrice+InitialStop*Point;  }
          OrderSend(Symbol(),OP_SELL,Lots,SellPrice,3,sl,tp,NULL,0,0,Red);
      }   
}

//----
if(OpenOrders!=0 && PriceOpenCurr<Sma)
  {
     for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          mode=OrderType();
        if (OrderSymbol()==Symbol())
        {
         if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Blue); }
        }
     }
  }

if(OpenOrders!=0 && PriceOpenCurr>Sma)
  {
     for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
          mode=OrderType();
        if (OrderSymbol()==Symbol())
        {
         if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red); }
        }
     }
  }
//----
//----
   return(0);
  }

ruddy01

  • Newbie
  • *
  • Posts: 38
ขอบคุณมากครับเอดมิน  ใช้ได้แล้วครับ

chartwat

  • Newbie
  • *
  • Posts: 43
admin ครับ หาก เราต้องการ run หลาย ๆ ค่าเงินพร้อมกัน เราจะต้องใส่ค่า magicnumber ใช่ใหมครับ
รบกวน admin ใส่ให้หน่อยครับ ขอบคุณหลาย ๆ ครับ