Create your own MetaTrader extension (dll) - page 11

 

receiving stock price

Hello,

I'm trying to receive stock prices from meta trader with c#, but don't really know how to do it.

can someone explain to me or send me into a specific guide?

thanks a lot.

 
kfirmt:
Hello,

I'm trying to receive stock prices from meta trader with c#, but don't really know how to do it.

can someone explain to me or send me into a specific guide?

thanks a lot.

In the experts\examples\DLLExample you will find how the prices can be passed from metatrader to C (it is close enough , so you can use that example directly for that), The rate infostructure haven't changed from the beginning and is still defined as :

struct RateInfo

{

unsigned int ctm;

double open;

double low;

double high;

double close;

double vol;

};

so you should not have any problems to pass it to C#

 

thanks!

where is the experts\examples\DLLExample ?

 
kfirmt:
thanks! where is the experts\examples\DLLExample ?

In your metatrader folder (the folder where you installed it)

 
mladen:
In your metatrader folder (the folder where you installed it)

I've downloaded 2 metatraders, and in the both of them the examples were in c++. I think I could understand from this although I'm programming with c#, but I couldn't find what I need, how to get the stock prices.

 
kfirmt:
I've downloaded 2 metatraders, and in the both of them the examples were in c++. I think I could understand from this although I'm programming with c#, but I couldn't find what I need, how to get the stock prices.

You are passing the prices from and indicator or an EAs to your DLL extension

You have a complete example (MQL part as well as C part) at that folder how it is done. Once you receive data from mql part in C# part ity is only a matter of code what are you going ot do with it

 
mladen:
You are passing the prices from and indicator or an EAs to your DLL extension You have a complete example (MQL part as well as C part) at that folder how it is done. Once you receive data from mql part in C# part ity is only a matter of code what are you going ot do with it

I didn't find example in MQL or C, just in C++. Anyway, there were a lot of functions and I couldn't understand which one is the function that I need for getting the price. do you have such an example?

thanks very much.

 
kfirmt:
I didn't find example in MQL or C, just in C++. Anyway, there were a lot of functions and I couldn't understand which one is the function that I need for getting the price. do you have such an example? thanks very much.

From C side (see the comment) :

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

MT4_EXPFUNC double __stdcall GetRatesItemValue(const RateInfo* rates,const int rates_total,const int shift,const int nrate)

{

//---

if(rates==NULL)

{

printf("GetRatesItemValue: NULL array\n");

return(0.0);

}

//---

if(rates_total<0)

{

printf("GetRatesItemValue: wrong rates_total number (%d)\n", rates_total);

return(0.0);

}

//---

if(shift=rates_total)

{

printf("GetRatesItemValue: wrong shift number (%d)\n", shift);

return(0.0);

}

//---

if(nrate5)

{

printf("GetRatesItemValue: wrong rate index (%d)\n", nrate);

return(0.0);

}

//

// here you are having prices, time and volume

//

int nitem=rates_total-1-shift;

switch(nrate)

{

case 0: return double(rates[nitem].ctm);

case 1: return rates[nitem].open;

case 2: return rates[nitem].low;

case 3: return rates[nitem].high;

case 4: return rates[nitem].close;

case 5: return rates[nitem].vol;

}

//---

return(0.0);

}

 
mladen:
From C side (see the comment) :
//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

MT4_EXPFUNC double __stdcall GetRatesItemValue(const RateInfo* rates,const int rates_total,const int shift,const int nrate)

{

//---

if(rates==NULL)

{

printf("GetRatesItemValue: NULL array\n");

return(0.0);

}

//---

if(rates_total<0)

{

printf("GetRatesItemValue: wrong rates_total number (%d)\n", rates_total);

return(0.0);

}

//---

if(shift=rates_total)

{

printf("GetRatesItemValue: wrong shift number (%d)\n", shift);

return(0.0);

}

//---

if(nrate5)

{

printf("GetRatesItemValue: wrong rate index (%d)\n", nrate);

return(0.0);

}

//

// here you are having prices, time and volume

//

int nitem=rates_total-1-shift;

switch(nrate)

{

case 0: return double(rates[nitem].ctm);

case 1: return rates[nitem].open;

case 2: return rates[nitem].low;

case 3: return rates[nitem].high;

case 4: return rates[nitem].close;

case 5: return rates[nitem].vol;

}

//---

return(0.0);

}

thanks!

do you have something in C#? because it doesn't really say something to me.

 
kfirmt:
thanks! do you have something in C#? because it doesn't really say something to me.

kfirmt

Excuse me for asking, but did you actually ever code in C/C++/C#?

It does not get simpler than the example from that post

Reason: