Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

Experts

Waddah Attar Win - expert for MetaTrader 5

| English Русский 中文 Español Deutsch 日本語 Português

Published by:
Vladimir Karputov
Views:
852
Rating:
votes: 18
Published:
2017.03.02 10:01

Author of the idea — Ahmad Waddah Attarauthor of thr MQL5 code — barabashkakvn

The Expert Advisor trades using pending Buy Limit (BuyLimit) and Sell Limit (SellLimit) orders. Once the price moves very close to the pending order:

   if((m_symbol.Ask()-LastBuyLimitPrice)<=5*m_symbol.Point()) // FirstLot очень близко
      m_trade.BuyLimit(LastBuyLimitLot+IncLot,m_symbol.NormalizePrice(LastBuyLimitPrice-ExtStep));

   if((LastSellLimitPrice-m_symbol.Bid())<=5*m_symbol.Point()) // FirstLot очень близко
      m_trade.SellLimit(LastBuyLimitLot+IncLot,m_symbol.NormalizePrice(LastSellLimitPrice+ExtStep));

Place one more pending order

To get the last price of the placed order we use OnTradeTransaction():

//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- Get the trade type as a value of the enumeration
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
   Print(EnumToString(type));
//--- if a deal — the result of deal adding to history
   if(type==TRADE_TRANSACTION_ORDER_ADD)
     {
      long     order_type        =0;
      double   order_price       =0.0;
      double   order_volume      =0.0;
      string   order_symbol      ="";
      long     order_magic       =0;
      if(OrderSelect(trans.order)) // Select pending orders
        {
         order_type=OrderGetInteger(ORDER_TYPE);
         order_price=OrderGetDouble(ORDER_PRICE_OPEN);
         order_volume=OrderGetDouble(ORDER_VOLUME_INITIAL);
         order_symbol=OrderGetString(ORDER_SYMBOL);
         order_magic=OrderGetInteger(ORDER_MAGIC);
        }
      else
         return;
      if(order_symbol==m_symbol.Name() && order_magic==m_magic)
        {
         if(order_type==ORDER_TYPE_BUY_LIMIT)
           {
            LastBuyLimitPrice=order_price;
            LastBuyLimitLot=order_volume;
           }
         if(order_type==ORDER_TYPE_SELL_LIMIT)
           {
            LastSellLimitPrice=order_price;
            LastSellLimitlLot=order_volume;
           }
        }
     }
  }

Testing on EURUSD, M15 from 2015.06.07 to 2016.12.31 — "Every tick" mode, initial deposit 10000:

Waddah Attar Win tester

Translated from Russian by MetaQuotes Software Corp.
Original code: https://www.mql5.com/ru/code/17339

e-TurboFx e-TurboFx

Analysis of bars, if they contain N consecutive bars of the same type.

MA Reverse MA Reverse

Trading by Moving Average. Checking for sufficiency of funds.

up3x1_premium_v2M up3x1_premium_v2M

Two iMAs on the current period and one on PERIOD_D1.

Bull vs Medved Bull vs Medved

The Expert Advisor makes trading decisions based on simple candlestick combinations. It is designed for use on the H4 period.