Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

Coin Flip - expert for MetaTrader 5

Published by:
Vladimir Karputov
Views:
4433
Rating:
(16)
Published:
2018.06.18 12:32
Coin Flip.mq5 (67.45 KB) view
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Idea by: Vladimir Gribachev.

MQL5 code by: Vladimir Karputov.

An EA without using any custom indicators; positions are opened pseudorandomly. The EA can show the current statistics in two languages:

Coin Flip trading info

Trailing modifies the Stop Loss of open positions. In case of loss, the lots increase using Martingale. How to monitor losses: In OnTradeTransaction, we catch transaction DEAL_REASON_SL - the sign of the Stop Loss triggered:

//+------------------------------------------------------------------+
//| TradeTransaction function                                        |
//+------------------------------------------------------------------+
void OnTradeTransaction(const MqlTradeTransaction &trans,
                        const MqlTradeRequest &request,
                        const MqlTradeResult &result)
  {
//--- get transaction type as enumeration value 
   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;
//--- if transaction is result of addition of the transaction in history
   if(type==TRADE_TRANSACTION_DEAL_ADD)
     {
      long     deal_ticket       =0;
      long     deal_order        =0;
      long     deal_time         =0;
      long     deal_time_msc     =0;
      long     deal_type         =-1;
      long     deal_entry        =-1;
      long     deal_magic        =0;
      long     deal_reason       =-1;
      long     deal_position_id  =0;
      double   deal_volume       =0.0;
      double   deal_price        =0.0;
      double   deal_commission   =0.0;
      double   deal_swap         =0.0;
      double   deal_profit       =0.0;
      string   deal_symbol       ="";
      string   deal_comment      ="";
      string   deal_external_id  ="";
      if(HistoryDealSelect(trans.deal))
        {
         deal_ticket       =HistoryDealGetInteger(trans.deal,DEAL_TICKET);
         deal_order        =HistoryDealGetInteger(trans.deal,DEAL_ORDER);
         deal_time         =HistoryDealGetInteger(trans.deal,DEAL_TIME);
         deal_time_msc     =HistoryDealGetInteger(trans.deal,DEAL_TIME_MSC);
         deal_type         =HistoryDealGetInteger(trans.deal,DEAL_TYPE);
         deal_entry        =HistoryDealGetInteger(trans.deal,DEAL_ENTRY);
         deal_magic        =HistoryDealGetInteger(trans.deal,DEAL_MAGIC);
         deal_reason       =HistoryDealGetInteger(trans.deal,DEAL_REASON);
         deal_position_id  =HistoryDealGetInteger(trans.deal,DEAL_POSITION_ID);

         deal_volume       =HistoryDealGetDouble(trans.deal,DEAL_VOLUME);
         deal_price        =HistoryDealGetDouble(trans.deal,DEAL_PRICE);
         deal_commission   =HistoryDealGetDouble(trans.deal,DEAL_COMMISSION);
         deal_swap         =HistoryDealGetDouble(trans.deal,DEAL_SWAP);
         deal_profit       =HistoryDealGetDouble(trans.deal,DEAL_PROFIT);

         deal_symbol       =HistoryDealGetString(trans.deal,DEAL_SYMBOL);
         deal_comment      =HistoryDealGetString(trans.deal,DEAL_COMMENT);
         deal_external_id  =HistoryDealGetString(trans.deal,DEAL_EXTERNAL_ID);
        }
      else
         return;
      if(deal_symbol==m_symbol.Name() && deal_magic==m_magic)
         if(deal_entry==DEAL_ENTRY_OUT)
           {
            PrevBars=0;
            if(deal_reason==DEAL_REASON_SL && deal_commission+deal_swap+deal_profit<0.0)
               last_lots_sl=deal_volume;
            else
               last_lots_sl=0.0;
           }
     }
  }


Input parameters

  • Stop Loss - Stop Loss;
  • Take Profit - Take Profit;
  • Trailing Stop - trailing;
  • Trailing Step - trailing step;
  • Lots - lot size is set manually (if Lots is above zero, then Risk must be equal to zero);
  • Risk - lot size is calculated automatically (if Risk is above zero, then Lots must be equal to zero);
  • Martingale - lot increase ratio, if the preceding position was closed by Stop Loss and the profit gained was negative;
  • Max lots - the maximum position size; if this size is exceeded, then the EA terminates its operation abnormally;
  • magic number - unique identifier for the EA.

Then testing was interrupted (the EA was unloaded from the chart forcedly), since the reference lot exceeded the Max lots parameter:

Coin Flip

Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/20836

InvertCandle_Plus InvertCandle_Plus

The inverted chart of the current financial instrument, displaying Ask and Bid price levels.

AnchoredMomentum_x10 AnchoredMomentum_x10

Indicator AnchoredMomentum_x10 shows the location of indicator AnchoredMomentum from ten different timeframes.

BrainTrend2_V2 BrainTrend2_V2

Indicator BrainTrend2 that generates alerts and sends e-mails and Push-messages when the indicator changes its color.

BrainTrend2Stop_HTF BrainTrend2Stop_HTF

Indicator BrainTrend2Stop with the timeframe selection option available in input parameters.