My coding is using IsNewBar function as below;
After compiling, there is an error message that 'IsNewBar' - function must have a body
What should I modify for my coding??
input double Lotsize=1.0;
input int Slippage=10;
input int Stoploss=30;
input
int Takeprofit=30;
input int MAPeriod=20;
input int MAShift=0;
input ENUM_TIMEFRAMES MATimeFrame=PERIOD_M30;
input
ENUM_MA_METHOD MAMethod=MODE_SMA;
input ENUM_APPLIED_PRICE MAPrice=PRICE_CLOSE;
bool IsNewBar (string symbol,
ENUM_TIMEFRAMES timeframe);
void OnTick()
{
double MA=iMA(NULL, MATimeFrame, MAPeriod,
MAShift, MAMethod, MAPrice, 0);
if (IsNewBar (Symbol(), PERIOD_M30))
{
if (Close[1] > MA)
{
OrderSend(Symbol(),OP_BUY, Lotsize, Ask,
Slippage, 0, 0, "1", 2, 0, clrGreen);
}
}
}
To answer your topic question - define a function as a body of code that is returning a value or executing a task
bool IsNewBar (string symbol, ENUM_TIMEFRAMES timeframe);
with
bool IsNewBar (string symbol, ENUM_TIMEFRAMES timeframe) { ...your code here }

- 2017.07.24
- www.mql5.com
- Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor -
For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 programming forum

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
My coding is using IsNewBar function as below;
After compiling, there is an error message that 'IsNewBar' - function must have a body
What should I modify for my coding??
input double Lotsize=1.0;
input int Slippage=10;
input int Stoploss=30;
input int Takeprofit=30;
input int MAPeriod=20;
input int MAShift=0;
input ENUM_TIMEFRAMES MATimeFrame=PERIOD_M30;
input ENUM_MA_METHOD MAMethod=MODE_SMA;
input ENUM_APPLIED_PRICE MAPrice=PRICE_CLOSE;
bool IsNewBar (string symbol, ENUM_TIMEFRAMES timeframe);
void OnTick()
{
double MA=iMA(NULL, MATimeFrame, MAPeriod, MAShift, MAMethod, MAPrice, 0);
if (IsNewBar (Symbol(), PERIOD_M30))
{
if (Close[1] > MA)
{
OrderSend(Symbol(),OP_BUY, Lotsize, Ask, Slippage, 0, 0, "1", 2, 0, clrGreen);
}
}
}