warren78: I simply want to create an indicator that calculate my custom price (Close + Spread/2). and I don't manage to do it...
"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.
learntocodeit. 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.
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.
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 parametersdouble MA[]; // Moving Average Arraydouble PRICE_MIDDLE []; // customized price serie//---- handles for indicatorsint MA_handle; // array for the indicator MAint PRICE_MIDDLE_handle; // array for the indicator PRICE_MIDDLE// handle of the indicator iMA//+------------------------------------------------------------------+//| Expert initialization function |//+------------------------------------------------------------------+intOnInit()
{
//---
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 |//+------------------------------------------------------------------+voidOnDeinit(constint reason)
{
//---
}
//+------------------------------------------------------------------+//| Expert tick function |//+------------------------------------------------------------------+voidOnTick()
{
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]);
}
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.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
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...
-
Search for it,
-
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.
-
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.
-
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 :
No you can't.
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 :
Do you have an idea why this happens?