Indicator to EA - MT5

 

I tried to make an EA from a indicator. 

I took the basics of the indicator and added the necessary stuff to make a trade in some of the indicator points. 

And now it error free within the  MetaEditor. But now i want to backtest te EA but it is still showing the indicator image in MT5. So it won't let it backtest the EA.

 

See the attachment. The Envelops_ea has the good icon but the Beginner_ea is still showing the indicator image..

Ive tried to copy the code in a new window of a exitsting EA but that also does not work. How can i solve this problem?   

Files:
Naamloos.png  3 kb
 

Hi,

1. You can not use any trading functions within the Indicator.

2. You can not make the EA from indi, just putting trading functionality inside. These are 2 different types of program.

Your new "EA" has an indicator icon and quality, because it has #property indicator_chart_window string in it, and plots lines.

If you want to build an EA based on custom indi, you should create new file with EA and use indicator via iCustom function.

Hope it helps.

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Language Basics / Preprocessor / Program Properties (#property) - Documentation on MQL5
 

Ah ok, i understand. 

Ive to work the other way arround.

Build a EA and implement the indicator and not take the indicator and build the EA inside.


Ill try to figure out the iCustom function. Thx for the fast reply.

 
Ive been working with the iRSI to get more understanding. But i cant get the right value..

example:

double rsi_chart = iRSI(symbol[0],PERIOD_CURRENT,10, PRICE_CLOSE) ; 

if( rsi_chart > 70 ){ 
OpenFromMarket(ORDER_TYPE_BUY) ; 
} 

When the RSI value is more then 70. Start long trade.

But it is not giving me the right RSI value.. Because it trades anyway..

So maybe the rsi_chart has to be int. So do i did:
int moment_int = (int) moment_chart ; 
int rsi_int = (int) rsi_chart ; 

But that is also not working or am i taking the wrong price, 'PRICE_CLOSE' ?



The RSI chart is showing good in the backtest but the EA is not trading on the RSI outcome..
 

well, you better refer to the CopyBuffer function in the documentation page.

The basic procedure processing indicators looks as following.

1. You declare a handle (Global Scope)

int handle=-1;

2. You initialize the handle (OnInit function)

handle= iRSI(_Symbol,PERIOD_CURRENT,10, PRICE_CLOSE) ; 

You can also then check if your handle is not INVALID_HANDLE

3. You get the value from the indicator's buffer (OnTick function or whenever you need it)

double rsi[1]={0};
CopyBuffer(handle,.......,rsi);

and you can also check how many elements were copied etc etc.

Refer to the documentation for more info.

Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
Timeseries and Indicators Access / CopyBuffer - Documentation on MQL5
 

Yes i figured it out.. It is (almost) the same as you did with the iEnvelops, it needs his history to work properly.

And it works now. thks

 
Kima:

Yes i figured it out.. It is (almost) the same as you did with the iEnvelops, it needs his history to work properly.

And it works now. thks

Well, yes. The procedure is the same, regardless the indi. It is the same for all standard MT5 indicators and for custom indicators as well.
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • 2009.11.23
  • Андрей
  • www.mql5.com
I will not list all of the new possibilities and features of the new terminal and language. They are numerous, and some novelties are worth the discussion in a separate article. Also there is no code here, written with object-oriented programming, it is a too serous topic to be simply mentioned in a context as additional advantages for developers. In this article we will consider the indicators, their structure, drawing, types and their programming details, as compared to MQL4. I hope that this article will be useful both for beginners and experienced developers, maybe some of them will find something new.
 
I am struggling a bit to get the last value, is this right? 
// rsi point
double get_rsi(int handle,int bar)
  {
   double rsi_line[1]={0};
   CopyBuffer(handle,0 ,bar,1,rsi_line);
   return(rsi_line[0]);
  }

// if last point rsi value > (bigger then) the point before last rsi value ) { 
if( get_rsi(handles_rsi[i], 0 ) > get_rsi(handles_rsi[i], 1 ) ) {
int rsi_go = 1 ;
}

Is this right? Because it trades sometimes a bit weird..

Or is is because 'get_rsi(handles_rsi[i], 0 )' is the point that is still to be set on a value, and is still fluctuating up and down? 

 
Code looks ok, so yes, probably this is because you are using the close price of the current bar which is changig.

There are 2 options. You either use points 2&1 instead of 1&0 or you build your RSI based on PRICE_OPEN instead of PRICE_CLOSE
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Standard Constants, Enumerations and Structures / Indicator Constants / Price Constants - Documentation on MQL5
 

Ah ok, i thought maybe i used the wrong values from the indicator or it was the changing bar, it was the last one.

Now i use  PRICE_OPEN and the results are much more stable. 

 

Getting information from standard inducators like iMomentum/iRSI and so on i can handle.

But from  iCustom  is now just a bit to early i think. I cant get the right value from the indicator to the ea by copybuffer.

It will figure it out if the time is right.

 

 

 
I think you should use code free about ea rsi . After that, you fix it same your ideal
Reason: