Ask price indicator

 

My broker varies spreads on a market that I'm interested in. I'd like to have an indicator that shows the historic Ask price. Can I access historic Ask prices, or will I need to keep a record of them myself? Does such an indicator already exist?


Also, if I do need to keep a record myself, how can I do this across deinitialisation? It seems that I can't have an external array.

 
You will have to do it yourself . . . unless your Broker has it in a form that you can download, dukascopy do . . . . if you write the data out to a file it will survive de-initialisation.
 
RaptorUK:
You will have to do it yourself . . . unless your Broker has it in a form that you can download, dukascopy do . . . . if you write the data out to a file it will survive de-initialisation.

Thanks. I'm with Smart Live Markets/GKFX. I don't know if I can download it with them. But I'll set to writing it to a file anyway.
 

My code is below. I'm getting an error "Wrong delimiter for FileOpen as BIN function". What is the correct delimiter for a binary file?


#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- indicator parameters


//---- indicator buffers
double ExtMapBuffer[];
//----
int ExtCountedBars=0;
string FileName;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int deinit()
{int handle;

   //No need to worry about there being an old file which may not have been deleted, because I open without FILE_READ, all old data will be deleted.
   //"If FILE_WRITE does not combine with FILE_READ, a zero-length file will be opened. If even the file containd some data, they will be deleted. If there is a need to add data to an existing file, it must be opened using combination of FILE_READ | FILE_WRITE."

   //Could just make these global variables and they will be saved across deinit and init.

         handle=FileOpen(FileName, FILE_BIN|FILE_WRITE, ';');   
         Print (handle + "-" + ArraySize(ExtMapBuffer));
          if(handle>0)
                {
                 FileWriteArray(handle, ExtMapBuffer,0,1000);    //should I be storing ArraySize(ExtMapBuffer) and then recovering this to reload the array?
        
                 FileClose(handle);
                 
                }

        }

int init()
  {FileName= "AskData" + Symbol();
  int handle;
        handle=FileOpen(FileName,FILE_BIN|FILE_READ,";");

   if (handle>0)
   {FileReadArray(handle, ExtMapBuffer,0,1000);
   
   FileClose(handle);
   FileDelete(FileName);
    Print (handle + "-" + ArraySize(ExtMapBuffer));
   }

//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
  
   SetIndexBuffer(0,ExtMapBuffer);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
   {
   int i,                           // Bar index
       Counted_bars;                // Number of counted bars
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Number of counted bars
   i=Bars-Counted_bars-1;           // Index of the first uncounted
  if(i>=0)                      // Loop for uncounted bars. No need to shift everything in the buffer back. Not sure how that works but don't worry about it.
     {
      ExtMapBuffer[0]=Ask;             // Value of 0 buffer on i bar
                       // Calculating index of the next bar
     }
//--------------------------------------------------------------------
   return;                          // Exit the special funct. start()
  }
 
Arbu:

My code is below. I'm getting an error "Wrong delimiter for FileOpen as BIN function". What is the correct delimiter for a binary file?

Binary files have NO delimiters.
 
WHRoeder:
Binary files have NO delimiters.

Thanks, that's what I thought. I didn't realise that the parameter was optional. Is it simply the fact that it's quoted with a default value ( int delimiter=';') that indicates that it's optional? I come from Visual Basic where the word "Optional" would appear in the parameter declaration to indicate this; clearly not here.


I'm now trying to work out how to deal with the array size for reading and writing it. The array seems to save OK, but I get an error when I try to reload it ("FileReadArray function cannot resize index array"). So I've written the following code to try to deal with the array size, but I'm still getting the same error. Any thoughts?

int deinit()
{int handle;

   //No need to worry about there being an old file which may not have been deleted, because I open without FILE_READ, all old data will be deleted.
   //"If FILE_WRITE does not combine with FILE_READ, a zero-length file will be opened. If even the file containd some data, they will be deleted. If there is a need to add data to an existing file, it must be opened using combination of FILE_READ | FILE_WRITE."

         handle=FileOpen(FileName, FILE_BIN|FILE_WRITE);        
         Print (handle + "-" + ArraySize(ExtMapBuffer));
          if(handle>0)
                {int i= ArraySize(ExtMapBuffer);
                FileWriteInteger(handle,i);
                 FileWriteArray(handle, ExtMapBuffer,0,i);    //should I be storing ArraySize(ExtMapBuffer) and then recovering this to reload the array?
        
                 FileClose(handle);
                 
                }

        }

int init()
  {FileName= "AskData" + Symbol();
  int handle;
        handle=FileOpen(FileName,FILE_BIN|FILE_READ);

   if (handle>0)
   
   {int i = FileReadInteger(handle);
   ArrayResize(ExtMapBuffer,i);
   FileReadArray(handle, ExtMapBuffer,0,i);
   
   FileClose(handle);
   FileDelete(FileName);

         Print (handle + "-" + ArraySize(ExtMapBuffer) + "-" + i);

   }