This is my first code in MQL4 and just trying to get it working. there are no orders going through but no errors or warnings pop up.
It is an indicator. Indicators cannot handle orders
Keith Watford:
It is an indicator. Indicators cannot handle orders
is there a simple way to make it an EA or do i need to re do it?
It is an indicator. Indicators cannot handle orders
brolarbear: is there a simple way to make it an EA or do i need to re do it?
| Don't do that. Write your EA and just get the value of the indicator. You should write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum |
whroeder1:
So is iCustom basically how you get value from other indicators or files?
Don't do that. Write your EA and just get the value of the indicator. You should write a self documenting function instead of calling iCustom directly, see Detailed explanation of iCustom - MQL4 forum |
brolarbear:
So is iCustom basically how you get value from other indicators or files?
So is iCustom basically how you get value from other indicators or files?
Yes, other indicators.
No, not other files.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
}//+------------------------------------------------------------------+
//| MAvsRSI.mq4 |
//| Copyright 2017, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_color1 Black //RSI color
#property indicator_color2 Green
#property indicator_level1 32 //SetLevelValue(0,50);
#property indicator_level2 50 //SetLevelValue(1,68);
#property indicator_level3 68 //SetLevelValue(2,32);
#property indicator_levelcolor DimGray //color indicator value
#define BIGMACMATT 42069
//--- input parameters
extern int RSI_Period = 13; //8-25
extern int RSI_Price = 0; /*PRICE_CLOSE 0 Close price.
PRICE_OPEN 1 Open price.
PRICE_HIGH 2 High price.
PRICE_LOW 3 Low price.
PRICE_MEDIAN 4 Median price, (high+low)/2.
PRICE_TYPICAL 5 Typical price, (high+low+close)/3.
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. */
extern int RSI_MA_Period = 7;
extern int RSI_MA_Type = 0; // 0 SMA , 1 EMA , 2 SMMA , 3 LWMA
input double Lots = 0.01;
//--- buffers
double RSIBuf[];
double MaBuf[];
int init()
{
IndicatorShortName("MA of the RSI");
//---- drawing settings RSI (0,......)
SetIndexBuffer(0,RSIBuf);
SetIndexLabel(0,"RSI"); //SetIndexLabel(0,NULL); wrong
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1); //SetIndexStyle(0,DRAW_NONE);wrong this is draw nothing
//---- drawing settings of Moving Average on RSI
SetIndexBuffer(1,MaBuf);
SetIndexLabel(1," ("+RSI_MA_Period+") Period MA of RSI"); //SetIndexLabel(1,"MA of the RSI");
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1); //SetIndexStyle(1,DRAW_LINE);
//SetLevelValue(0,50);
//SetLevelValue(1,68);
//SetLevelValue(2,32);
//SetLevelStyle(STYLE_DOT,1,DimGray);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int start()
{
bool tradedirection;
int i;
int res;
double MA,RSI[];
ArrayResize(RSI,RSI_MA_Period);
int counted_bars=IndicatorCounted();
int limit = Bars-counted_bars-1;
for(i=limit; i>=0; i--)
RSIBuf[i] = (iRSI(NULL,0,RSI_Period,RSI_Price,i));
MA = 0;
for(int x=i; x<i; x++) {
RSI[x-i] = RSIBuf[x];
MA += RSIBuf[x]/RSI_MA_Period;}
if(OrdersTotal()>0 && MA>50)
{
if (!OrderClose(OrderTicket(),1,Ask,3,Blue)){
Print("OrderModify error ",GetLastError());}
}
if(OrdersTotal()>0 && MA<50)
{
if (!OrderClose(OrderTicket(),1,Bid,3,Red)){
Print("OrderModify error ",GetLastError());}
}
if(MA<50 && OrdersTotal() <1)
{
tradedirection = false;
res=OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,"",BIGMACMATT,0,Red);
}
if(MA>50 && OrdersTotal() <1)
{
tradedirection = true;
res=OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"",BIGMACMATT,0,Blue);
}
for(int j=limit; j>=0; j--) //was missing
{MaBuf[j] = (iMAOnArray(RSIBuf,0,RSI_MA_Period,0,RSI_MA_Type,j));}
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);