Trying to capture the current closed price

 

Does anyone know how to capture the current closed price? I'm writing an EA program and I assumed that the current closed price was contained within the below but I was wrong.


input ENUM_APPLIED_PRICE CURRENT_CLOSE        = PRICE_CLOSE;
 
flwilliams87:

Does anyone know how to capture the current closed price? I'm writing an EA program and I assumed that the current closed price was contained within the below but I was wrong.


Why not just use:

Close[0]
 
Stuart Browne:

Why not just use:

Not sure what you mean by Close[0]. What function does that belong to?
 
flwilliams87:
Not sure what you mean by Close[0]. What function does that belong to?
Sorry should have looked at your code closer. I think you're mixing two things up. PRICE_CLOSE is an enumeration price constant that is used on indicators (eg MA's) that can apply their formula to either open price, close price, median price etc etc. Is that what you're trying to do? Or are you trying to get the actual $ value of what the last close price was?
 

Close[0] has no value it's always open so you check Close[1]

double close=Close[1];

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(close!=Close[1])
     {
      Print(" New close: ",close);
      close=Close[1];
     }
  }
//+------------------------------------------------------------------+

 
Marco vd Heijden:

Close[0] has no value it's always open so you check Close[1]

Not correct sorry, Close[0] does have a value, it's always the current price ;-)
 
Stuart Browne:
Not correct sorry, Close[0] does have a value, it's always the current price ;-)

yes i mean the candle is always open i thought he needed the close price of candle [0] which can only be taken from [1] after [0] has closed.

 
Marco vd Heijden:

yes i mean the candle is always open i thought he needed the close price of candle [0] which can only be taken from [1] after [0] has closed.

Yeah I'm not sure what he's trying to capture to be honest, think we need more info from the OP.......
 
Stuart Browne:
Yeah I'm not sure what he's trying to capture to be honest, think we need more info from the OP.......

Thanks for the feedback. I really do appreciate it and what I am trying to do is capture the most current close.  I played around with the below but it doesn't give me any numbers to the right of the decimal with is not very helpful.  Also do I have to hard-code the symbol? Thoughts?


double myClose[];
double LastClose = CopyClose("EURUSD", 1, 0, 1, myClose);
 

start position 1 and data count to copy 0 ?

maybe you can switch them.

 
OK, Got my array that provides my the most current price close but when I run it I get the same values. I have the copybuffer in my OnInit Section.  And I get the same values for AskBuy and AskSale.  What am I doing wrong?
int OnInit()
{
  
  
  
   CloseHandle=CopyClose("EURUSD", 1, 0, 32, CloseArray);
   if(CloseHandle==INVALID_HANDLE)
      {
       Print(" Was not possible to recieve handle of Close");
       return(INIT_FAILED);
       }
}


 double ArrayTotal;
 double ArrayAverage;

void OnTick()
{ 
 ArrayTotal =0.0;
 
   for(int x=0; x<32; x++)
    {
      ArrayTotal+=CloseArray[x];
    }
    
    ArrayAverage=ArrayTotal/32;

 double AskBuy = ArrayAverage - .00051;
  double AskSale = ArrayAverage + .00051;
  

 Print("-- ");
 Print("Buy Array Average = ",NormalizeDouble(ArrayAverage,_Digits));
 Print("Buy Last Close = ",NormalizeDouble(CloseArray[0],_Digits));
 Print("-- ");
 

}