Questions from Beginners MQL5 MT5 MetaTrader 5 - page 508

 
I attached a martingale. In the middle of the day I attached the Expert Advisor in this form (it had already made a few deals of the same EA, but in an unfinished state before), - the EA worked fine, the martingale worked, took out losses for half a day in the plus. The next day, I turned on the platform in the morning, went to work, in the evening - one deal. Martingale increases the lot for a losing trade, otherwise - the standard lot.
void OnTick()
  {
   datetime EaStartTime = StringToTime(StartTime);  // время начала работы советника
   datetime EaEndTime = StringToTime(EndTime);      // время окончания работы советника
   datetime CurrTime = TimeCurrent();               // это если нужно взять время терминала
   if(CurrTime<EaStartTime || CurrTime>=EaEndTime)
      return;                                       // если еще не время торговать - выход
     {
      MacdCurrent=iMACD(NULL,0,InpFastEMA,InpSlowEMA,InpSignalSMA,Macd_Applied_Price,MODE_MAIN,0);
      SignalCurrent=iMACD(NULL,0,InpFastEMA,InpSlowEMA,InpSignalSMA,Macd_Applied_Price,MODE_SIGNAL,0);
      SignalMAPrevious=iMA(NULL,0,InpMAPeriod,InpMAShift,InpMAMethod,MA_Applied_Price,1);
      SignalMAThis=iMA(NULL,0,InpMAPeriod,InpMAShift,InpMAMethod,MA_Applied_Price,0);
      SignalParabolic=iSAR(NULL,0,InpSARStep,InpSARMaximum,0);
      SignalStochastic_5=iStochastic(NULL,5,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,0,1,0);
      MainStochastic_5=iStochastic(NULL,5,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,0,0,0);
      SignalStochastic=iStochastic(NULL,0,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,0,1,0);
      MainStochastic=iStochastic(NULL,0,InpKPeriod,InpDPeriod,InpSlowing,MODE_SMA,0,0,0);
      SignalCCIPrevious=iCCI(NULL,0,InpCCIPeriod,0,1);
      SignalCCIThis=iCCI(NULL,0,InpCCIPeriod,0,0);
      if(CountTrades()==0) CheckForOpen();
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
 {if(ModLots())
  {
      //-----Ставим ордер на покупку.
    if(SignalCurrent<MacdCurrent && SignalMAPrevious<SignalMAThis && 
      Ask>SignalParabolic && SignalStochastic_5<MainStochastic_5&&SignalStochastic<MainStochastic&&
      SignalCCIPrevious<SignalCCIThis)
      {
       ticket=OrderSend(NULL,OP_BUY,lot,Ask,slippage,0,0,exptime,magic,0,Blue);
       if(ticket>0)
          return;
      }
//-----Ставим ордер на продажу.
    if(SignalCurrent>MacdCurrent && SignalMAPrevious>SignalMAThis && 
      Bid<SignalParabolic && SignalStochastic_5>MainStochastic_5&&SignalStochastic>MainStochastic&&
      SignalCCIPrevious>SignalCCIThis)
      {
       ticket=OrderSend(NULL,OP_SELL,lot,Bid,slippage,0,0,exptime,magic,0,Red);
       if(ticket>0)
          return;
      }
  }
 }
//+------------------------------------------------------------------+
int CountTrades()
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
            count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
bool ModLots()
  {
    for(int i=OrdersHistoryTotal()-1;i>=0;i--)
      {
       if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
       if((OrderMagicNumber()==magic) && (OrderSymbol()==Symbol()))
         {
          if(OrderProfit()<0)
            {lot=OrderLots()*LotMarti;  break;}
          else { lot=Lots; break;}
         }
      }
   return(true);
  }
//+------------------------------------------------------------------+
 
Hello. The mql4 manual says that Timer and ChartEvent event handling is not supported in the strategy tester. Accordingly, the buttons (OBJ_BUTTON) do not work (more precisely, nothing happens when you click). The trial version of this EA, however, for some reason doesn't support this rule. Please tell me why this is happening and how to make the buttons in the tester work?
 
Maks_Knyazev:
Hello. The mql4 manual says that the Timer and ChartEvent events processing is not supported in the strategy tester. Accordingly, the buttons (OBJ_BUTTON) do not work (more precisely, nothing happens when you click). The trial version of this EA, however, for some reason doesn't support this rule. Please tell me why this is happening and how to make the buttons in the tester work?

Yes, they don't work. You have to check the buttons manually in the tester, like this

CButton *cbSell, *cbBuy;

//проверяем из OnTick в тестере 
void CheckButtons()
{
    if(cbSell.Pressed())
    {
        OpenOrderWithCheck2(Symbol(), OP_SELL, 0.1, Bid, 50, 0, 0, "", 1, 0, clrDeepSkyBlue);
        cbSell.Pressed(false);
    }    
    if(cbBuy.Pressed())
    {
        OpenOrderWithCheck2(Symbol(), OP_BUY, 0.1, Bid, 50, 0, 0, "", 1, 0, clrRed);
        cbBuy.Pressed(false);
    }
    ChartRedraw();
}

 
Alexey Volchanskiy:

Yes, they don't work. In the tester, you have to check the buttons manually, like this

Thank you very much! Is there any literature that describes this kind of thing?
 

flint17480, 2016.02.01 08:58

Hello. Didn't close the profit on the 09-47 minute candle on EURUSD the profit was at 1.08428 the candle went to 1.08420. What to do? Thanks in advance.
 
<br / translate="no">

flint17480, 2016.02.01 08:58

Hello. My profit on EURUSD was at 1.08428 and went up to 1.08420. Can you tell me what to do? Thanks in advance.

Need more information:

  1. Type of open position: SELL or BUY?
  2. Did you know that the price in the terminal is drawn by BID?

 
Karputov Vladimir:

flint17480, 2016.02.01 08:58

Hello. Didn't close the profit on the 09-47 minute candle on EURUSD the profit was at 1.08428 the candle went to 1.08420. What to do? Thank you in advance.

You should pay attention to the spread, because short positions are closed on Asc, while the candlestick is drawn on Bid. Spreads over 8 pips for a five-digit is normal for most currency pairs.

 
Karputov Vladimir:

flint17480, 2016.02.01 08:58

Hello. Didn't close the profit on the 09-47 minute candle on EURUSD the profit was at 1.08428 the candle went to 1.08420. What to do? Thank you in advance.
Tick quotes to write. Shall I send you my quote? Although there are plenty of them in kodobaz. You were right about the spread.
 
Good afternoon to all) Share the code for a mobile stop loss - to drive the price )))) Thanks in advance
 
Tema97:
Good afternoon to all) Share the code for a mobile stop loss - to drive the price )))) Thanks in advance.
What do you do not like trailing stop? It is already built into the terminal