for(i=0;i<totalorders; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
{ datetime A = OrderOpenTime();
if( (TimeYear(A)==Year())
&& (TimeMonth(A)==Month())
&& (TimeDay(A)==Day()) )
{
onedayorder = 1;
}
else
{onedayorder =2;
}
}
for(i=0;i<totalorders; i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
{ datetime A = OrderOpenTime();
if( (TimeYear(A)==Year())
&& (TimeMonth(A)==Month())
&& (TimeDay(A)==Day()) )
{
onedayorder = 1;
}
else
{onedayorder =2;
}
}
The global scope error occurs because your code above is not contained within the onstart() function
So when you say you only want your code to trade once per day, do you mean once on the start of a new day candle, or do you mean at anytime during the day but once it has traded no more trades until the start of the next day?
Either is quite simple to do. If you mean the first one, code to execute on the start of a new days candle you can use the following function.
The charts needs to be a on a day chart.
void start() { if(IsNewCandle()) { //execute code } } //+------------------------------------------------------------------+ // v1.0 // New candle function //+------------------------------------------------------------------+ bool IsNewCandle() { static int BarsOnChart=0; if(Bars == BarsOnChart) return(false); BarsOnChart = Bars; return(true); }
Thanks again Jason. I use the following code to have only one trade per day (my ea has tf 15m). However, I would like to create a variant indicating a single trade per candle (therefore with multiple trades per day). ps: is it possible to insert the trailing stop in the backtests? thanks always for your help datetime midnight = TimeCurrent()-(TimeCurrent() % (PERIOD_D1*60)); for(int i =OrdersHistoryTotal( )-1 ;i>=0;i--) { OrderSelect(i, SELECT_BY_POS, MODE_HISTORY); if( OrderMagicNumber( ) ==MagicNumber ) { if ( OrderOpenTime()>= midnight) return(0); } } for(i =OrdersTotal( )-1 ;i>=0;i--) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); if( OrderMagicNumber( ) ==MagicNumber ) { if ( OrderOpenTime()>= midnight) 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
Hi all.
Please help to add limitation for per bar/signal. Currently it opened alot of order per signal (buy/sell condition).
Thanks alot