MT4/MT5 data flow - page 2

 
warren78:
in the iMA command you have the ability to define a custom enum price. That is what I'm trying to use...

No you can't just define a "custom enum price", where did you see that ?

You can :

1° Build a custom indicator to calculate your custom price, then get an handle to this indicator and use it with iMA.

2° Don't use iMA at all and create your own custom indicator to calculate an MA of your custom price.

 

exactly what I'm trying to do : create a custom indicator to get a handle to be used with existing functions such as iMA or iRSI.

The thing is if this indicator would be using iMA or other functions returning a handle that would be fine. but in my case I simply want to

create an indicator that calculate my custom price (Close + Spread/2). and I don't manage to do it...

 
warren78: I simply want to create an indicator that calculate my custom price (Close + Spread/2). and I don't manage to do it...
  1. "Don't manage" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. We can't see your broken code. There are no mind readers here and our crystal balls are cracked.

  2. You have only four choices:
    1. Search for it,
    2. Beg at Will code your trading systems for free - Free Expert Advisors - Trading Systems - MQL5 programming forum, or Coding help - MQL4 and MetaTrader 4 - MQL4 programming forum, or Need help with coding - General - MQL5 programming forum, or Free MQL4 To MQL5 Converter - General - MQL5 programming forum, or Requests & Ideas (MQL5 only!), or I will code & automate your strategy for free - Options Trading Strategies - General - MQL5 programming forum.
    3. learn to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
    4. or pay (Freelance) someone to code it.
    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
              No free help
              urgent help.

 

for instance when instead of a PRICE_CLOSE I use a RSI, this is fairly direct since the iRSI function returns a handle...

ie : CUSTOM_HANDLE = iRSI(....) then you can use CUSTOM_HANDLE in the original iMA function and that works. But in my case

I can't do CUSTOM_HANDLE = iClose (NULL,0,0) + iSpread (NULL,0,0)....

 

Alain,

thanks for naming the rules. First, I don't want to have code generated by someone else, I have lots of PRT EA to redevelop using MT5.

Maybe, the global topic is of interest, I don't know what you think. Generally speaking, MT5 uses Bid price to determine the Close Price,

where as PRT uses Middle Price (Bid + Spread/2). That is why every people looking to "migrate" PRT EAs to MT5 EAs will have to deal with that.

In order to be more efficient and reuse all MT5 built in functions (iMA, iRSI,etc....) I think it is better to create a custom indicator that calculates

the MIDDLE PRICE.

Having said that, I've searched a lot and I'm blocked at compilation time with a array out of range message.

Here is the code :

//+------------------------------------------------------------------+
//|                                                    CUSTOM_MA.mq5 |
//|                                                         WARREN78 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "WARREN78"
#property link      ""
#property version   "1.00"

//--- input parameters
double      MA[];                         // Moving Average Array
double      PRICE_MIDDLE [];              // customized price serie

//---- handles for indicators
int         MA_handle;                    // array for the indicator MA
int         PRICE_MIDDLE_handle;          // array for the indicator PRICE_MIDDLE
         // handle of the indicator iMA

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   MA_handle= iMA(NULL,0,50,0,MODE_SMA,PRICE_MIDDLE_handle);
   SetIndexBuffer(0,MA,INDICATOR_DATA);
   ArraySetAsSeries(MA,true);
   SetIndexBuffer(0,PRICE_MIDDLE,INDICATOR_DATA);
   ArraySetAsSeries(PRICE_MIDDLE,true);
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {

PRICE_MIDDLE[0]= iClose(NULL,0,0)+ iSpread(NULL,0,0);

CopyBuffer(MA_handle,0,0,100000,MA);
CopyBuffer(PRICE_MIDDLE_handle,0,0,100000,PRICE_MIDDLE);

Print(MA[0]);

 }

 
warren78: I can't do CUSTOM_HANDLE = iClose (NULL,0,0) + iSpread (NULL,0,0)....

No you can't.

warren78: I simply want to create an indicator that calculate my custom price (Close + Spread/2).

Write the indicator. Then you can use iMA(indicatorHandle)

Or create an indicator with a price buffer, and then implement iMAOnArray on a second buffer.

 

Thanks for your answer. As I want to take advantage of the built in functions of MT5, I will go for your first proposition ie write an indicator that computes

the price and then apply iMA to it.

I created an indicator in a file called prix : the file compiles well and also shows the right price on a graph.

Then I have my main code file that is supposed to compute the MA of this indicator.

The iMA calculation doesn't take into account the prices that I put in the prixBuffer.

Even if I put zero, the MA is still the same and doesn't change.


Both files source codes are below :

//+------------------------------------------------------------------+
//|                                                         prix.mq5 |
//|                                                         WARREN78 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "WARREN78"
#property link      ""
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot prix
#property indicator_label1  "prix"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- indicator buffers
double         prixBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,prixBuffer,INDICATOR_DATA);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
   for (int i=1;i<rates_total;i++)
   {
   prixBuffer[i]= close[i] + spread[i];
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                                    CUSTOM_MA.mq5 |
//|                                                         WARREN78 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "WARREN78"
#property link      ""
#property version   "1.00"

//--- input parameters
double      MA[];                         // Moving Average Array
double      PRICE_MIDDLE [];              // customized price serie

//---- handles for indicators
int         MA_handle;                    // array for the indicator MA
int         PRICE_MIDDLE_handle;          // array for the indicator PRICE_MIDDLE
         // handle of the indicator iMA

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   MA_handle= iMA(NULL,0,2,0,MODE_SMA,PRICE_MIDDLE_handle);
   SetIndexBuffer(0,MA,INDICATOR_CALCULATIONS);
   ArraySetAsSeries(MA,true);
   //SetIndexBuffer(0,PRICE_MIDDLE,INDICATOR_DATA);
   //ArraySetAsSeries(PRICE_MIDDLE,true);
   PRICE_MIDDLE_handle=iCustom(NULL,0,"prix");
   
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+

void OnTick()
  {

CopyBuffer(MA_handle,0,0,100000,MA);
Print (MA[0]);


 }

Do you have an idea why this happens? 

Reason: