Edit Your Comment
Pease i need your support
Sep 10, 2017 at 07:57
Uczestnik z Feb 06, 2017
31 postów
Hello guys i have this idea i wish to implement into my EA, this idea involve waiting one hour after my order has been close that is either if TP or SL is hit and i have been thinking and came up with this so guy please i need your help.
below is my attempt, is it correct? or should there be any changes. THANK IN ADVANCE.
if(OneHour()==1)
{
OrderSend(...)
}
int OneHour()
{
int HasItBeenAnHourSinceLastTrade=0;
for(int i=0; i<OrdersHistoryTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number)
{
if(TimeCurrent() - OrderCloseTime() > 3600)
{
HasItBeenAnHourSinceLastTrade++;
}
}
}
}
return(HasItBeenAnHourSinceLastTrade);
}
below is my attempt, is it correct? or should there be any changes. THANK IN ADVANCE.
if(OneHour()==1)
{
OrderSend(...)
}
int OneHour()
{
int HasItBeenAnHourSinceLastTrade=0;
for(int i=0; i<OrdersHistoryTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number)
{
if(TimeCurrent() - OrderCloseTime() > 3600)
{
HasItBeenAnHourSinceLastTrade++;
}
}
}
}
return(HasItBeenAnHourSinceLastTrade);
}
Tomorrow is far away but yesterday is so close.
Uczestnik z Aug 20, 2009
266 postów
Sep 11, 2017 at 06:24
Uczestnik z Aug 20, 2009
266 postów
Hi Wamski,
Not a bad attempt.......but let's see if we can improve it a bit.....
if(OneHour()){ //you don't need to check if ==1 just use OneHour() or !OneHour()
Ordersend.......
}
bool OneHour()
{
for(int i=OrdersHistoryTotal()-1;i>=0; i--){ //it is good practice to count your loops downwards......make it a habit
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number){
if(TimeCurrent() - OrderCloseTime() < 3600)return(false); //checking if there is an order younger than 1 hour not older
}
}
}
return(true);
}
Basically you loop through all your orders. the moment it detects one younger than 1 hour, it immediately returns false(no point looking any further).
Hope it helps.
Kenny
Not a bad attempt.......but let's see if we can improve it a bit.....
if(OneHour()){ //you don't need to check if ==1 just use OneHour() or !OneHour()
Ordersend.......
}
bool OneHour()
{
for(int i=OrdersHistoryTotal()-1;i>=0; i--){ //it is good practice to count your loops downwards......make it a habit
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number){
if(TimeCurrent() - OrderCloseTime() < 3600)return(false); //checking if there is an order younger than 1 hour not older
}
}
}
return(true);
}
Basically you loop through all your orders. the moment it detects one younger than 1 hour, it immediately returns false(no point looking any further).
Hope it helps.
Kenny
Wealth Creation Through Technology
Uczestnik z Aug 20, 2009
266 postów
Sep 11, 2017 at 06:24
Uczestnik z Aug 20, 2009
266 postów
Also just remember that you start your loop at OrdersHistoryTotal() -1 because the orderselect by position is indexed from zero it your first order is 0, not 1.
Wealth Creation Through Technology
Sep 11, 2017 at 06:36
Uczestnik z Feb 06, 2017
31 postów
if( OneHour() )
{
// OrderSend(...)
}
// ...
bool OneHour()
{
datetime OneHourBack = TimeCurrent() - 3600;
for( int i = OrdersHistoryTotal() - 1; i >= 0; i-- )
{
if( OrderSelect( i, SELECT_BY_POS, MODE_HISTORY ) )
{
if( ( OrderSymbol() == _Symbol ) &&
( OrderMagicNumber() == magic_number ) )
{
if( OrderCloseTime() >= OneHourBack )
return( false );
}
}
}
return( true );
}
{
// OrderSend(...)
}
// ...
bool OneHour()
{
datetime OneHourBack = TimeCurrent() - 3600;
for( int i = OrdersHistoryTotal() - 1; i >= 0; i-- )
{
if( OrderSelect( i, SELECT_BY_POS, MODE_HISTORY ) )
{
if( ( OrderSymbol() == _Symbol ) &&
( OrderMagicNumber() == magic_number ) )
{
if( OrderCloseTime() >= OneHourBack )
return( false );
}
}
}
return( true );
}
Tomorrow is far away but yesterday is so close.
Sep 11, 2017 at 06:36
Uczestnik z Feb 06, 2017
31 postów
The above code is the correct one, i posted this so that in the future, if someone should have this same problem and research, the answer/solution will be available in the internet.
NOTICE: what this piece of code does is is delay trade operation for one hour if TP or SL is hit
NOTICE: what this piece of code does is is delay trade operation for one hour if TP or SL is hit
Tomorrow is far away but yesterday is so close.
Sep 13, 2017 at 06:22
Uczestnik z Feb 06, 2017
31 postów
compuforexpamm posted:
Also just remember that you start your loop at OrdersHistoryTotal() -1 because the orderselect by position is indexed from zero it your first order is 0, not 1.
thanks for your help
Tomorrow is far away but yesterday is so close.
*Komercyjne wykorzystanie i spam są nieprawidłowe i mogą spowodować zamknięcie konta.
Wskazówka: opublikowanie adresu URL obrazu / YouTube automatycznie wstawi go do twojego postu!
Wskazówka: wpisz znak@, aby automatycznie wypełnić nazwę użytkownika uczestniczącego w tej dyskusji.