Questions from Beginners MQL5 MT5 MetaTrader 5 - page 873

 
Лауреат:

I couldn't find it on YouTube. The documentation is just for the clever ones.

Youtube is our thing? You know where north-south is on YouTube too?

 

When the EA is started, two moving averages are added to the chart ( ChartIndicatorAdd function). Both moving averages are drawn in red. How can I colour them programmatically?

 
Kvin_:

When the EA is started, two moving averages are added to the chart ( ChartIndicatorAdd function). Both moving averages are drawn in red. How to paint them programmatically in other colours?

The help is very clear:

When you create a handle for the indicator you're working with, you can specify a parameter on the line:

indicator_handle=iMACD(symbol,period,fast_ema_period,slow_ema_period,signal_period,apr);
 
Artyom Trishkin:

Is YouTube our everything? Do you know where north-south is from YouTube videos too?

Of course you're smart.

 
Kvin_:

When the EA is started, two moving averages are added to the chart ( ChartIndicatorAdd function). Both moving averages are drawn in red. How to paint them programmatically in other colours?

Use custom indicator that has a special setting: colour.

Example in theCustom Moving Average Input Color code:

Using theCrossing of two iMAs as an example, the call of the three indicators is now visually distinct in the visual strategy tester:

Crossing of two iMAs

 
Vladimir Karputov:

Use a custom indicator that has a special setting: colour.

Example in theCustom Moving Average Input Color code:

Using theCrossing of two iMAs as an example, the call of the three indicators is now visually distinct in the visual strategy tester:

Just what I need. Thank you!
 

I can't get the lot multiplication factor right.

Previously in codebase EA it was multiplying the previous lot by 2.

if(last_position_type==POSITION_TYPE_BUY && m_symbol.Bid()+count_positions*ExtStep<last_position_price_open)
         m_trade.Sell(last_position_volume*2,m_symbol.Name());

I changed it to

input double   KLot              = 1.5;     //Коэффициент умножения лота
//------------------------------------------
if(last_position_type==POSITION_TYPE_BUY && m_symbol.Bid()+count_positions*ExtStep<last_position_price_open)
         m_trade.Sell(last_position_volume*KLot,m_symbol.Name());


I get wrong lot volume

 
ilyav:

I can't get the lot multiplication factor right.

Previously in codebase EA it was multiplying the previous lot by 2.

I changed it to

I get the wrong lot volume

After doing the arithmetic, you should adjust the lot volume to the lot volume step for that symbol.

Example:Coin Flip lot calculation and check for BUY

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

   double check_open_long_lot=0.0;
   if(Risk>0.0)
     {
      check_open_long_lot=m_money.CheckOpenLong(m_symbol.Ask(),sl);
      Print("sl=",DoubleToString(sl,m_symbol.Digits()),
            ", CheckOpenLong: ",DoubleToString(check_open_long_lot,2),
            ", Balance: ",    DoubleToString(m_account.Balance(),2),
            ", Equity: ",     DoubleToString(m_account.Equity(),2),
            ", FreeMargin: ", DoubleToString(m_account.FreeMargin(),2));
      if(check_open_long_lot==0.0)
        {
         Print(__FUNCTION__,", ERROR: method CheckOpenLong returned the value of \"0.0\"");
         return;
        }
     }
   else
      check_open_long_lot=InpLots;
   if(last_lots_sl>0.0)
      check_open_long_lot=last_lots_sl*InpMartingale;
   if(check_open_long_lot>InpMaxLots)
     {
      Print(__FUNCTION__,", ERROR: check_open_long_lot (",DoubleToString(check_open_long_lot,2),") > \"Max lots\" (",DoubleToString(check_open_long_lot,2),")");
      ExpertRemove();
      return;
     }
   check_open_long_lot=LotCheck(check_open_long_lot);
   if(check_open_long_lot==0)
     {
      Print(__FUNCTION__,", ERROR: LotCheck -> 0.0");
      return;
     }
//--- check volume before OrderSend to avoid "not enough money" error (CTrade)
   double check_volume_lot=m_trade.CheckVolume(m_symbol.Name(),check_open_long_lot,m_symbol.Ask(),ORDER_TYPE_BUY);
   if(check_volume_lot!=0.0)
     {
      if(check_volume_lot>=check_open_long_lot)
        {
         if(m_trade.Buy(check_open_long_lot,NULL,m_symbol.Ask(),sl,tp))
           {
            if(m_trade.ResultDeal()==0)
              {
               Print("#1 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
               PrintResult(m_trade,m_symbol);
              }
            else
              {
               Print("#2 Buy -> true. Result Retcode: ",m_trade.ResultRetcode(),
                     ", description of result: ",m_trade.ResultRetcodeDescription());
               PrintResult(m_trade,m_symbol);
              }
           }
         else
           {
            Print("#3 Buy -> false. Result Retcode: ",m_trade.ResultRetcode(),
                  ", description of result: ",m_trade.ResultRetcodeDescription());
            PrintResult(m_trade,m_symbol);
           }
        }
      else
        {
         string text="";
         if(Risk>0.0)
            text="< method CheckOpenLong ("+DoubleToString(check_open_long_lot,2)+")";
         else
            text="< Lots ("+DoubleToString(InpLots,2)+")";
         Print(__FUNCTION__,", ERROR: method CheckVolume (",DoubleToString(check_volume_lot,2),") ",
               text);
         return;
        }
     }
   else
     {
      Print(__FUNCTION__,", ERROR: method CheckVolume returned the value of \"0.0\"");
      return;
     }
//---
  }
 

hello such a question:

is it possible to dynamically change the number of buffers/lines in an indicator?

 
Andrii Djola:

hello such a question:

Is it possible to dynamically change the number of buffers/lines in an indicator?

You can't.