Can someone explain Indicator/EA differences

To add comments, please log in or register
Ralph Freshour
80
Ralph Freshour  

So I read in basic terms that an Indicator shows you trends, MA's, etc. but that Indicator scripts do not (or maybe is was cannot) do trade.buy and trade.sell functions. You have to write an EA to do trades.

My questions is really this:

If I write an EA to do trades, I'd want to code in some indicators/triggers for the trades to kick in or not kick in. Should I start with one of the Indicator scripts and modify it to do trades or should I write the script as an EA script and copy the indicator code to get the indicators working in the EA script?

I'm just a little confused about the structure of the Indicator scripts vs the EA scripts.

Thank you...

Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
Documentation on MQL5: Constants, Enumerations and Structures / Named Constants / Predefined Macro Substitutions
  • www.mql5.com
//| Expert initialization function                                   | //| Expert deinitialization function                                 | //| Expert tick function                                             | //| test1                                                            |...
Vladimir Karputov
Moderator
207337
Vladimir Karputov  
Ralph Freshour :

So I read in basic terms that an Indicator shows you trends, MA's, etc. but that Indicator scripts do not (or maybe is was cannot) do trade.buy and trade.sell functions . You have to write an EA to do trades.

My questions is really this:

If I write an EA to do trades, I'd want to code in some indicators/triggers for the trades to kick in or not kick in. Should I start with one of the Indicator scripts and modify it to do trades or should I write the script as an EA script and copy the indicator code to get the indicators working in the EA script?

I'm just a little confused about the structure of the Indicator scripts vs the EA scripts.

Thank you...

Personally, I like to do this: to test an idea (to visually evaluate the idea) - I am writing an indicator. If the idea is of interest - I write an adviser on this indicator.


In general, the main thing is first the idea, then the realization of the idea.

William Roeder
22709
William Roeder  
Ralph Freshour: should I write the script as an EA script and copy the indicator code to get the indicators working in the EA script?

Can you drive in the ocean? Can you boat down the highway?

Don't try to do that. There are no buffers, no IndicatorCounted() or prev_calculated. No way to know if older bars have changed or been added (history update.)

Just get the value(s) of the indicator(s) into EA/indicator (using iCustom) and do what you want with it.

You should encapsulate your iCustom calls to make your code self-documenting.
          Detailed explanation of iCustom - MQL4 programming forum #33 2017.05.23

Ralph Freshour
80
Ralph Freshour  

I found a good explanation here: https://www.mql5.com/en/articles/496

This is a good explanation if you're new to MT5 programming like I am.

A Quick Start Or a Short Guide for Beginners
A Quick Start Or a Short Guide for Beginners
  • www.mql5.com
Hello dear reader! In this article, I will try to explain and show you how you can easily and quickly get the hang of the principles of creating Expert Advisors, working with indicators, etc. It is beginner-oriented and will not feature any difficult or abstruse examples. So the article may probably not be so inspiring and informative for those...
Isaac Kimani
935
Isaac Kimani  
Ralph Freshour:

So I read in basic terms that an Indicator shows you trends, MA's, etc. but that Indicator scripts do not (or maybe is was cannot) do trade.buy and trade.sell functions. You have to write an EA to do trades.

My questions is really this:

If I write an EA to do trades, I'd want to code in some indicators/triggers for the trades to kick in or not kick in. Should I start with one of the Indicator scripts and modify it to do trades or should I write the script as an EA script and copy the indicator code to get the indicators working in the EA script?

I'm just a little confused about the structure of the Indicator scripts vs the EA scripts.

Thank you...

If you want to create an EA based on an indicator.  Lets assume you want to create an EA for MT4. You will have to follow this procedure.
- Create an Expert  Advisor template 
-In the OnTick() function, thats where you place the main code that will be executed over and over again every time the market price changes. 
Since you are a beginner, it is not necessary to use the OnInit() and OnDenit function. 
- You will not necessarily need to create any indicators, you can use the indicators already available in the platform.
Also you do not need to copy the indicators code into the Expert Advisor template, you do what is known as "Calling" the indicator. 
Now you simply use the indicator that you need in the Ontick() function to filter conditions to trade. 
-When you call the OrderSend() function, the trades will be opened repeatedly everytime your condition is met. 

Note this is simply a quick guide. 

To add comments, please log in or register