Please is this possible or correct? - page 2

 
Nkechi Sonia Kanu:

  1. The reason why i use TimeToStr() is because i notice you can convert any time either to TIME_MINUTES, TIME_DATE or TIME_SECONDS (TIME_MINUTES convert the time to hours) if i had used TimeCurrent+3600, without  #property strict it will just display series of numbers and with #property strict it will display the date, the hour, minutes and seconds thats what i don't want...i just want the time in hour thats why i use TimeToStr().r .
    datetime varl=TimeToStr(TimeCurrent()+3600,TIME_MINUTES);

Displaying it is irrelevant. It's not doing what you think.

If you use TIME_SECONDS, it's the same as if you did
datetime var1=TimeCurrent()+3600;
If you use TIME_MINUTES, all you are doing is dropping any seconds from the result. Same as if you did
datetime var1=TimeCurrent()+3600; var1 -= var1 % 60;
If you use TIME_DATE, you get the beginning of the day
datetime var1=TimeCurrent()+3600; var1 -= var1 % 86400;

Stop thinking hours and start thinking time. bool ItsBeenAnHour = TimeCurrent() - LastOrderClosedTime > 3600;

 
whroeder1:

Displaying it is irrelevant. It's not doing what you think.

If you use TIME_SECONDS, it's the same as if you did
If you use TIME_MINUTES, all you are doing is dropping any seconds from the result. Same as if you did
If you use TIME_DATE, you get the beginning of the day

Stop thinking hours and start thinking time. bool ItsBeenAnHour = TimeCurrent() - LastOrderClosedTime > 3600;

Hello Whroeder, i think i have done it base on your idea;

but please don't be mad in case i didn't get it.


void OnInit()
{

for(int i=0; i<OrdersHistoryTotal(); i++){
if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
if(OrderSymbol()==_Symbol && OrderMagicNumber()==magic_number){

datetime LastOrderClosedTime =OrderCloseTime();
}}}

bool ItsBeenAnHour=TimeCurrent() - LastOrderClosedTime>3600;
if(ItsBeenAnHour==true)
OrderSend(...);
}
 
Nkechi Sonia Kanu: Hello Whroeder, i think i have done it base on your idea; but please don't be mad in case i didn't get it.
  1. You got the time part right.
  2. But, you are getting the oldest order(sym,mn) Not the lastest. You had correct code at #7 (initially zero, compare, remember newest.)

  3. You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. "If it's been an hour" reads out loud correctly.
 
whroeder1:
  1. You got the time part right.
  2. But, you are getting the oldest order(sym,mn) Not the lastest. You had correct code at #7 (initially zero, compare, remember newest.)

  3. You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So Don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled. Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence. "If it's been an hour" reads out loud correctly.

Thank You Whroeder1,

  1. thank you so much.
  2. when you say the newest order...i know your talking about for loop, that stuff always confuses me, i believe to get the newest order i should use this:

for(int cnt=OrdersHistoryTotal()-1; cnt>=0; cnt--)

Also i will try to use meaningful variable names along with simplicity in my coding.

 
Nkechi Sonia Kanu: when you say the newest order...i know your talking about for loop, that stuff always confuses me, i believe to get the newest order i should use this:
for(int cnt=OrdersHistoryTotal()-1; cnt>=0; cnt--)
  1. You assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 and MetaTrader 4 - MQL4 programming forum
              Count how many lost orders from the last profit order - MQL4 and MetaTrader 4 - MQL4 programming forum
  2. I pointed you to "#7 (initially zero, compare, remember newest.)" I didn't say anything about the order of the loop.


 
whroeder1:
  1. You assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 and MetaTrader 4 - MQL4 programming forum
              Count how many lost orders from the last profit order - MQL4 and MetaTrader 4 - MQL4 programming forum
  2. I pointed you to "#7 (initially zero, compare, remember newest.)" I didn't say anything about the order of the loop.



Please pardon my ignorance but are you saying i should use my code in #7 in my EA, that it is correct?

thanks for the links.

i believe once i read the links i should be good in history loop

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

I have finally done my best and its not working please find it in your heart to help me in what ever way a you can:

 

It will be so rude of me not to thank you guys for helping out, though the problem isn't solved yet i have temporary abandon it, well for the time being, i hope somebody out there find a way to solve this problem.

 THANKS...

 
Nkechi Sonia Kanu: It will be so rude of me not to thank you guys for helping out, though the problem isn't solved yet i have temporary abandon it, well for the time being, i hope somebody out there find a way to solve this problem.
// This sample code is untested

#property strict

extern int magic_number = 123456789;

void OnTick()
{
   // ...
   
   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 );
}


However, this is still not going to solve your problem, because you are only looking at "closed" orders. You have to remember that there might also be orders that are still open.

So, here is the exercise for you. Show your attempt at how you would solve that part of the problem, and I will help you figure it out.

 
Fernando Carreiro:


However, this is still not going to solve your problem, because you are only looking at "closed" orders. You have to remember that there might also be orders that are still open.

So, here is the exercise for you. Show your attempt at how you would solve that part of the problem, and I will help you figure it out.


I just tested it now and it WORKED, i just cant thank you enough, your indeed a fine programmer.

in other to solve the "opening and close other" stuff, should we be looking at the OrdersTotal() instead of the OrdersHistoryTotal()


once again thank you.


Reason: