error end_of_program unbalanced left parentheses

 
1) I want to sell if the current price minus the price before is negative:

void CheckForOpen()
{
double ma;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
if((iMA[1] - iMA([1]+1))<0
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid, 3, 0,0,"", MAGICMA, 0,Red);
return;
}

but the program tells me end_of_program unbalanced left parentheses. I've tried to change the 0 after PRICE_CLOSE to 1, (like I saw earlier in the forum) but it doesn't help
any ideas? THANKS!

2) Is there a general error definition and troubleshooting page which is extensive enough to have this? I only found a page with a few errors. That'd be cool.
 
1) Answer:
if((iMA[1] - iMA([1]+1))<0 -- You can't call function iMa like array.
There is no paranthese that close CheckForOpen function.
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0); -- There is no need for indicator if you compare current price with price before current.

This should solve problem:

// ----------------------------------------------------------------------------
double PriceBefore;
void CheckForOpen()
{
double ma;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- Initialize PriceBefore CheckForOpen is called first time
if(PriceBefore == 0) PriceBefore = Bid;
//---- get Moving Average
// ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
if(Bid < PriceBefore) // If current price is smaler then previus price
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"", MAGICMA, 0,Red);

PriceBefore = Bid;
return;
}
// ----------------------------------------------------------------------------
 
Thanks a lot mstanic! It works!

I'm sorry though. I didn't ask my question properly. =( What I REALLY want to do is this:

Sell if current ma is smaller than previous ma. (previous ma meaning the ma at the beginning of the last bar as usual)

Do you know how I can do that?

thanks again
 
Actually, I changed my mind on the trading time. I don't want to only check at the first tiks of a new bar.

I want the ma checked constantly- or if that's too much processing power, then once every 10 min.
 
nevermind, I figured it out
 
earth wrote:
1) I want to sell if the current price minus the price before is negative:

void CheckForOpen()
{
double ma;
int res;
//---- go trading only for first tiks of new bar
if(Volume[0]>1) return;
//---- get Moving Average
ma=iMA(NULL,0,MovingPeriod,MovingShift,MODE_SMA,PRICE_CLOSE,0);
//---- sell conditions
if((iMA[1] - iMA([1]+1))<0
{
res=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid, 3, 0,0,"", MAGICMA, 0,Red);
return;
}

but the program tells me end_of_program unbalanced left parentheses. I've tried to change the 0 after PRICE_CLOSE to 1, (like I saw earlier in the forum) but it doesn't help
any ideas? THANKS!

2) Is there a general error definition and troubleshooting page which is extensive enough to have this? I only found a page with a few errors. That'd be cool.

 
also the line: if((iMA[1] - iMA([1]+1))<0 should be (i believe) if((IMA[1] -(iMA[1]+1)) <0
 
oldman:
also the line: if((iMA[1] - iMA([1]+1))<0 should be (i believe) if((IMA[1] -(iMA[1]+1)) <0
Hello all;

I have similar problem, i try to write my first EA, but i have a problem, \end_of_program.....

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);
}
}
}
}

Can anybody help me?

Peter
 

For every ( or [ or { you must have a ) or ] or } to match.

They also have to be in a logically correct place.

Start counting/matching.

Reason: