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;
}
// ----------------------------------------------------------------------------
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
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
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.
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.
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
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.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
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.