Sign Up

Have an account? Sign In Now

Sign In

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here
Sign InSign Up

First independent community of traders

First independent community of traders Logo First independent community of traders Logo

First independent community of traders Navigation

  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • Buy Theme
  • Home
  • About Us
  • Blog
  • Contact Us

Share your knowledge in the forex community!

Our community is a completely independent place for communication between forex traders and software developers for trading platforms Metatrader 4 and Metatrader 5

Create A New Account
Home/ Questions/Q 6913
Next
In Process
1006293
1006293

1006293

  • 1 Question
  • 1 Answer
  • 0 Best Answers
  • 20 Points
View Profile
  • 0
1006293
Asked: April 8, 20212021-04-08T06:52:01+00:00 2021-04-08T06:52:01+00:00In: Forex Expert Advisors

A question about the intersection of moving averages in MQL5

  • 0

Good day to all forumchanam. I can’t figure out the sliding ones. More precisely, how to take the readings of two moving averages in mql5 ? I read the help, but I can’t figure it out yet. I want to take the fast MA readings at 10 and 15 bars. And the same slow MA at 10 and 15 bars, but Cheto already does not think straight, he is completely confused. It was based on the standard code and references.  Even the value of one moving average is already displayed incorrectly.  Tell me who will tell you how to implement this code. Thank you all in advance. //---- indicator buffers
double MA10_fast []; / / array of the 1st fast MA bar
double MA15_fast []; / / array of the 2nd fast MA bar

//---- handles for indicators
int MA_handle_fast; / / pointers to the fast iMA indicator
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
//- - - creating a pointer to an iMA indicator object
   MA_handle_fast = iMA(NULL,0,7,0,MODE_EMA,PRICE_CLOSE); / / fast iMA
return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void onTick()
{
//- - - filling the MA [] array with the current values of the iMA indicator
/ / - - - 100 CopyBuffer elements will be written to the array
(MA_handle_fast,0,0,20, MA15_fast);
   / / - - - setting the indexing order of the MA[] array as in MQL4
ArraySetAsSeries(MA15_fast,true);
   / / - - - and then do whatever you want with this data, for example:
/* if(MA[0]>MA[1])
{
//--- performing some operations
      
      }*/

   Comment ("MA_1 = "+DoubleToString(MA15_fast[15],_Digits));
return;
   }

  • 3 3 Answers
  • 0 Followers
  • 0
Answer
Share
  • Facebook

    3 Answers

    • Voted
    • Oldest
    • Recent
    1. 1006293

      1006293

      • 1 Question
      • 1 Answer
      • 0 Best Answers
      • 20 Points
      View Profile
      1006293
      2021-04-08T06:52:22+00:00Added an answer on April 8, 2021 at 6:52 am

      Good day to all who answered, and to all forumchanam. I was completely confused, and decided to re-take the standard code and start to understand again. I output the value of the indicator value, and according to the idea it should coincide with the closing of the candle that I specified (in my case,the 10th bar), but I look at the value of the bar and it does not match. I don’t understand what the error is, where does it get this Close value from ??? I just just started learning mql5 and want to do a simple moving average intersection. But to do this, you need to get the values of the moving averages. And in my case, some gibberish turns out! Of course, I understand that I can’t do it properly. Tell me who knows what the reason is?! Thank you all in advance for your answers.

      //---- indicator buffers
      double MA []; / / array for the iMA indicator
      //---- handles for indicators
      int MA_handle; / / pointer to the iMA indicator
      //+------------------------------------------------------------------+
      //| Expert initialization function                                   |
      //+------------------------------------------------------------------+
      int OnInit()
        {
         Comment(" ");
         / / - - - creating a pointer to an iMA indicator object
         MA_handle=iMA(NULL,0,21,0,MODE_EMA,PRICE_CLOSE);
         / / - - - if an error occurred when creating the object, then output the message
      if(MA_handle<0)
      {
      Print("iMA object not created: MA_handle= ",INVALID_HANDLE);
            Print("Execution error=",GetLastError());
      / / - - - forced program termination
            return(-1);
            }
         return(0);
        }
      //+------------------------------------------------------------------+
      //| Expert tick function                                             |
      //+------------------------------------------------------------------+
      void OnTick()
      {
      //--- fill the array MA[] current values of the indicator iMA
      / / in the array will be written 100 items, and if there is
      //--- error stop execution of further operations
      if(CopyBuffer(MA_handle,0,0,100,MA)<=0) return;
         / / - - - setting the indexing order of the MA[] array as in
      the ArraySetAsSeries timeseries(MA,true);
        
         Comment("MA_1 = "+DoubleToString(MA[10],_Digits));
         / / - - - and then do whatever you want with this data
        }

      Here, for example, I run the code on EURUSD, H1 and I output the value MA_1 = 1.21170, I look at the destination of the 10th bar, Close 21.21261, and the idea should be the closing of the 10-bar 1.21170, or am I confusing something? I'm telling you, you're already confused!

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    2. alexandrim

      alexandrim

      • 0 Questions
      • 2 Answers
      • 0 Best Answers
      • 26 Points
      View Profile
      alexandrim
      2021-04-08T06:52:13+00:00Added an answer on April 8, 2021 at 6:52 am

      OnInit – properties of the indicator, not the code itself.

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    3. elenavvt

      elenavvt

      • 1 Question
      • 8 Answers
      • 0 Best Answers
      • 22 Points
      View Profile
      elenavvt
      2021-04-08T06:52:07+00:00Added an answer on April 8, 2021 at 6:52 am

      To avoid confusion, I usually create a handle for each parameter, so it’s easier, and then just match the values of one and the other. You have an error in the enumeration of the handle parameters, please review it in accordance with the help  

      • 0
      • Reply
      • Share
        Share
        • Share on Facebook
        • Share on Twitter
        • Share on LinkedIn
        • Share on WhatsApp
    Leave an answer

    Leave an answer
    Cancel reply

    Browse

    Sidebar

    Ask A Question

    Stats

    • Questions 514
    • Answers 2k
    • Posts 5
    • Comments 0
    • Best Answers 0
    • Users 921
    • Popular
    • Answers
    • Tags
      • On: December 18, 2020
      • Answers: 16

      How to allow trading at certain times

      • On: December 29, 2020
      • Answers: 16

      Example of implementing the OOP pattern Abstract Factory using MQL5 ...

      • On: December 18, 2020
      • Answers: 15

      EMA with a different formula

      • On: December 29, 2020
      • Answers: 15

      Invitation for algo traders.

      • On: December 29, 2020
      • Answers: 14

      Dear Programmers, do not pass by, help fix the error!

    • atma1
      atma1 added an answer Added activation. Thanks. April 8, 2021 at 6:54 am
    • iks_
      iks_ added an answer Atma1: Good day, dear colleagues. Yesterday I updated VMware to… April 8, 2021 at 6:54 am
    • renat
      renat added an answer Atma1: Good day, dear colleagues. Yesterday I updated VMware to… April 8, 2021 at 6:54 am
    • mvs
      mvs added an answer Renat Fatkhullin: You can not immediately send the received data,… April 8, 2021 at 6:53 am
    • anton_m
      anton_m added an answer Renat Fatkhullin: How much data do you read? You can… April 8, 2021 at 6:53 am
    analytics british company computer developers django employee employer english facebook french google interview javascript language life php proforexea programmer programs pro vsa salary university

    Related Questions

    • atma1

      Yesterday I updated VMware to version 16.1.0 and the product ...

      • 3 Answers
    • anton_m

      It is not possible to read data from the server ...

      • 6 Answers
    • s22aa

      Tell me what the difference is.

      • 2 Answers
    • areedbreen

      on the chart in the tester one yield and in ...

      • 2 Answers
    • gsasha

      A strange phenomenon, there was no Windows update, and the ...

      • 3 Answers

    Users

    atma1

    atma1

    • 1 Question
    • 1 Answer
    s22aa

    s22aa

    • 1 Question
    • 1 Answer
    areedbreen

    areedbreen

    • 1 Question
    • 1 Answer

    Footer

    First independent community of traders

    About

    An independent community of forex traders. This is where traders communicate. You can ask your questions and you will receive an answer to your question.
    • Terms of Use
    • Privacy Policy
    • Cookie Policy
    • Knowledge Base
    • Support

    © 2021 Forexcommunity.net. All Rights Reserved