Open trade in the last second, is it possible?

Back to topics list  | 1 2 To post a new topic, please log in or register
avatar
735
honest_knave 2015.02.05 16:32 #
 

Having played around with this today, there is another problem with lack of synchronization between the local clock and broker.

Gooly's mod is definitely better.

avatar
16
gviali 2015.02.06 04:08 #
 
Thanks a lot you both, guys!
avatar
16
gviali 2015.02.07 01:23 #
 

So gooly and honest_knave, i've tried to put it all together, but guess I didn't succeded..

 I know I have to study further more, but i'm trying, and this is why i'm here, if I already knew everything I wouldn't be asking for help, so, again, thank you guys for you time and patience..

Here is what i gor so far:

#property strict
#define magicnumber 123

input double lots = 1; // Lot:
input int sleep = 30000; // Sleep, in milliseconds:

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }

void OnTick()
  {
   if ( IsNewBar ) 
      {
         int tmeLeft = PeriodSeconds() - 1 - (TimeCurrent()-Time[0]);
         EventSetTimer(tmeLeft);
      }
  }
  
void OnTimer()
  {
      
      int order;
      double customindarrow0 = iCustom(Symbol(),0,"cia",0,0);
      double customindarrow1 = iCustom(Symbol(),0,"cia1",1,0);
      
      if(customindarrow0!=0.0)
         {
            order=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,"custom buy arrow",magicnumber,0,Blue);
            Sleep(sleep);
            if(order==0)
               {
                  Print("Error Opening Buy Order: ",GetLastError());
               }
            else if(order>0)
               {
                  Print("Buy Order Opened");
               }
         }
      if(customindarrow1=!0.0)
         {
            order=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,"custom sell arrow",magicnumber,0,Red);
            Sleep(sleep);
            if(order==0)
               {
                  Print("Error Opening Sell Order: ",GetLastError());
               }
            else if(order>0)
               {
                  Print("Sell Order Opened");
               }
         }
  
  
  EventKillTimer();
  }    
  

 The objective is to open order in the 59th second when there is an arrow of a custom indicator.

Compiling this i got the following errors: 

'IsNewBar' - undeclared identifier      EA.mq4  25      9
possible loss of data due to type conversion    EA.mq4  27      22
expression not boolean  EA.mq4  51      25
avatar
735
honest_knave 2015.02.07 09:29 #
 

Hello gviali,

The first problem is you haven't created any code to check for a new bar (Gooly was using pseudo code).

The second problem is because TimeCurrent() and Time[0] are datetime, whereas tmeLeft is int.

The third problem was a typo.

#property strict
#define magicnumber 123

input double lots=1; // Lot:
input int sleep=30000; // Sleep, in milliseconds:

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }

void OnTick()
  {
   static datetime LastBar=0;
   if(Time[0]!=LastBar)
     {
      LastBar=Time[0];
      int tmeLeft=PeriodSeconds()-1 -(int)(TimeCurrent()-Time[0]);
      EventSetTimer(tmeLeft);
     }
  }

void OnTimer()
  {
   int order;
   double customindarrow0 = iCustom(Symbol(),0,"cia",0,0);
   double customindarrow1 = iCustom(Symbol(),0,"cia1",1,0);

   if(customindarrow0!=0.0)
     {
      order=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,"custom buy arrow",magicnumber,0,Blue);
      Sleep(sleep);
      if(order==0)
        {
         Print("Error Opening Buy Order: ",GetLastError());
        }
      else if(order>0)
        {
         Print("Buy Order Opened");
        }
     }
   if(customindarrow1!=0.0)
     {
      order=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,"custom sell arrow",magicnumber,0,Red);
      Sleep(sleep);
      if(order==0)
        {
         Print("Error Opening Sell Order: ",GetLastError());
        }
      else if(order>0)
        {
         Print("Sell Order Opened");
        }
     }
   EventKillTimer();
  }

 

avatar
16
gviali 2015.02.09 07:28 #
 

It's working fine! A little delay some times, got some trades opened at 3 seconds after, but that must be due to my poor internet connection.

I just had to take off the Sleep function, it was making the EA open position as soon as the sleep time was over. 

 Thanks a lot for your help guys, I really apreciated that. 

avatar
16
gviali 2015.02.27 20:39 #
 

Hello guys, i toth it would be good to bring back alive this topic.

I'm having a situation with this code, he is exactly as its written above, except for Sleep function.

So, i'm watching it opens the orders normally when the arrow indicator plots it's arrow, but sometimes it doesnt open the position according to the indicator arrow. It is missing some entries, as if the ea haven't seen the arrow.

I wonder what is making this error, the GetLastError() function doesnt bring back any error, is as if the arrow haven't existed. 

Anyone have a guest about what this could be?

Thanks in advance. 

Back to topics list   | 1 2  

To add comments, please log in or register