Incorrect tick counting for non-forex symbols

 

Hello everyone!


I have an indicator than counts the amount of upticks and downticks for each candle which works well for Forex symbols however for symbols such as SP500 it can show negative upticks/downticks and ticks decreasing live which shouldn't be possible. I'm unsure as to why it works for Forex symbols but not other symbols and therefore would greatly appreciate an explanation/work around!


Best regards,

MK


The code:

#property copyright "Copyright © 2008, FOREXflash Software Corp."
#property link      "http://www.metaquotes.net"
#property strict
//-----
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots 2

#property indicator_type1  DRAW_LINE
#property indicator_color1 clrLime
#property indicator_label1 "UpTicks"
#property indicator_type2  DRAW_LINE
#property indicator_color2 clrRed
#property indicator_label2 "DownTicks"

double UpTicks[];
double DownTicks[];
double dXecn = 1;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
  IndicatorSetString(INDICATOR_SHORTNAME,"TicksSeparateVolume ("+Symbol()+")");

  SetIndexBuffer(0,UpTicks);
  ArraySetAsSeries(UpTicks,true);
  SetIndexBuffer(1,DownTicks);
  ArraySetAsSeries(DownTicks,true);
  if(_Digits==3||_Digits==5) {
    dXecn=10;
  }

  return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{


  Comment("");

  return(0);
}
//+------------------------------------------------------------------+
//| Ticks Volume Indicator                                           |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
  if(prev_calculated<1) {
    ArrayInitialize(UpTicks,EMPTY_VALUE);
    ArrayInitialize(DownTicks,EMPTY_VALUE);
  }
  ArraySetAsSeries(open,true);
  ArraySetAsSeries(close,true);
  ArraySetAsSeries(tick_volume,true);
//----
  int limit=rates_total-1;
  if(rates_total-prev_calculated<2) limit=1;

  for(int i=0; i<limit; i++) {
    UpTicks[i]=(tick_volume[i]+(close[i]-open[i])/_Point/dXecn)/2;
    DownTicks[i]=tick_volume[i]-UpTicks[i];
  }
//----
  return(rates_total);
}
//+------------------------------------------------------------------+
 
MKThePlug: Hello everyone! I have an indicator than counts the amount of upticks and downticks for each candle which works well for Forex symbols however for symbols such as SP500 it can show negative upticks/downticks and ticks decreasing live which shouldn't be possible. I'm unsure as to why it works for Forex symbols but not other symbols and therefore would greatly appreciate an explanation/work around! Best regards, MK The code:

You are mixing the concept of tick size as in the smallest possible difference in quote price, and tick volume as in the count or number ticks or price changes when deals are made.

Using "tick_volume" and "close - open" are not compatible values to added or subtracted together, even if scaled by "_point". They are different concepts.

EDIT: Also, if you want to analyse proper tick data you should use the CopyTicks function.

 

One more thing ... for non-forex symbols, the tick size and the point size can be different.

Forum on trading, automated trading systems and testing trading strategies

Symbol Point Value

Fernando Carreiro, 2022.06.02 01:14

Here are two examples from AMP Global (Europe):

  • Micro E-mini S&P 500 (Futures): point size = 0.01, tick size = 0.25, tick value = $1.25
  • EURO STOXX Banks (Stock Index): point size = 0.01, tick size = 0.05, tick value = €2.50

Forum on trading, automated trading systems and testing trading strategies

Symbol Point Value

Fernando Carreiro, 2022.05.18 21:05

double
   dbTickSize   = SymbolInfoDouble( _symbol, SYMBOL_TRADE_TICK_SIZE  ), // Tick size
   dbTickValue  = SymbolInfoDouble( _symbol, SYMBOL_TRADE_TICK_VALUE ), // Tick value
   dbPointSize  = SymbolInfoDouble( _symbol, SYMBOL_POINT ),            // Point size
   dbPointValue = dbTickValue * dbPointSize / dbTickSize;               // Point value
Remember, it's best to use tick size and tick value in your calculations, instead of point size and its value.

Forum on trading, automated trading systems and testing trading strategies

Tick size vs Point(), can be a little tricky in Multicurrency EA

Fernando Carreiro, 2022.03.09 12:11

Tick Size and Point Size can be very different especially on stocks and other symbols besides forex.

Always use Tick Size to adjust and align your prices, not the point size. In essence, make sure that your price quotes, are properly aligned to the Tick size (see following examples).

...
double tickSize = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
...
double normalised_price = round( price / tick_size ) * tick_size;
...
// Or use a function
double Round2Ticksize( double price )
{
   double tick_size = SymbolInfoDouble( _Symbol, SYMBOL_TRADE_TICK_SIZE );
   return( round( price / tick_size ) * tick_size );
};
Reason: