# How to get ask bid price on history array with copyclose?

19

Hi,

I want to calculate a vector who represent the profitability to buy now a forex cross (like EURUSD) and sell it in a futur period of time pre-defined.

To calculate this, I made a for loop who calculate the difference between the close price now and the close price in 20minutes(for exemple).

This is working now, i get the data from the function CopyClose().

Now I want to put the spread on my model, i have two solutions: calculate the difference between the ask/close price now and the bid/close price in 20minutes, or I can calculate the difference between the close now and the close in 20minute minus the spread.

But I don't understand which price is returned from the copyclose function (ask or bid? is it possible to configure it?) and/or how to get the spread (I tried with copyspread, i suppose that the unit is in 1/10000, but guess what?it's never profitable to buy and sell in 20minutes with the spread given by copyspread function).

I hope somebody can help me.

Best regards.

17943

happylulux: But I don't understand which price is returned from the copyclose function (ask or bid?
1. All charts are bid charts.  The spread if provided is in points.
2. I'm on MT4 so I don't have the spread. I maintain my own.
```//{ Typedefs
#define  PRICE    double         // A PRICE
#define     PRICE_MAX   (PRICE)EMPTY_VALUE
#define     PRICE_MIN   (PRICE)0.0
#define     CHANGE      PRICE    // Difference of two prices.
#define  INDEX    uint           // Zero based.
#define  COUNT    uint           //  One based.
#define  MONEY    double
#define  SYMBOL   string
//} Typedefs
//{ Average maximum Spread.   (Must run per tick.)
#define EMA(P, C, L) ((P) + ((C)-(P))*2./(L+1))
// https://en.wikipedia.org/wiki/Generalized_mean#Special_cases (Power Mean)
#define PMA(P, C, L, PM) MathPow(EMA(MathPow(P,PM), MathPow(C,PM), L), 1.0/PM)
// AMS is saved in a global variable for the case of TF change.
static const string  ms = "MaxSpread_" + _Symbol;
static const double  PM = 10;
}

19

Hi,

maybe my calculus is wrong...a point is 1/10000 of the price right? I checked and the difference of price on 20min is approximately 5 to 15pip, and the spread is everytime approximately 20 (but increase to 150 pip during a certain time), is that usual values?? if yes, it mean that "fast" trading (less than 30min between buy and sell) is never profitable...I think I make an error somewhere... here is my function, it write the "rentability" vector on a csv file.

```void writeOutputToFile(string symbol,string filename,datetime startdate,int Ndata,int mean)
{
Print("date d'output: ",startdate);
ArraySetAsSeries(data,1);
while(CopyClose(symbol,TIMEPERIOD,startdate,Ndata,data)!=Ndata)
{
Print("reacquisition du close du symbole: ",symbol);
}
{
Print("reacquisition du spread du symbole: ",symbol);
}
for(int i=0;i<Ndata;i++)
{
}
int N=ArraySize(data)-mean;
ArrayResize(rentable,N);
for(int i=0;i<N;i++)
{
}

string strdata="";
for(int i=0;i<N;i++)
{
strdata=strdata+string(rentable[i])+"\n";
}
if(FileIsExist(filename,FILE_COMMON))
{
Print("suppression du fichier d'output");
do{
}while(FileDelete(filename,FILE_COMMON)==false);
}