1. Welcome back! Thank you for being a part of this Traders Community. Let's discuss and share :)
    Selamat datang kembali! Trimakasih telah menjadi bagian dari Komunitas Trader ini. Mari berdiskusi dan berbagi :)
    Dismiss Notice

Problem Membuat EA - Open Posisi Terus Menerus

Discussion in 'Belajar MQL dari Nol' started by Dewa199, 19 May 2021.

  1. Dewa199

    Dewa199 New Member

    Equity
    Credit
    Ref Point
    Hallo Pak SoeHoe, Saya sedang Belajar Membuat EA Sederhana dengan Rule Entry Buy CROSS EMA 4 Memotong EMA 90 ke atas & Close Posisi saat EMA 4 Cross EMA 21 ke Bawah ( Untuk Sell Sebaliknya )

    Saya menggunakan Forex Advisor.

    Kendala yang saya Alami adalah Ketika EMA4 Cross EMA90 Memang Open BUY & Close Transaksi Secara Normal.

    Tetapi Saat Close Posisi Sudah Selesai, EA Tetap Open Posisi Setiap Pergantian Candle Karena EMA4 Masih berada di Atas EMA90.

    Mohon Arahannya Pak SoeHoe
     
  2. SoeHoe

    SoeHoe Administrator Moderator

    Equity
    Credit
    Ref Point
    Btw, tolong kasi Foto Profile mas, supaya mudah dikenali.
    Kasi detail scriptnya ke sini mas. Copy paste kan aja, dan tandai sebagai code. Masuk ke Insert > Code. Lihat gambar berikut:
    upload_2021-5-19_12-54-45.png
     
  3. Dewa199

    Dewa199 New Member

    Equity
    Credit
    Ref Point
    Code:
    //+------------------------------------------------------------------+
    //                        DO NOT DELETE THIS HEADER
    //             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT
    //
    //                   Copyright ©2011-2020, ForexEAdvisor.com
    //                 ForexEAdvisor Strategy Builder version 0.3
    //                        https://www.ForexEAdvisor.com
    //
    // THIS EA CODE HAS BEEN GENERATED USING FOREXEADVISOR STRATEGY BUILDER 0.3
    // on: 5/19/2021 11:56:49 AM
    // Disclaimer: This EA is provided to you "AS-IS", and ForexEAdvisor disclaims any warranty
    // or liability obligations to you of any kind.
    // UNDER NO CIRCUMSTANCES WILL FOREXEADVISOR BE LIABLE TO YOU, OR ANY OTHER PERSON OR ENTITY,
    // FOR ANY LOSS OF USE, REVENUE OR PROFIT, LOST OR DAMAGED DATA, OR OTHER COMMERCIAL OR
    // ECONOMIC LOSS OR FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, STATUTORY, PUNITIVE,
    // EXEMPLARY OR CONSEQUENTIAL DAMAGES WHATSOEVER RELATED TO YOUR USE OF THIS EA OR
    // FOREXEADVISOR STRATEGY BUILDER     
    // Because software is inherently complex and may not be completely free of errors, you are
    // advised to verify this EA. Before using this EA, please read the ForexEAdvisor Strategy Builder
    // license for a complete understanding of ForexEAdvisor' disclaimers. 
    // USE THIS EA AT YOUR OWN RISK.
    // 
    // Before adding this expert advisor to a chart, make sure there are NO
    // open positions.
    //                      DO NOT DELETE THIS HEADER
    //             DELETING THIS HEADER IS COPYRIGHT INFRIGMENT
    //+------------------------------------------------------------------+
    
    
    extern int MagicNumber=10001;
    extern double Lots =0.01;
    extern double StopLoss=0;
    extern double TakeProfit=0;
    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((iMA(NULL,0,4,0,MODE_EMA,PRICE_CLOSE,0)>iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0))) // Here is your open buy rule
         {
            result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",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((iMA(NULL,0,4,0,MODE_EMA,PRICE_CLOSE,0)<iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,0))) // Here is your open Sell rule
         {
            result=OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,0,"EA Generator www.ForexEAdvisor.com",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((iMA(NULL,0,4,0,MODE_EMA,PRICE_CLOSE,0)<iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,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((iMA(NULL,0,4,0,MODE_EMA,PRICE_CLOSE,0)>iMA(NULL,0,50,0,MODE_EMA,PRICE_CLOSE,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);
    }
     
  4. Dewa199

    Dewa199 New Member

    Equity
    Credit
    Ref Point

    Sudah saya Upload Scriptnya ya Pak SoeHoe.. Mohon Arahanyya
     
  5. Dewa199

    Dewa199 New Member

    Equity
    Credit
    Ref Point
    Saya kok ga bisa kirim Balasan ya
     
  6. Onyx MIB

    Onyx MIB Member

    Equity
    Credit
    Ref Point
    mengenai code crossing 2 MA, saya sudah pernah sharing juga.
    boleh coba liat codenya, sangat simple.
    Tapi klo masih ada yang kurang dimengerti, bisa ikut dikusi di group kami
    klik aja t.me/codeMQL

    Berikut link Crossing 2 MA:
    https://www.mql5.com/en/code/34176

    Semoga bisa membantu.
     
  7. tomblox

    tomblox New Member

    Equity
    Credit
    Ref Point
    Saya bantu jawab ya mas.
    Itu kodenya saya lihat kurang benar mas. Saat mas mau buat ea dengan cross MA maka mas harus tentukan logic cross terlebih dahulu.
    1. Kondisi sebelum cross
    EMA 4 dibawah EMA 90 (shift 2)
    2. Kondisi setelah cross
    EMA 4 diatas EMA 90 (shift 1)
    Kalo kode mas di atas itu akan terbaca bukan cross tetapi "EMA 4 diata EMA 90 maka Buy"

    Kebetulan saya pernah buat video tutorialnya.
    Silakan dilihat di youtube "ea tanpa coding"
     
    • Informative Informative x 1

Share This Page