Have the open price of candle at specific hour. - page 2

 
Kane59:

Ok, i inserted your code in my EA and it works perfectly ! I smilled when i see the EA execute like i wanted !!!

Very thanks very very ......

It's on backtest cause market is closed...

But there is a problem:

Ea Open correctly positions, but buy are never closed and sell immediatelly closed when opened.

Don't you want to know if your OrderClose() has failed and if it has why it has ?  why aren't you checking the return value from the OrderClose() function and reporting any errors ?  you might find that both the Buy and Sell are trying to close immediately but the Buy OrderClose() fails . . .

What are Function return values ? How do I use them ? 

 

There is no error on Journal tab.


I will place return values. Can i do that?

Close = CloseOrder(....)

if (Close < 1)

Print ("Close Failed", GetLastError())
 
Kane59:

There is no error on Journal tab.


I will place return values. Can i do that?

Close has a different meaning . . .  OrderClose() returns a bool . . . 

if ( ! OrderClose(....) )

Print ("Close Failed", GetLastError())
 
RaptorUK:

Close has a different meaning . . .  OrderClose() returns a bool . . . 


Ok ok i will do that, thanks :)
 

I inserted:

if(OrdersTotal()>0)
            { 
               for(int i=OrdersTotal()-1; i>=0; i--)
               {
                  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
                  {
                     if(OrderMagicNumber() == MagicSH && OrderOpenTime() > iTime(Symbol(), PERIOD_H1, 1))
                     {
                        if(OrderType() == OP_BUY)
                        {
                           OrderClose(OrderTicket(),LotsSH, bid, 300, CLR_NONE);
                           {
                              if(! OrderClose(OrderTicket(),LotsSH, bid, 300, CLR_NONE))
                              {
                                 Print ("Close Buy Failed", GetLastError());
                              }
                           }
                        }
                        if(OrderType() == OP_SELL)
                        {
                           OrderClose(OrderTicket(),LotsSH, ask, 300, CLR_NONE);
                           {
                              if(! OrderClose(OrderTicket(),LotsSH, ask, 300, CLR_NONE))
                              {
                                 Print ("Close Sell Failed", GetLastError());

No error writed.

 
Kane59:

I inserted:

No error writed.

You can't close the same order twice . . . 

 OrderClose(OrderTicket(),LotsSH, bid, 300, CLR_NONE);            //  first attempt to close
    {
    if(! OrderClose(OrderTicket(),LotsSH, bid, 300, CLR_NONE))       //  second attempt to close
 

I solved the problem, loop conditions weren't correctly coded...

Thanks again.

 

Hi all,

i used the code given by WHRoeder, but i see with the time that EA only take only one "#define" to be a reference for the 4 differents hours.

    #define HR0900 23400    // 9*3600
    #define HR1500 54000
    #define HR1900 68400
    #define HR2300 59800

I tried different way:

I built a arraysize with Int which are candle reference and it's the same, only one is considered no the 4 number, how can i solve it?

 
Kane59:

Ok, i inserted your code in my EA and it works perfectly ! I smilled when i see the EA execute like i wanted !!!

What did you do to break WHRoeder's code ?
 
Kane59:

 . . .  how can i solve it?

I think you need to show your code.
Reason: