Requests & Ideas (MQL5 only!) - page 8

 
Vladimir Karputov:

Yes, in post  code includes the 60 sec check.


Perfect.

Yes it makes sense to remove it. The person that told me the strategy specifically mentioned it, but it doesn't seem necessary to the final results tbh.

 
ef91:


Perfect.

Yes it makes sense to remove it. The person that told me the strategy specifically mentioned it, but it doesn't seem necessary to the final results tbh.


Ok, and at the same time I'll insert the input parameters for TakeProfit and StopLoss. Also show how to normalize prices.
 
Vladimir Karputov:

Ok, and at the same time I'll insert the input parameters for TakeProfit and StopLoss. Also show how to normalize prices.


How does it work for the trader who's phisically launching the EA, does he/she have to input any parameter from MT5 or does it need to be changed inside the code?

Like TP, SL and quantity for the single trades

 
ef91:


How does it work for the trader who's phisically launching the EA, does he/she have to input any parameter from MT5 or does it need to be changed inside the code?

Like TP, SL and quantity for the single trades


When you run the Expert Advisor, the user will see these parameters:

Input parameters

With 10 pip it in the system of "4-digit"

 
Vladimir Karputov:


When you run the Expert Advisor, the user will see these parameters:

With 10 pip it in the system of "4-digit"


I see. Looks easy to me. Cause I'm not gonna be there with them when they'll try it.
 
Vladimir Karputov:

Ok, and at the same time I'll insert the input parameters for TakeProfit and StopLoss. Also show how to normalize prices.


To normalize prices, I use the CSymbolInfo.NormalizePrice - this method takes into account the quantization of prices.

cheduecoglioni version   "1.002"


Only here there is no protection from lack of money.

Files:
 
Vladimir Karputov:


To normalize prices, I use the CSymbolInfo.NormalizePrice - this method takes into account the quantization of prices.

cheduecoglioni version   "1.002"


Only here there is no protection from lack of money.


What does that implies? (no protection from lack of money)
 
ef91:

What does that implies? (no protection from lack of money)


This means, when you send a trade request, and as a result you can not open a position, because there is not enough money on the trading account:

2017.02.21 00:26:18   current account state: Balance: 96.58, Credit: 0.00, Commission: 0.00, Accumulated: 0.00, Assets: 0.00, Liabilities: 0.00, Equity 96.58, Margin: 0.00, FreeMargin: 96.58
2017.02.21 00:26:18   calculated account state: Assets: 0.00, Liabilities: 0.00, Equity 96.58, Margin: 106.12, FreeMargin: -9.54
2017.02.21 00:26:18   not enough money [instant buy 0.10 EURUSD at 1.06124 sl: 1.06004 tp: 1.06204]
2017.02.21 00:26:18   CTrade::OrderSend: instant buy 0.10 EURUSD at 1.06118 sl: 1.06004 tp: 1.06204 [not enough money]


I'll put the defense on later ...

 
Vladimir Karputov:


This means, when you send a trade request, and as a result you can not open a position, because there is not enough money on the trading account:


I'll put the defense on later ...


Thank you for your help so far Vladimir

 
ef91:


Thank you for your help so far Vladimir


cheduecoglioni(barabashkakvn's edition)  version   "1.003"

//+------------------------------------------------------------------+
//|                      cheduecoglioni(barabashkakvn's edition).mq5 |
//|                                                   Gianni Esperti |
//|                                  https://www.gianniesperti.come? |
//+------------------------------------------------------------------+
#property copyright "Gianni Esperti"
#property link      "https://www.gianniesperti.come?"
#property version   "1.003"

Now with protection from lack of money when opening a position:

//+------------------------------------------------------------------+
//| Open Buy position                                                |
//+------------------------------------------------------------------+
void OpenBuy(double sl,double tp)
  {
   sl=m_symbol.NormalizePrice(sl);
   tp=m_symbol.NormalizePrice(tp);

//--- check volume before OrderSend to avoid "not enough money" error (CTrade)
   double chek_volime_lot=m_trade.CheckVolume(m_symbol.Name(),InpLots,m_symbol.Ask(),ORDER_TYPE_BUY);

   if(chek_volime_lot!=0.0)
     {
      if(chek_volime_lot>=InpLots)
        {
         if(m_trade.Buy(InpLots,NULL,m_symbol.Ask(),sl,tp))
           {
            if(m_trade.ResultDeal()==0)
              {
               Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
              }
            else
              {
               Print("Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
              }
           }
         else
           {
            Print("Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
                  ", description of result: ",m_trade.ResultRetcodeDescription());
           }
        }
      else
        {
         m_is_trade=false;
        }
     }
   else
     {
      m_is_trade=false;
     }
//---
  }
//+------------------------------------------------------------------+
//| Open Sell position                                               |
//+------------------------------------------------------------------+
void OpenSell(double sl,double tp)
  {
   sl=m_symbol.NormalizePrice(sl);
   tp=m_symbol.NormalizePrice(tp);

//--- check volume before OrderSend to avoid "not enough money" error (CTrade)
   double chek_volime_lot=m_trade.CheckVolume(m_symbol.Name(),InpLots,m_symbol.Bid(),ORDER_TYPE_SELL);

   if(chek_volime_lot!=0.0)
     {
      if(chek_volime_lot>=InpLots)
        {
         if(m_trade.Sell(InpLots,NULL,m_symbol.Bid(),sl,tp))
           {
            if(m_trade.ResultDeal()==0)
              {
               Print("Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
              }
            else
              {
               Print("Sell -> true. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
              }
           }
         else
           {
            Print("Sell -> false. Result Retcode: ",m_trade.ResultRetcode(),
                  ", description of result: ",m_trade.ResultRetcodeDescription());
           }
        }
      else
        {
         m_is_trade=false;
        }
     }
   else
     {
      m_is_trade=false;
     }
//---
  }

I think that's enough. And now I can place this file in the codebase.

Files:
Reason: