Download MetaTrader 5

Getting indicator values from a specified time

To add comments, please log in or register
Nato
22
Nato  

Dears,

I need to get value of iMA from a specified time, how I do this?

thanks

whroeder1
15580
whroeder1  
Convert the "specified time" to a bar shift, use that in iMA
Nato
22
Nato  
WHRoeder:
Convert the "specified time" to a bar shift, use that in iMA

I'm sorry, but I don't know that I do. could you give me an example?
Keith Watford
Moderator
10569
Keith Watford  

This thread

https://forum.mql4.com/61669

Has an example

Nato
22
Nato  

What is wrong with this script and how to fix?

<SRC by Moderator: Ubzen>

//+------------------------------------------------------------------+
//| test.mq4 |
//| Copyright 2013, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init() {
    //---- indicators
    shift = iBarShift(NULL, PERIOD_H1, 13 : 00)
    iMA(NULL, 0, 13, 8, MODE_SMMA, PRICE_MEDIAN, shift);
    //----
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit() {
    //----
    //----
    return (0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start() {
     int counted_bars = IndicatorCounted();
    //----
    //----
    return (0);
}
//+------------------------------------------------------------------+
Keith Watford
Moderator
10569
Keith Watford  

unless this is something new in mql4, I don't think that you can input datetime like that

shift = iBarShift(NULL, PERIOD_H1, 13 : 00)

You can use

shift = iBarShift(NULL, PERIOD_H1, D'2014.03.09 13:00');
Nato
22
Nato  

This is the errors

'iMA' - an operator expected C:\Program Files (x86)\FXDD Malta - MetaTrader 4\experts\indicators\teste.mq4 (16, 5)
'=' - assignment expected C:\Program Files (x86)\FXDD Malta - MetaTrader 4\experts\indicators\teste.mq4 (15, 11)
'iMA' - semicolon expected C:\Program Files (x86)\FXDD Malta - MetaTrader 4\experts\indicators\teste.mq4 (16, 5)
'}' - semicolon expected C:\Program Files (x86)\FXDD Malta - MetaTrader 4\experts\indicators\teste.mq4 (18, 1)

Keith Watford
Moderator
10569
Keith Watford  

if you double click the error report line, the cursor will go to the problem area, makes them easier to find

I've inserted the missing ; I'm still not sure about the 13:00

int init() {
    //---- indicators
    shift = iBarShift(NULL, PERIOD_H1, 13 : 00) ;
    iMA(NULL, 0, 13, 8, MODE_SMMA, PRICE_MEDIAN, shift);
    //----
}
To add comments, please log in or register