seconds chart

 

I am looking to close a candle of Tick data on custom symbol in seconds 

I want to do it using  CustomTicksAdd and MqlTick

I attempted to add datetime time or  long time_msc in seconds but it did not work

If someone has working code example, please post

Thanks

Creating and testing custom symbols in MetaTrader 5
Creating and testing custom symbols in MetaTrader 5
  • www.mql5.com
Creating custom symbols pushes the boundaries in the development of trading systems and financial market analysis. Now traders are able to plot charts and test trading strategies on an unlimited number of financial instruments.
 

Please clean up your post and remove ALL that extra whitespace!

Or better still, given that you have just copy/pasted the structure and function declarations from the documentation, just provide the links to the documentation instead.

It would have reduced your post to just a few lines and made it so much easier to read.

EDIT: Also, show your own attempted code instead so that we help identify the issue.

 
Fernando Carreiro #:

Please clean up your post and remove ALL that extra whitespace!

Or better still, given that you have just copy/pasted the structure and function declarations from the documentation, just provide the links to the documentation instead.

It would have reduced your post to just a few lines and made it so much easier to read.

EDIT: Also, show your own attempted code instead so that we help identify the issue.

thanks corrected, i am looking for any example on codebase or if someone have done this to build seconds chart on mt5. 

 
Arpit T #:

thanks corrected, i am looking for any example on codebase or if someone have done this to build seconds chart on mt5. 

You can build seconds chart but the time stamps can't be in seconds, it will be in minutes. Is the same way as some renko charts are built.

See this article. https://www.mql5.com/en/articles/8226

Custom symbols: Practical basics
Custom symbols: Practical basics
  • www.mql5.com
The article is devoted to the programmatic generation of custom symbols which are used to demonstrate some popular methods for displaying quotes. It describes a suggested variant of minimally invasive adaptation of Expert Advisors for trading a real symbol from a derived custom symbol chart. MQL source codes are attached to this article.
 
Arpit T #: thanks corrected, i am looking for any example on codebase or if someone have done this to build seconds chart on mt5. 

The following information was all found by using the website search with the keywords "Custom Symbol" or "CustomTicksAdd".

  • In the CodeBase, the following example generates a Renko Custom Symbol with tick data:

Code Base

Renko 2.0

Guilherme Santos, 2017.12.28 14:23

A complete Renko chart indicator with wicks. Configure using Tick Size, Pip Size, Points or R. Now with Asymetric Reversals!
  • In the Articles, the following publications discuss generating Custom Symbols with tick data:

Articles

Custom symbols: Practical basics

Stanislav Korotky, 2020.11.30 08:27

The article is devoted to the programmatic generation of custom symbols which are used to demonstrate some popular methods for displaying quotes. It describes a suggested variant of minimally invasive adaptation of Expert Advisors for trading a real symbol from a derived custom symbol chart. MQL source codes are attached to this article.

Articles

How to create and test custom MOEX symbols in MetaTrader 5

Dmitrii Troshin, 2019.02.04 12:05

The article describes the creation of a custom exchange symbol using the MQL5 language. In particular, it considers the use of exchange quotes from the popular Finam website. Another option considered in this article is the possibility to work with an arbitrary format of text files used in the creation of the custom symbol. This allows working with any financial symbols and data sources. After creating a custom symbol, we can use all the capabilities of the MetaTrader 5 Strategy Tester to test trading algorithms for exchange instruments.

Articles

WebSockets for MetaTrader 5 — Using the Windows API

Francis Dube, 2022.01.18 12:38

In this article, we will use the WinHttp.dll to create a WebSocket client for MetaTrader 5 programs. The client will ultimately be implemented as a class and also tested against the Binary.com WebSocket API.
 
Fernando Carreiro #:

Please clean up your post and remove ALL that extra whitespace!

Or better still, given that you have just copy/pasted the structure and function declarations from the documentation, just provide the links to the documentation instead.

It would have reduced your post to just a few lines and made it so much easier to read.

EDIT: Also, show your own attempted code instead so that we help identify the issue.

Here is code but i want to convert all history of chart in seconds, as of now it just update current data in seconds

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2020, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   1

#property indicator_label1  "open;high;low;close"
#property indicator_type1   DRAW_COLOR_CANDLES
#property indicator_color1  clrGray,clrLimeGreen,clrSandyBrown


input int Seconds = 3;  // Seconds for candles interval

double canc[],cano[],canh[],canl[],colors[],seconds[][4];
#define sopen  0
#define sclose 1
#define shigh  2
#define slow   3


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit() {
   SetIndexBuffer(0,cano,INDICATOR_DATA);
   SetIndexBuffer(1,canh,INDICATOR_DATA);
   SetIndexBuffer(2,canl,INDICATOR_DATA);
   SetIndexBuffer(3,canc,INDICATOR_DATA);
   SetIndexBuffer(4,colors,INDICATOR_COLOR_INDEX);
   EventSetTimer(Seconds);
   IndicatorSetString(INDICATOR_SHORTNAME,(string)Seconds+" seconds chart");
   return(0);
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
   EventKillTimer();
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTimer() {
   double close[];
   CopyClose(_Symbol,_Period,0,1,close);
   int size = ArrayRange(seconds,0);
   ArrayResize(seconds,size+1);
   seconds[size][sopen]  = close[0];
   seconds[size][sclose] = close[0];
   seconds[size][shigh]  = close[0];
   seconds[size][slow]   = close[0];
   updateData();
}


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void updateData() {
   int rates_total = ArraySize(canh);
   int size = ArrayRange(seconds,0);
   if (size<=0) {
      for (int i=rates_total-1; i>=0; i--) {
         canh[i] = EMPTY_VALUE;
         canl[i] = EMPTY_VALUE;
         cano[i] = EMPTY_VALUE;
         canc[i] = EMPTY_VALUE;
      }
      return;
   }
   double close[];
   CopyClose(_Symbol,_Period,0,1,close);
   seconds[size-1][shigh]  = MathMax(seconds[size-1][shigh],close[0]);
   seconds[size-1][slow]   = MathMin(seconds[size-1][slow],close[0]);
   seconds[size-1][sclose] =                                 close[0];
   for (int i=(int)MathMin(rates_total-1,size-1); i>=0 && !IsStopped(); i--) {
      int y = rates_total-i-1;
      canh[y] = seconds[size-i-1][shigh ];
      canl[y] = seconds[size-i-1][slow  ];
      cano[y] = seconds[size-i-1][sopen ];
      canc[y] = seconds[size-i-1][sclose];
      colors[y] = cano[y]>canc[y] ? 2 : cano[y]<canc[y] ? 1 : 0;
   }
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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[]) {
   int bars = Bars(_Symbol,_Period);
   if (bars<rates_total) return(-1);
   updateData();
   return(rates_total);
}
//+------------------------------------------------------------------+
 
Arpit T #: Here is code but i want to convert all history of chart in seconds, as of now it just update current data in seconds

Your question was about Custom Symbols and the CustomTicksAdd function.

Your sample code is an indicator, that processes normal bar data. It also does not create any Custom Symbol or use the CustomTicksAdd function.

What does your sample code have to do with your question?

 

If you want to process tick data to build up seconds based OHLC data, then use the CopyTicks function.

You can process the tick data directly, either in real-time or historically, without needing to build a Custom Symbol

Documentation on MQL5: Timeseries and Indicators Access / CopyTicks
Documentation on MQL5: Timeseries and Indicators Access / CopyTicks
  • www.mql5.com
CopyTicks - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Fernando Carreiro #:

Your question was about Custom Symbols and the CustomTicksAdd function.

Your sample code is an indicator, that processes normal bar data, not seconds. It also does not create any Custom Symbol or use the CustomTicksAdd function.

What does your sample code have to do with your question?

Since i have not been able to find any working method for CustomTicksAdd, now i am OK with bars data also, The goal is to convert chart in seconds in MT5 like MT4 offers offline charts. Right now the code i posted, have issues like if i draw fibo it does not stick to candles, and it start running when you add this indicator on chart only. I want it to convert full chart in seconds

 
Arpit T #: Since i have not been able to find any working method for CustomTicksAdd, now i am OK with bars data also, The goal is to convert chart in seconds in MT5 like MT4 offers offline charts. Right now the code i posted, have issues like if i draw fibo it does not stick to candles, and it start running when you add this indicator on chart only. I want it to convert full chart in seconds

Then read and process the tick data with CopyTicks function to build your second-based OHLC data and build the Custom Symbol.

Read and study the examples I gave you from the CodeBase and Articles I quoted in my post #4.

 
Samuel Manoel De Souza #:
the time stamps can't be in seconds

Hi.
Tell me, please, are you 100% sure that the time stamps can't be in seconds?

I believe, once I saw some tick or seconds chart that actually made bars to have seconds in their opening time and so you were able to use graphic objects on such chart. But I can't find it since then. Maybe it was just a dream...

Reason: