same problem
https://forum.mql4.com/28752
final solution
https://forum.mql4.com/28757
same problem
https://forum.mql4.com/28752
final solution
https://forum.mql4.com/28757
Thanks for the help, I'm trying to do it with Dev-C++ now, but without success until now. But I won't give up.
Anyway I would be happy if someone could have a look at my code, because I think some people will certainly find the same mistakes they made in their beginnings.
Thanks
missing parenthesis are usual.
i dont remember my beginnings, they are back in the eighties ;-)
but i make mistakes every day, so learning to debug my own code is very efficient...
your code makes partially no sense, in example here
if (TakeProfit<10) { Print ("TakeProfit less than 10"); return(0); }because there is no calulation of TakeProfit ...
1. tip
dont change much in one attempt, recompile often, you'll remeber the section where you may missed a bracket if a compile error occures
2. tip
indent brackets always and correctly something like this
if { if { if { } } }
Pay attention to this string:
if (((Hour()>=startHour) && (Hour()<=endHour)&& (Bid>=Maximum))
Pay attention to this string:
if (((Hour()>=startHour) && (Hour()<=endHour)&& (Bid>=Maximum))
Got it, I was too stupid, thanks anyway for the help. It's really better to recompile more often to find the sections with missing brackets easier.
//+------------------------------------------------------------------+
//| A.mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Essi Esser"
#property link "http://thefreemanperspective.blogspot.com"
extern int Quant_Bars=2;
extern int startHour=23;
extern int endHour=01;
extern double TakeProfit=15;
extern double StopLoss=10;
extern double Lots=0.1;
extern double TrailingStop=10;
extern bool Calculation=true;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double Maximum,Minimum;
int cnt,ticket,total;
if (Hour()==startHour)
{
Calculation=true;
Print("Calculation is true");
return(0);
}
if (Calculation==true)
{
int Ind_max=ArrayMaximum(High,Quant_Bars,1);
int Ind_min=ArrayMinimum(Low,Quant_Bars,1);
Maximum=High[Ind_max];
Minimum=Low [Ind_min];
Print ("For the last",Quant_Bars, "Bars min=",Minimum,"Bars min=",Maximum);
}
if (TakeProfit<10)
{
Print ("TakeProfit less than 10");
return(0);
}
total=OrdersTotal();
if (total<1)
{
if (Hour()>=startHour && Hour()<=endHour && Bid>=Maximum)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Night_Owl",23,0,Red);
if (ticket>0)
{
if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ("sell order opened:",OrderOpenPrice());
}
else Print ("Error opening sell order:",GetLastError());
return(0);
}
if (Hour()>=startHour && Hour()<=endHour && Ask<=Minimum)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Night_Owl",23,0,Blue);
if (ticket>0)
{
if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ("buy order opened:",OrderOpenPrice());
}
else Print ("error opening sell order:",GetLastError());
}
return(0);
}
for (cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if (OrderType()==OP_BUY)
{
if (Hour()==endHour)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
return(0);
}
if (TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
else
{
if (Hour()==endHour)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue);
return(0);
}
if (TrailingStop>0)
{
if (Bid-OrderOpenPrice()>Point*TrailingStop)
{
if (OrderStopLoss()<(Bid-Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Blue);
return(0);
}
}
}
}
}
}
//----
//----
return(0);
}
//+------------------------------------------------------------------+
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Could someone more experienced in programming have a look at my EA, because I can't find the end of program - unbalanced left parenthesis error.
Also I'm not sure about my bool operators and their logical usage in the beginning.
Thanks for your comments and feel free to use some parts of the code, if they're helpful for you.
//+------------------------------------------------------------------+
//| NIGHT_OWL_DREAM.mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
extern int Quant_Bars=2;
extern int startHour=23;
extern int endHour=01;
extern double TakeProfit=15;
extern double StopLoss=10;
extern double Lots=0.1;
extern double TrailingStop=10;
extern bool Action=true;
extern bool Calculation=true;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double Maximum,Minimum;
int cnt,ticket,total;
if (Hour()=startHour)
{
Calculation=true;
Print("Calculation is true");
return(0);
}
if (Calculation=true)
{
int Ind_max=ArrayMaximum(High,Quant_Bars,1);
int Ind_min=ArrayMinimum(Low,Quant_Bars,1);
Maximum=High[Ind_max];
Minimum=Low [Ind_min];
Alert ("For the last",Quant_Bars, "Bars min=",Minimum,"Bars min=",Maximum);
Return(0);
}
if (TakeProfit<10)
{
Print ("TakeProfit less than 10");
return(0);
}
total=OrdersTotal();
if (total<1)
{
if (((Hour()>=startHour) && (Hour()<=endHour)&& (Bid>=Maximum))
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Night_Owl",23,0,Red);
if (ticket>0)
{
if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ("sell order opened:",OrderOpenPrice());
}
else Print ("Error opening sell order:",GetLastError());
return(0);
}
if ((Hour()>=startHour) && (Hour()<=endHour)&& (Ask<=Minimum))
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"Night_Owl",23,0,Blue);
if (ticket>0)
{
if (OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ("buy order opened:",OrderOpenPrice());
}
else Print ("error opening sell order:",GetLastError());
}
return(0);
}
for (cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderType()<=OP_SELL && OrderSymbol()==Symbol())
{
if (OrderType()==OP_BUY)
{
if (Hour()=endHour)
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
return(0);
}
if (TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if(OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
else
{
if (Hour()=endHour)
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue);
return(0);
}
if (TrailingStop>0)
{
if (Bid-OrderOpenPrice()>Point*TrailingStop)
{
if (OrderStopLoss()<(Bid-Point*TrailingStop))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Blue);
return(0);
}
}
}
}
}
}
return(0);
}