Discussion of article "Custom symbols: Practical basics" - page 3

 

Hi  Stanislav Korotky

Thanks for all you did on various ways and types regarding "Custom Symbols" topic

Secondly sorry for writing in english,since i do not know russian - :)

1 issue raised within "RenkoTicks" code (kind of error)

1

Can you kindly manage time,removing this error

regards

Stanislav Korotky
Stanislav Korotky
  • 2023.04.26
  • www.mql5.com
Trader's profile
 
mntiwana #:

Can you kindly manage time,removing this error

Just remove 0 inside the curly braces. Please follow MQL5 syntax changes in the news announces. This one is a bit old - I can't remember exact reference now.

 
Stanislav Korotky #:

This one is a bit old,,,

Once again, it took me 3 years to find this work of art. If this is "old", old has just met... slow. Ha. Thank you.

 

Regarding RenkoTicks.mq5, I experienced a points to pips conversion issue with 3 digit pricing. I previously experienced the same thing with some utilities in MT4, so I implemented the same fix:


//in globals, insert
double _PntsToPips;

//in OnInit, insert
if(_Digits == 3 || _Digits == 5)
{
 PntsToPips = 10;
}
else
{
 _PntsToPips = 1;
}

//in 2 lines containing _Point (not in sendSpread...), insert
* _PntsToPips //2 new lines will be:

double Renko::boxPoints = NormalizeDouble(RenkoBoxSize * _Point * _PntsToPips, _Digits);
Renko::setBoxPoints(NormalizeDouble(RenkoBoxSize * _Point * _PntsToPips, _Digits));


 

Here is a small but important improvement in the custom signal based on 2 MA crossing. The underlying indicator objects maintain internal buffers with indicator's data (not only MA case, but in general), hence calling m_maFast.Main(ind) or m_maSlow.Main(ind) leads to reading somewhat outdated (cached) data from the objects, not from indicators themselves, if your trading system trades by ticks (!). Now it's replaced with the following calls to GetData which is basically is a wrapper for direct CopyBuffer:

class Signal2MACross : public CExpertSignal
{
    ...
    // helper functions to read indicators' data
    double FastMA(int ind) { static double buffer[1]; m_maFast.GetData(ind, 1, 0, buffer); return buffer[0]; }
    double SlowMA(int ind) { static double buffer[1]; m_maSlow.GetData(ind, 1, 0, buffer); return buffer[0]; }
};

The updated header file is attached. It should be placed in /MQL5/Include/Expert/Signal/MySignals/. Without this the signals have been built by completed bars.

Files:
 

It's turned out to be even worse. Some times timeseries are not re-calculated yet when new tick is fired, hence bar index should be adjusted dynamically for trade signal analysis. For example (rough approach):

    double FastMA(int ind)
    {
      MqlTick t;
      SymbolInfoTick(m_symbol.Name(), t);
      bool correction = false;

      if(t.time / 60 * 60 != iTime(m_symbol.Name(), PERIOD_CURRENT, 0) && ind > 0)
      {
        ind--;
        correction = true;
      }
      
      static double buffer[1]; m_maFast.GetData(ind, 1, 0, buffer);
      
      if(correction)
        PrintFormat("F: %s'%03d %s %.5f", TimeToString(t.time, TIME_SECONDS), t.time_msc % 1000, TimeToString(iTime(m_symbol.Name(), PERIOD_CURRENT, 0)), buffer[0]);
        
      return buffer[0]; 
    }

This is critical for EAs trading on bar opening, and for symbols with sparse ticks.