/| ray testimg.mq4 | //| Copyright ?2010, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright ?2010, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" //---- input parameters extern double profittarget=400.0; extern double stoploss=100.0; extern double Lots=0.1; #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Red #property indicator_color4 Blue #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 3 #property indicator_width4 3 //---- extern color color1 = Red; extern color color2 = Blue; extern color color3 = Red; extern color color4 = Blue; //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; double ExtMapBuffer4[]; //---- int ExtCountedBars=0; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, color1); SetIndexBuffer(0, ExtMapBuffer1); SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, color2); SetIndexBuffer(1, ExtMapBuffer2); SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, color3); SetIndexBuffer(2, ExtMapBuffer3); SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, color4); SetIndexBuffer(3, ExtMapBuffer4); //---- SetIndexDrawBegin(0,10); SetIndexDrawBegin(1,10); SetIndexDrawBegin(2,10); SetIndexDrawBegin(3,10); //---- indicator buffers mapping SetIndexBuffer(0,ExtMapBuffer1); SetIndexBuffer(1,ExtMapBuffer2); SetIndexBuffer(2,ExtMapBuffer3); SetIndexBuffer(3,ExtMapBuffer4); //---- initialization done return(0); } //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int changing (double haOpen,double haClose,double haLow,double haHigh) { int last_direction = 0; int current_direction = 0; {if (haOpen[1] < haClose[1] && haHigh[1] > haLow[1]) = 1; if (haOpen[1] > haClose[1] && haHigh[1] < haLow[1]) = -1; if(current_direction != last_direction) { last_direction = current_direction; return (last_direction); } else { return (0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ // if(Bars<=10) return(0); ExtCountedBars=IndicatorCounted(); //---- check for possible errors if (ExtCountedBars<0) return(-1); //---- last counted bar will be recounted if (ExtCountedBars>0) ExtCountedBars--; int pos=Bars-ExtCountedBars-1; while(pos>=0) { haOpen=(ExtMapBuffer3[pos+1]+ExtMapBuffer4[pos+1])/2; haClose=(Open[pos]+High[pos]+Low[pos]+Close[pos])/4; haHigh=MathMax(High[pos], MathMax(haOpen, haClose)); haLow=MathMin(Low[pos], MathMin(haOpen, haClose)); if (haOpen<haClose) { ExtMapBuffer1[pos]=haLow; ExtMapBuffer2[pos]=haHigh; } else { ExtMapBuffer1[pos]=haHigh; ExtMapBuffer2[pos]=haLow; } ExtMapBuffer3[pos]=haOpen; ExtMapBuffer4[pos]=haClose; pos--; int start() { //Entry Sign condition bool GoLong; ; bool GoLong = false, GoShort = false; int ticket; if (haOpen[2] < haClose[2] && haHigh[2] > haLow[2])= 1 GoLong =true; { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Ask+profittarget*Point,Ask+stoploss*Point); if (haOpen[2] > haClose[2] && haHigh[2] < haLow[2])= -1 GoShort=true; { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Bid+profittarget*Point,Bid+stoploss*Point); } return(0); +------------------------------------------------------------------+
This open brace doesn't belong {if (haOpen[1] < haClose[1] && haHigh[1] > haLow[1]) = 1; if (haOpen[1] > haClose[1] && haHigh[1] < haLow[1]) = -1; if(current_direction != last_direction) { last_direction = current_direction; return (last_direction); } else { return (0); } No closing brace for function changing //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ Junk code starts - no function name. This code can only be in an indicator if(Bars<=10) return(0); ExtCountedBars=IndicatorCounted(); ... ExtMapBuffer3[pos]=haOpen; ExtMapBuffer4[pos]=haClose; pos--; Junk code ends int start() { This code can only be in an EADon't try to combine indicator code and EA code. Use iCustom() in the EA with the original indicator.
WHRoeder:
Don't try to combine indicator code and EA code. Use iCustom() in the EA with the original indicator.
t
thank i new in writing a EA i do not know what can or what cannot be writen . after reading i thought as long as code it ok it will work . i want to use Icustom but i cant find the indicator
Don't try to combine indicator code and EA code. Use iCustom() in the EA with the original indicator.
t
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
hi i just finish reading how to write MQL, i try to write an EA useing heiken to enter a trade but after writing it . i found out this error which i can find out what the problem is can anyone help me?
/+------------------------------------------------------------------+
//| ray testimg.mq4 |
//| Copyright ?2010, MetaQuotes Software Corp. |
//| https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2010, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net//"
//---- input parameters
extern double profittarget=400.0;
extern double stoploss=100.0;
extern double Lots=0.1;
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 3
#property indicator_width4 3
//----
extern color color1 = Red;
extern color color2 = Blue;
extern color color3 = Red;
extern color color4 = Blue;
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
//----
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_HISTOGRAM, 0, 1, color1);
SetIndexBuffer(0, ExtMapBuffer1);
SetIndexStyle(1,DRAW_HISTOGRAM, 0, 1, color2);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexStyle(2,DRAW_HISTOGRAM, 0, 3, color3);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexStyle(3,DRAW_HISTOGRAM, 0, 3, color4);
SetIndexBuffer(3, ExtMapBuffer4);
//----
SetIndexDrawBegin(0,10);
SetIndexDrawBegin(1,10);
SetIndexDrawBegin(2,10);
SetIndexDrawBegin(3,10);
//---- indicator buffers mapping
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexBuffer(2,ExtMapBuffer3);
SetIndexBuffer(3,ExtMapBuffer4);
//---- initialization done
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int changing (double haOpen,double haClose,double haLow,double haHigh)
{
int last_direction = 0;
int current_direction = 0;
{if (haOpen[1] < haClose[1] && haHigh[1] > haLow[1]) = 1;
if (haOpen[1] > haClose[1] && haHigh[1] < haLow[1]) = -1;
if(current_direction != last_direction)
{
last_direction = current_direction;
return (last_direction);
}
else
{
return (0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
//
if(Bars<=10) return(0);
ExtCountedBars=IndicatorCounted();
//---- check for possible errors
if (ExtCountedBars<0) return(-1);
//---- last counted bar will be recounted
if (ExtCountedBars>0) ExtCountedBars--;
int pos=Bars-ExtCountedBars-1;
while(pos>=0)
{
haOpen=(ExtMapBuffer3[pos+1]+ExtMapBuffer4[pos+1])/2;
haClose=(Open[pos]+High[pos]+Low[pos]+Close[pos])/4;
haHigh=MathMax(High[pos], MathMax(haOpen, haClose));
haLow=MathMin(Low[pos], MathMin(haOpen, haClose));
if (haOpen<haClose)
{
ExtMapBuffer1[pos]=haLow;
ExtMapBuffer2[pos]=haHigh;
}
else
{
ExtMapBuffer1[pos]=haHigh;
ExtMapBuffer2[pos]=haLow;
}
ExtMapBuffer3[pos]=haOpen;
ExtMapBuffer4[pos]=haClose;
pos--;
int start()
{
//Entry Sign condition
bool GoLong;
bool GoLong = false, GoShort = false;
int ticket;
if (haOpen[2] < haClose[2] && haHigh[2] > haLow[2])= 1 GoLong =true;
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,Ask+profittarget*Point,Ask+stoploss*Point);
if (haOpen[2] > haClose[2] && haHigh[2] < haLow[2])= -1 GoShort=true;
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,Bid+profittarget*Point,Bid+stoploss*Point);
}
return(0);