Problem with iMA in code - help needed

 

I want to get the ima over a 1 minute time frame, but just cannot seem to format the code properly, please help

ma_btc_usd[i] = iMA(BTCUSD, 0, ma_period, 0, MODE_EMA, PRICE_CLOSE, i);
ma_cad_jpy[i] = iMA(CADJPY, 0, ma_period, 0, MODE_EMA, PRICE_CLOSE, i);
 
supermagicfx: I want to get the ima over a 1 minute time frame, but just cannot seem to format the code properly, please help
Attach your codes properly.
Is this Mq4 or 5?  
 
Chioma Obunadike #:
Attach your codes properly 
Is this Mq4 or 5?  
mq5
 
supermagicfx #:
...

When you post code please use the Code button (Alt+S) !

...

Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

...

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
 
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Lime     // Buy signal color
#property indicator_color2 Red      // Sell signal color

// Input parameters
input string BTCUSD = "BTC/USD";
input string CADJPY = "CAD/JPY";
input int ma_period = 14; // Moving average period

// Indicator buffers
double BuyBuffer[];
double SellBuffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
    // Set indicator buffers
    SetIndexBuffer(0, BuyBuffer);
    SetIndexBuffer(1, SellBuffer);
    
    // Set empty values for buffers
    ArrayInitialize(BuyBuffer, EMPTY_VALUE);
    ArrayInitialize(SellBuffer, EMPTY_VALUE);
    
    // Set indicator labels
    IndicatorSetString(INDICATOR_SHORTNAME, "Oil Trading Signals");
    
    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[])
{
    int limit = rates_total - prev_calculated;
    
    // Calculate BTC/USD values
    double btc_usd[];
    ArrayResize(btc_usd, limit);
    ArraySetAsSeries(btc_usd, true);
    for (int i = 0; i < limit; i++)
        btc_usd[i] = close[i];
    
    // Calculate CAD/JPY values
    double cad_jpy[];
    ArrayResize(cad_jpy, limit);
    ArraySetAsSeries(cad_jpy, true);
    for (int i = 0; i < limit; i++)
        cad_jpy[i] = close[i];
    
    // Calculate the moving averages
    double ma_btc_usd[], ma_cad_jpy[];
    ArrayResize(ma_btc_usd, limit);
    ArraySetAsSeries(ma_btc_usd, true);
    ArrayResize(ma_cad_jpy, limit);
    ArraySetAsSeries(ma_cad_jpy, true);
    for (int i = 0; i < limit; i++)
    {
        ma_btc_usd[i] = iMA(BTCUSD, 0, ma_period, 0, MODE_EMA, PRICE_CLOSE, i);
        ma_cad_jpy[i] = iMA(CADJPY, 0, ma_period, 0, MODE_EMA, PRICE_CLOSE, i);
    }
    
    // Check for buy and sell signals
    for (int i = limit - 1; i >= 0; i--)
    {
        if (btc_usd[i] > ma_btc_usd[i] && cad_jpy[i] > ma_cad_jpy[i])
        {
            BuyBuffer[i] = close[i];  // Buy signal
            SellBuffer[i] = EMPTY_VALUE;
        }
        else if (btc_usd[i] < ma_btc_usd[i] && cad_jpy[i] < ma_cad_jpy[i])
        {
            SellBuffer[i] = close[i]; // Sell signal
            BuyBuffer[i] = EMPTY_VALUE;
        }
        else
        {
            BuyBuffer[i] = EMPTY_VALUE;
            SellBuffer[i] = EMPTY_VALUE;
        }
    }
    
    return(rates_total);
}

Thanks for your direction, I have a problem with the iMA values, string is not correctly constructed and i am not having much luck getting it to work
 
Your topic has been moved to the section: Technical Indicators — In the future, please consider which section is most appropriate for your query.
 
supermagicfx: I want to get the ima over a 1 minute time frame, but just cannot seem to format the code properly, please help

Please read the documentation on iMADocumentation on MQL5: Technical Indicators / iMA.

In MQL5, the iMA function returns a handle (which you should do in OnInit). It does no return actual buffer data as it did in MQL4.

In MQL5, you then have to use CopyBuffer to retrieve the buffer values.

Documentation on MQL5: Technical Indicators / iMA
Documentation on MQL5: Technical Indicators / iMA
  • www.mql5.com
iMA - Technical Indicators - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Reason: