open buy and sell from a custom indiator

 

hi everyone 

i have an indiator i want to get signal from it 

please help me how can i get buy and sell signal from it thank you

Files:
CMA.mq4  6 kb
 

You can use an Expert Advisor code to open buy and sell operations. Afaik indicators are for analysing trends and not placing orders

On MetaEditor (MT4) open File, New, Expert Advisor template

Copy the necessary code from your indicator to the EA template 

Among other changes Your OnCalculate(...) function will be replaced by OnTick() 

To initiate orders e.g. BUY  you can read a bit here: https://docs.mql4.com/trading/ordersend

For example 

int ticket=OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",16384,0,clrGreen);

If you want to read the indicator values, set up the EA then in your EA code inside OnTick() function place the following 

   int lineindex=0;

  Int bar = 0;

  double var = iCustom("CMA",lineindex,bar);

This will read the latest value of line 0.

There are 5 graph lines in your CMA indicator so from 0 to 4 you can read.

 Your CMA indicator has this code below so there are 5 graph lines:


SetIndexBuffer(0,ma,INDICATOR_DATA);

 SetIndexBuffer(1,cma,INDICATOR_DATA);

SetIndexBuffer(2,up,INDICATOR_DATA);

SetIndexBuffer(3,dn,INDICATOR_DATA);

SetIndexBuffer(4,trend,INDICATOR_CALCULATIONS);


But your CMA indicator specified 4 buffers instead of 5 buffers. You can fix that

  #property indicator_buffers 4

Just remove 4 and type 5

Documentation on MQL5: File Functions / FileOpen
Documentation on MQL5: File Functions / FileOpen
  • www.mql5.com
FileOpen - File Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
Reason: