May I please have a bit of help with this compile error?

 

I get the following error '\end_of_program' - unbalanced left parenthesis C:\Program Files\MetaTrader - North Finance\experts\Rappeler.mq4 (78, 1)

I haven't been in the saddle for a while and I can't find where I'm off. Can I not do a loop within a loop?

Thanks for your time.

Rollerbob

//+------------------------------------------------------------------+
//| Rappeler.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"

extern double lotmultiplier= 2.0; //factor to apply to number of opposite orders
extern double entry=-200.00; //profit in $ below which protective order is placed
extern double safeloss=10.0; // stoploss in points for protective orders
extern double takeprofit=20.0; // take profit in points for protective orders
extern int magicnum=77777; // magic number
int type, n,i; // order type counters
double ord_num; // ticket number
double profit; // order profit in $
double lots; // open order lots
string EURUSD;
string hedged_num; //ord_num converted to a string
datetime expiration=0; //20
color green;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0); //30
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0); //40
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
for (i i=0; i< OrdersTotal();i++)
{
OrderSelect (i, SELECT_BY_POS,MODE_TRADES)==FALSE Print("Error in initial selection"); break; //50
// cycle to find orders with profit less than entry profit
If (OrderProfit()>entry return;

ord_num= OrderTicket() // keeping current variable values to send into next loop
hedged_num=DoubleToStr(ord_num,1)
type= OrderType()
lots= OrderLots()

for(n=0; n<OrdersTotal();n++) // loop to check if order is currently hedged or hedge it if not
{ //60
OrderSelect (n, SELECT_BY_POS,MODE_TRADES)==FALSE Print ("Error in secondary selection"); break;
if OrderComment()=hedged_num return;
if type=0 OrderSend(EURUSD,OP_SELL,lots*lotmultiplier,Bid,3,Bid+safeloss*Point,Bid-takeprofit*Point,hedged_num,magicnum,expiration,green);
//if order is a buy then sell lotmultiplier*open lots at market.

if type=1 OrderSend(EURUSD,OP_BUY,lots*lotmultiplier,Ask,3,Ask-safeloss*Point,Ask+takeprofit*Point,hedged_num,magicnum,expiration,green);
// if order is a sell then buy lotmultiplier*open lots at market.
}
return;
//70
}
// ----

return(0);
}


//+------------------------------------------------------------------+

 

Good day,

Where to start...


(Line 52) If (OrderProfit()>entry return;

I in if is a capital and you have an unterminated ( at the start of OrderProfit. I changed this and got 4 warnings and 51 errors.


(Line 48) for (i i=0; i< OrdersTotal();i++)

There is one to many "i"s when you define your i value: for (i=0; i< OrdersTotal();i++)


Watch the Semicolons, there was 4 lines that should end in them. Yeah, I always hated when people picked on my code. I reformatted it and it compiles. I hope it still does what you need.



//+------------------------------------------------------------------+
//| Rappeler.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"

extern double lotmultiplier= 2.0; //factor to apply to number of opposite orders
extern double entry=-200.00; //profit in $ below which protective order is placed
extern double safeloss=10.0; // stoploss in points for protective orders
extern double takeprofit=20.0; // take profit in points for protective orders
extern int magicnum=77777; // magic number
int type, n,i; // order type counters
double ord_num; // ticket number
double profit; // order profit in $
double lots; // open order lots
string EURUSD;
string hedged_num; //ord_num converted to a string
datetime expiration=0; //20
color green;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0); //30
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0); //40
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
for (i=0; i< OrdersTotal();i++)
{
if (OrderSelect (i, SELECT_BY_POS,MODE_TRADES)==FALSE){
Print("Error in initial selection"); break; //50
}
// cycle to find orders with profit less than entry profit
if (OrderProfit()>entry)
{
return;
}
ord_num= OrderTicket(); // keeping current variable values to send into next loop
hedged_num=DoubleToStr(ord_num,1);
type= OrderType();
lots= OrderLots();

for(n=0; n<OrdersTotal();n++) // loop to check if order is currently hedged or hedge it if not
{ //60
if (OrderSelect(n, SELECT_BY_POS,MODE_TRADES)==FALSE){
Print ("Error in secondary selection"); break;
}
if (OrderComment()==hedged_num)
{
return;
}
if (type==0){
OrderSend(EURUSD,OP_SELL,lots*lotmultiplier,Bid,3,Bid+safeloss*Point,Bid-takeprofit*Point,hedged_num,magicnum,expiration,green);
}
//if order is a buy then sell lotmultiplier*open lots at market.

if (type==1){
OrderSend(EURUSD,OP_BUY,lots*lotmultiplier,Ask,3,Ask-safeloss*Point,Ask+takeprofit*Point,hedged_num,magicnum,expiration,green);
}
// if order is a sell then buy lotmultiplier*open lots at market.
}
return;
//70
}
// ----

return(0);
}



//+------------------------------------------------------------------+
 

Thank you so very much! I haven't written a program that I had to compile since I last put a stack of punch cards in a reader.~1979!! I'll take closer looks at each character from now on. Anyway the program doesn't quite do what I want but at least now I have a handle on debugging it. This is fun. Thanks again for your time and effort! Rollerbob