Basic Help Needed Creating an Array for a Custom Variable

 

Hello Everyone,

I am requesting guidance & assistance with basics steps to creating an array for a variable.

My intent is to create a variable for a position's profit per candle, more specifically, I would like a position's profit for the last 3 candles.

I will need to create an array right?

& was planning on using PositionGetDouble(POSITION_PROFIT) to fill this array

If I'm not too far off track already, can someone please outline steps to creating an array?

// Declaring an Array for New Buffer

// Associating an Array with a Buffer

//  Calculating Values of the Variable

//  Check Values of the Variable

// Resize?

// Index?

// CopyBuffer


I've inserted my attempt below

GREAT THANKS to everyone in advance for affording me this opportunity to learn!


//Declare Variables

double         pos_profit_Handle;               // handle for our Position Profit indicator
double         pos_profit_Val[];                // Profit/Loss of the position

// Declaring an Array for New Buffer
// the pos_Profit values arrays

ArraySetAsSeries(pos_profit_Val,true);   

// Associating an Array with a Buffer
?
SetIndexBuffer(0,pos_profit_HandleBuffer,?pos_profit_Handle?); 
?

//  Calculating Values of the Variable
//--- the position will be selected by symbol of the current chart
               
string symbol=Symbol();
bool selected=PositionSelect(symbol);
long pos_id=PositionGetInteger(POSITION_IDENTIFIER);
               
pos_profit_Handle=PositionGetDouble(POSITION_PROFIT); // position 

//--- Check if handle returns Invalid Handle, & yes it returns an error
if(pos_profit_Handle<0)
{
Alert("Error Creating Handles for indicators - error: ",GetLastError(),"!!");
return(-1);
}

//--- Release handles (where in the cose does this need to go?)
IndicatorRelease(pos_profit_Handle);                              
               
//--- Copy the new values of our indicators to buffers (arrays) using the handle
              
if(CopyBuffer(pos_profit_Handle,3,pos_profit_Val)<0)// & yes it returns an error
{
Alert("Error copying Position Profit indicator buffer - error:",GetLastError());
ResetLastError();
return;
}               
// Copy Position Profit Values for the 3 most recent candles
double pos_profit_Val0=NormalizeDouble(pos_profit_Val[0],5);
double pos_profit_Val1=NormalizeDouble(pos_profit_Val[1],5);
double pos_profit_Val2=NormalizeDouble(pos_profit_Val[2],5); 

// THIS IS THE END RESULT I AM SEEKING. THE PROFIT OF THE CURRENT POSITION FOR THE LAST 3 CANDLES