Custom indi update problem

[Deleted]  

When I am on a 5 min chart my custom indicator shows the latest value. However on the 30 min chart it doesn't show the last value until a new bar. Is there a way to make the indicator show the latest value before the next bar is drawn? I've tried calling WindowRedraw() everytime the .txt file that I am using for the data for the indicator window is updated, but that's not working.


if (fileSize > oldFileSize)
{
Print(curPair," changed: redrawing window");

if (curPair > "")
{
ReadSeriesFromFile(StringConcatenate(curPair, ".", FileExtention), delimiter, curDateArray, curRateArray);
}
WindowRedraw();
}

 

Hi,

That's too brief a code to tell... but in general, bar 0 is the shift of current unfinished bar, i.e. 'the latest value'. 

[Deleted]  
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_color3 Blue

//---- input parameters
extern string  FileExtention = "txt";
extern string pairDataFiles = "The EURUSDPosBuySell.txt etc files must be located in the folder ../experts/files/ ";
extern string estHourShiftUsage = "estHourShift is the hour difference between your broker and Eastern Standard Time";
extern int estHourShift = -7;
extern string AutoPairUsage = "AutoPair automatically selects the pair information for the current currency pair";
extern bool AutoPair = true;

extern string firstPairUsage = "If you wish to compare another set(s) of pair data against this currency pair, you can specify that here.  Must set AutoPairUsage to false";
extern string firstPair = "EURUSD";
extern bool screenShots = false;
extern int screenShotTimer = 20;

string fileName;
int h, fileSize, oldFileSize;
int minNow, minPast;

//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

datetime pairDateArray[], pairDateArray2[], pairDateArray3[];
double pairBuyArray[], pairSellArray[];

string pairPair;
int estSecShift, lastBarCount;
int delimiter = 9;
//datetime termsDate[];
//double termsRate[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   IndicatorShortName("pairPos");
   //---- indicators
   SetIndexStyle(0, DRAW_LINE, 2, 2, LimeGreen);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexStyle(1, DRAW_LINE, 2, 2, Red);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexStyle(2, DRAW_LINE, 2, 2, Blue);
   SetIndexBuffer(2, ExtMapBuffer3);
   SetLevelValue( 0, 0);
   SetLevelValue( 1, 1);
   SetLevelValue( 2, 3);
   SetLevelValue( 3, -1);
   SetLevelValue( 4, -3);

   lastBarCount = Bars;
   // get current currency symbols
   string symbol = Symbol();
   
   if(AutoPair) {
      pairPair = symbol;
   }
   else {   
      pairPair = firstPair;
   }

   Print("Reading:", StringConcatenate(pairPair, "PosBuySell.", FileExtention));
   //---- read file
   if (ReadSeriesFromFile(StringConcatenate(pairPair, "PosBuySell.", FileExtention), delimiter, pairDateArray, pairBuyArray, pairSellArray) < 0)
   {
      Print("could not find:"+pairPair,"PosBuySell.",FileExtention);
      return(Terminate());
   }
  
   //----
   return(0);
}

int saveChartPic() {
   int lastError;
   //---- make WindowScreenShot for further checking
   if(!WindowScreenShot("shots\\"+Symbol()+Period()+".gif",880,550))
        lastError=GetLastError();
   return (lastError);
}

int displayComments() {
   //---- Web Add     
   int subWin=0;
   subWin = WindowFind("pairPos");
   // Print("window num:",subWin);
   ObjectCreate("lBuyers", OBJ_LABEL, subWin, 0, 0);
   ObjectSetText("lBuyers","Buyers",11, "Arial", indicator_color1);
   ObjectSet("lBuyers", OBJPROP_CORNER, 2);
   ObjectSet("lBuyers", OBJPROP_XDISTANCE, 2);
   ObjectSet("lBuyers", OBJPROP_YDISTANCE, 34);          
   
   ObjectCreate("lSellers", OBJ_LABEL, subWin, 0, 0);
   ObjectSetText("lSellers","Sellers",11, "Arial", indicator_color2);
   ObjectSet("lSellers", OBJPROP_CORNER, 2);
   ObjectSet("lSellers", OBJPROP_XDISTANCE, 2);
   ObjectSet("lSellers", OBJPROP_YDISTANCE, 18);  
   return(0);
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   minNow=TimeMinute(TimeCurrent());
    
   if(!ObjectFind("lSellers"))
      displayComments();   
   
   int Counted_bars = IndicatorCounted();   
   int i;
   int pairRate;
   
   estSecShift=estHourShift*60*60;
   
   if (screenShots && MathMod(TimeMinute(TimeCurrent()), screenShotTimer)==0) {
      if (saveChartPic() > 0)
         Print("Chart screenshot failed:"+Symbol()+" "+Period());
      else 
         Print("Chart screenshot OK:"+Symbol()+" "+Period());
   }

   if (minNow > minPast) 
   {
      //Print("new min");   
      fileName = StringConcatenate(pairPair, "PosBuySell.", FileExtention);
      h = FileOpen(fileName, FILE_CSV || FILE_READ, delimiter);
      if (h < 1)
      {
         Print("File ", fileName, " not found, the last error is ", GetLastError());
         return(-1);
      }      
      fileSize = FileSize(h);
      FileClose(h);
   }
      
   if (fileSize > oldFileSize) 
   {
      Print(pairPair," changed: redrawing window");

      if (pairPair > "")
      {
         ReadSeriesFromFile(StringConcatenate(pairPair, "PosBuySell.", FileExtention), delimiter, pairDateArray, pairBuyArray, pairSellArray);
      }
      WindowRedraw();
   }  
   
   i = Bars - Counted_bars - 1; 
   while(i >= 0)
   {
      int ipair = ArrayBsearchCorrect(pairDateArray, Time[i]+estSecShift);
      if (ipair >= 0)
      {
         ExtMapBuffer1[i] = pairBuyArray[ipair];
         ExtMapBuffer2[i] = pairSellArray[ipair];
      }
      
     i--;
   }    

   oldFileSize = fileSize;
   minPast=minNow;
   lastBarCount=Bars;
   

   return(0);
}
//+------------------------------------------------------------------+

int ReadSeriesFromFile(string filename, int delimiter, datetime &keys[], double &valuesX[], double &valuesY[])
{
   int h = FileOpen(filename, FILE_CSV || FILE_READ, delimiter);
   if (h < 1)
   {
      Print("File ", filename, " not found, the last error is ", GetLastError());
      return(-1);
   }

   int i = 0;
   while (!FileIsEnding(h))
   {
      string s = StringTrimRight(FileReadString(h));
      if (s == "")
      {
         continue;   // ignore blank lines
      }
      datetime date = StrToTime(s);

      double valueX = FileReadNumber(h);
      double valueY = FileReadNumber(h);

      ArrayResize(keys, i + 1);
      keys[i] = date;
      ArrayResize(valuesX, i + 1);
      valuesX[i] = valueX;
      ArrayResize(valuesY, i + 1);
      valuesY[i] = valueY;      
      i++;
   }
  
   FileClose(h);
   SortDictionary(keys, valuesX);
   SortDictionary(keys, valuesY);
   return(i);
}

void SortDictionary(datetime &keys[], double &values[], int sortDirection = MODE_ASCEND)
{
   datetime keyCopy[];
   double valueCopy[];
   ArrayCopy(keyCopy, keys);
   ArrayCopy(valueCopy, values);
   ArraySort(keys, WHOLE_ARRAY, 0, sortDirection);
   for (int i = 0; i < MathMin(ArraySize(keys), ArraySize(values)); i++)
   {
    values[ArrayBsearch(keys, keyCopy[i])] = valueCopy[i];
   }
}

// ArrayBsearch figures out the 'best' datetime for the pair value - approximtes the best match/closest time if not exact match
int ArrayBsearchCorrect(datetime array[], datetime value, int count = WHOLE_ARRAY, int start = 0, int direction = MODE_ASCEND)
{
   int i = ArrayBsearch(array, value, count, start, direction);
   if (value < array[i])
   {
      i = -1;
   }
   return (i);
}

int Terminate()
{
   int err = 1; 
   Print("Self-terminating with divide by zero");
   err /= 0;
   return (err);
}


[Deleted]  
Anyone have a solution?