Here is what I am trying to achieve.
With ONE indicator I intend to scan multiple instruments(AA,BB,CC) by running the indicator on Chart X . Current chart used is 1 minute. Then print the close[1] of each of these instruments.
Example —> close of AA at 11:57:00 - 100 … close of AA at 11:58:00- 101 … close of AA at 11:59:00 - 102
For example if the time now is 11:59:01 , I want to print close[1] meaning it must print 102 the moment the new bar begins.
Problem 1 - At 11:59:01, if there is no new tick on chart X , it waits till the first tick is generated on chart X which can be a few seconds later and then it runs and prints the values.
Problem 2 - At 11:59:01 if there is a tick on Chart X and when it runs the program… " if there is no new tick on chart AA" … the program prints the 101 which is in fact the close[2].
And here is my code I have now. Help me correct this issue. Thanks in advance.
Here is my code
//+------------------------------------------------------------------+
//| ProjectName |
//| Copyright 2018, CompanyName |
//| http://www.companyname.net |
//+------------------------------------------------------------------+
#property copyright ""
#property link ""
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DarkGreen
#property indicator_color2 Red
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
extern int BarsToProcess = 100000;
double MA10, MA30,MA50,ival_low,ival_high,MA13,MA34;
int val_index_low,val_index_high;
extern double x = 20;
double highlow,percent, lll,hhh;
string Pairs[4] = {"BALAKRISHNA#","ASIANPAINT#","BANKBARODA#","SBIN#"};
int period = 1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW,EMPTY,5);
SetIndexArrow(0,217);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW,EMPTY,5);
SetIndexArrow(1,218);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexEmptyValue(1,0.0);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
Comment("Running");
//----
if(NewBar())
{
for(int j=0; j<=3; j++)
{
int bars = iBars(Pairs[j], period);
double oo = iOpen(Pairs[j],period,1);
double cc = iClose(Pairs[j],period,1);
datetime DT = TimeCurrent();
string Date = TimeToStr(TimeCurrent(),TIME_DATE);//"yyyy.mm.dd"
string exact_time = TimeToStr(TimeLocal(),TIME_SECONDS);//
int handle=FileOpen("print.csv", FILE_CSV|FILE_WRITE|FILE_READ, '\t');
bool del = FileDelete("print.csv",0);
if(handle>0)
{
FileSeek(handle, 0, SEEK_END);
FileWrite(handle, "Server Time is", DT, "No of Bars is", bars, "close is", cc, Pairs[j],"Local Date is", Date, exact_time," \n");
FileClose(handle);
}
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
bool IsthisANewCandle()
{
static int BarsOnChart = 0;
if(Bars == BarsOnChart)
return(false);
BarsOnChart = Bars;
return(true);
}
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool NewBar()
{
static datetime lastbar;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else
{
return(false);
}
}
//+------------------------------------------------------------------+