web statistics


Bagian 7 - Fungsi Order dan Indikator Teknikal

Discussion in 'Tutorial MQL4' started by white_tiger, Oct 21, 2008.

  1. jembroz

    jembroz
    Expand Collapse
    New Member

    Joined:
    May 7, 2009
    Messages:
    80
    Likes Received:
    0
    Om WT, izin berguru suhu.
    sebelumnyakan , kalo EA itu di eksekusi tiap tic. yang di eksekusi itu method start() kan..? trus tiap tic itu, 1 candle dengan nilai akhir, atau setiap pergerakan 1 candle naik turunnya harga..??:-/

    maaf, kalo2 OOT..?
     
  2. white_tiger

    white_tiger
    Expand Collapse
    Administrator
    Staff Member

    Joined:
    Jun 13, 2007
    Messages:
    1,501
    Likes Received:
    4
    yang dieksekusi yang start()
    tiap tick = tiap ada harga baru
     
  3. red_devil_fans

    red_devil_fans
    Expand Collapse
    New Member

    Joined:
    Dec 15, 2008
    Messages:
    10
    Likes Received:
    0
    mau nanya dah master :(

    ane kan mau pake fungsi orderclose, tp sampe skg fungsi itu gk blm bisa berjalan

    itu knp ya master?

    misalkan gini

    if(kondisi)
    {
    closeorder
    }

    nah yg saya ketik di bagian "closeorder" itu gmana pak?:-??

    thx bantuannya :(
     
  4. chandrawg

    chandrawg
    Expand Collapse
    Moderator

    Joined:
    Aug 30, 2008
    Messages:
    577
    Likes Received:
    2
    di post 1 ada tuh contohnya
     
  5. anakbaru46

    anakbaru46
    Expand Collapse
    New Member

    Joined:
    Jan 21, 2010
    Messages:
    105
    Likes Received:
    0
    selamat siang master semuanya...

    kalau saya ingin menambahkan TP in money bagaimana caranya???:-? :-? :-?
    untuk lebih jelasnya mungkin bisa ditambahkan pada EA yang dijadikan contoh pada bagian 2 -contoh EA. terimakasih atas bantuannya...

    ini ea yang saya maksud diatas


    #define SIGNAL_NONE 0
    #define SIGNAL_BUY 1
    #define SIGNAL_SELL 2
    #define SIGNAL_CLOSEBUY 3
    #define SIGNAL_CLOSESELL 4


    extern int MagicNumber = 0;
    extern bool SignalMail = False;
    extern bool EachTickMode = False;
    extern double Lots = 0.1;
    extern int Slippage = 3;
    extern bool UseStopLoss = False;
    extern int StopLoss = 30;
    extern bool UseTakeProfit = False;
    extern int TakeProfit = 60;
    extern bool UseTrailingStop = False;
    extern int TrailingStop = 30;

    int BarCount;
    int Current;
    bool TickCheck = False;
    //+------------------------------------------------------------------+
    //| expert initialization function |
    //+------------------------------------------------------------------+
    int init() {
    BarCount = Bars;

    if (EachTickMode) Current = 0; else Current = 1;

    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert deinitialization function |
    //+------------------------------------------------------------------+
    int deinit() {
    return(0);
    }
    //+------------------------------------------------------------------+
    //| expert start function |
    //+------------------------------------------------------------------+
    int start() {
    int Order = SIGNAL_NONE;
    int Total, Ticket;
    double StopLossLevel, TakeProfitLevel;



    if (EachTickMode && Bars != BarCount) TickCheck = False;
    Total = OrdersTotal();
    Order = SIGNAL_NONE;

    //+------------------------------------------------------------------+
    //| Variable Begin |
    //+------------------------------------------------------------------+


    double Buy1_1 = iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
    double Buy1_2 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, Current + 0);

    double Sell1_1 = iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
    double Sell1_2 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, Current + 0);

    double CloseBuy1_1 = iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
    double CloseBuy1_2 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, Current + 0);

    double CloseSell1_1 = iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, Current + 0);
    double CloseSell1_2 = iMA(NULL, 0, 20, 0, MODE_SMA, PRICE_CLOSE, Current + 0);


    //+------------------------------------------------------------------+
    //| Variable End |
    //+------------------------------------------------------------------+

    //Check position
    bool IsTrade = False;

    for (int i = 0; i < Total; i ++) {
    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
    if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
    IsTrade = True;
    if(OrderType() == OP_BUY) {
    //Close

    //+------------------------------------------------------------------+
    //| Signal Begin(Exit Buy) |
    //+------------------------------------------------------------------+

    if (CloseBuy1_1 < CloseBuy1_2) Order = SIGNAL_CLOSEBUY;


    //+------------------------------------------------------------------+
    //| Signal End(Exit Buy) |
    //+------------------------------------------------------------------+

    if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if(Bid - OrderOpenPrice() > Point * TrailingStop) {
    if(OrderStopLoss() < Bid - Point * TrailingStop) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    } else {
    //Close

    //+------------------------------------------------------------------+
    //| Signal Begin(Exit Sell) |
    //+------------------------------------------------------------------+

    if (CloseSell1_1 > CloseSell1_2) Order = SIGNAL_CLOSESELL;


    //+------------------------------------------------------------------+
    //| Signal End(Exit Sell) |
    //+------------------------------------------------------------------+

    if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
    if (!EachTickMode) BarCount = Bars;
    IsTrade = False;
    continue;
    }
    //Trailing stop
    if(UseTrailingStop && TrailingStop > 0) {
    if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
    if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
    OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
    if (!EachTickMode) BarCount = Bars;
    continue;
    }
    }
    }
    }
    }
    }

    //+------------------------------------------------------------------+
    //| Signal Begin(Entry) |
    //+------------------------------------------------------------------+

    if (Buy1_1 > Buy1_2) Order = SIGNAL_BUY;

    if (Sell1_1 < Sell1_2) Order = SIGNAL_SELL;


    //+------------------------------------------------------------------+
    //| Signal End |
    //+------------------------------------------------------------------+

    //Buy
    if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("BUY order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
    } else {
    Print("Error opening BUY order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    //Sell
    if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
    if(!IsTrade) {
    //Check free margin
    if (AccountFreeMargin() < (1000 * Lots)) {
    Print("We have no money. Free Margin = ", AccountFreeMargin());
    return(0);
    }

    if (UseStopLoss) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
    if (UseTakeProfit) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

    Ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
    if(Ticket > 0) {
    if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
    Print("SELL order opened : ", OrderOpenPrice());
    if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
    } else {
    Print("Error opening SELL order : ", GetLastError());
    }
    }
    if (EachTickMode) TickCheck = True;
    if (!EachTickMode) BarCount = Bars;
    return(0);
    }
    }

    if (!EachTickMode) BarCount = Bars;

    return(0);
    }
    //+------------------------------------------------------------------+


    saya ingin menambahkan fungsi TP in money, yang kurang lebih artinya Target Point berdasarkan Profit uang yang dihasilkan....terimakasih ats bantuan master2 yang ada disini...=D> =D> =D>
     
    #45 anakbaru46, Feb 9, 2010
    Last edited by a moderator: Feb 9, 2010
  6. chandrawg

    chandrawg
    Expand Collapse
    Moderator

    Joined:
    Aug 30, 2008
    Messages:
    577
    Likes Received:
    2
    untuk mengetahui profit dalam satuan uangnya bisa pakai code
    Code:
    AccountProfit()
    
    jadi kalau diterapkan dalam ea diatas, mungkin seperti ini (contoh)

    1. tambahkan extern TP=1000;
    2. setelah "start" tambahkan code
    if (AccountProfit()>TP)
    {
    for(int k=0;k<OrdersTotal();k++)
    {
    if(OrderSelect(k,SELECT_BY_POS,MODE_TRADES))
    {
    if ((OrderType()==0)||(OrderType()==1))
    {
    OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0);
    }
    }
    }
    return (0);
    }
     
    #46 chandrawg, Feb 21, 2010
    Last edited: Feb 21, 2010
  7. anakbaru46

    anakbaru46
    Expand Collapse
    New Member

    Joined:
    Jan 21, 2010
    Messages:
    105
    Likes Received:
    0
    terimakasih atas bantuannya master....=D>=D>=D>
     
  8. Bagja

    Bagja
    Expand Collapse
    Member

    Joined:
    Oct 21, 2009
    Messages:
    41
    Likes Received:
    0
    Max Open order per candle?

    Para suhu,

    Newbie minta tolong, kalau membatasi open order tidak lebih dari 1x per hari sudah bisa, tapi kalau membatasi open order tidak lebih dari 1x/2x (bisa diset) per candle bisa tidak ya?
    Jadi misalkan dalam 1 rentang trend ada 10 candle, saya bisa open order masing2 1 order di setiap candle.

    Kalau bisa minta tolong scriptnya...

    Terima kasih,
     
  9. chandrawg

    chandrawg
    Expand Collapse
    Moderator

    Joined:
    Aug 30, 2008
    Messages:
    577
    Likes Received:
    2
    untuk satu trade per candle mungkin bisa dibuat supaya ordernya hanya saat candle baru. code untuk detect new candle seperti ini:
    Code:
    void Fun_New_Bar()
      {
       static datetime New_Time=0;
       New_Bar=false;
       if(New_Time!=Time[0])
         {
          New_Time=Time[0];
          New_Bar=true;
         }
      }
    
     
  10. Bagja

    Bagja
    Expand Collapse
    Member

    Joined:
    Oct 21, 2009
    Messages:
    41
    Likes Received:
    0
    Asiik, udah dijawab, makasih master chandra, mau dicoba dulu.
    (Kalau boleh nambah), saya ingin bila open order kena SL, otomatis dia akan langsung open opposite order dengan lot 2x, (jumlah pengali bisa diset),
    Minta contoh scriptnya master,
    Terima kasih banyak,...
     

Share This Page