trading on time basis, not tick basis... any suggestions?

 

I'm trying to place a series of trades at a certain time, but i've noticed the trades only go through as long as there is a tick at that certain time...


is there a way to make the trades go through soley on a time basis, and not on each tick?


here's what i'm working with.... it's pretty simple.


int TradeSwitch=0;

int start()
{if(TradeSwitch==0)
{if(Hour() == 15)
{if(Minute() == 29)
{if(Seconds() > 40)
{OrderSend(Symbol(),OP_BUY,1.0,Ask,1,Ask-20*Point,Ask+30*Point,"BUYER",0,0,Green);
OrderSend(Symbol(),OP_SELL,1.0,Bid,1,Bid+20*Point,Bid-30*Point,"BUYER",0,0,Red);
TradeSwitch=1;
}
}
}
}
return(0);
}

 

Hi

Yes run EA in contiuous loop like this so it can only be stopped by removing it from chart.



2008-06-19 01:02:04


int Start{


while(!IsStopped()){


*****your code here****


Sleep(1000);

}

}

 
Ruptor:

Hi

Yes run EA in contiuous loop like this so it can only be stopped by removing it from chart.



2008-06-19 01:02:04


int Start{


while(!IsStopped()){


*****your code here****


Sleep(1000);

}

}

i copied and pasted your code, and copy and pasted my code where you told me... and it came up with all kinds of errors when i compiled... could you elaborate on what the code is supposed to look like?

 

No errors with this


 
Ruptor:

No errors with this


seems to be working, but can't test it until market hours open again.


i appreciate your help with this

 

deymer,


Ruptor has done a nice job of setting you up with code for launching trades independent of ticks.


Last week when we worked on this your initial question morphed from a desire to launch 40 trades in a short period of time to a single trade. In anticipation that you may want to launch more than one trade once the time based criteria has been met, I offer the following:


int RunCounter=0;
int MaxOrders=1;

int start(){

if(RunCounter==1) return(0);
RunCounter=1;
while(!IsStopped()){

if(OrdersTotal()==MaxOrders) break;

if(Hour() == 15){
if(Minute() == 29){
if(Seconds() > 40){
OrderSend(Symbol(),OP_BUY,1.0,Ask,1,Ask-20*Point,Ask+30*Point,"BUYER",0,0,Green);
OrderSend(Symbol(),OP_SELL,1.0,Bid,1,Bid+20*Point,Bid-30*Point,"BUYER",0,0,Red);
}
}
}
Sleep(1000);
}
return(0);
}


The variable "MaxOrders" allows you to launch more than one trade by simply changing the value of this variable when the precscribed time criteria has been met.

I added the variable "RunCounter" to prevent trade launch series from occurring everyday at the same time. By setting the variable
"RunCounter" at "1", your EA will run one time on the day you launch the EA and issue "MaxOrders" trades at the prescribed time independently of the ticks.

Cheers
 
FXtrader2008:

deymer,


Ruptor has done a nice job of setting you up with code for launching trades independent of ticks.


Last week when we worked on this your initial question morphed from a desire to launch 40 trades in a short period of time to a single trade. In anticipation that you may want to launch more than one trade once the time based criteria has been met, I offer the following:



thank you again, good to hear from you.


what i did, in my own words, is went from a shotgun approach (40 trades) to a sniper approach (10 trades).


(that's from 8 trades per chart... 5 charts... to 2 trades per chart)


it's a simple concept, the news comes out at 15:30, and i'm trying to place the trades about 20 seconds before that time, and i don't want to rely on the tick factor to place the trades. i think these strategies will work, i'm just hoping it will not flood the server or anything... i'll find out more when trading begins on sunday, but again, i really appreciate your help with this guys


cheers

 

Hello deymer

fwiw, your trades are shown sequentially and may not work as desired, especially with I believe you are suggesting 5 charts/5 EAs?

Remember, is only one trade thread for the Client Terminal. eg, EAs must know that they potentially have access to this one thread available to place trade, else ERR_TRADE_CONTEXT_BUSY manifests.

Refs: IsTradeContextBusy(), IsTradeAllowed()

hth

 
fbj:

Hello deymer

fwiw, your trades are shown sequentially and may not work as desired, especially with I believe you are suggesting 5 charts/5 EAs?

Remember, is only one trade thread for the Client Terminal. eg, EAs must know that they potentially have access to this one thread available to place trade, else ERR_TRADE_CONTEXT_BUSY manifests.

Refs: IsTradeContextBusy(), IsTradeAllowed()

hth

ok, so, i tested it out now that trading hours started, and i noticed that it doesn't work when the seconds parameter is in the code, but when i remove it, it works just fine.


any suggestions?

 

deymer,


I think the problem is two fold:


1) the statement Seconds() returns the value of the last known "server"time, hence since the the market is very slow right now there may be a 20 second gap between the >40 and the end of the minute and by the time the end of the minute arrives the Minute() criteria is no longer valid.


2) I think you have to use the internal computer clock for the last 40 seconds other wise you are being constrained by the tick time.


Anyone else have comments?

 
deymer,

I got the following code to work. Apparently MQL4 is unable to tell time once it is placed in a "while" loop, because when I peppered the previous code with print statements
it was unable to printout the new minutes as time marched forward. It kept printing out the same time. Therefore I eliminated the "while" loop and inserted a "Delay" variable.

The value of the "Delay" variable is calculated approximately 40 seconds before the time you want to launch the trades. For example, if the first tick occurs 5 seconds after the
hour and minute criteria are met, the delay will be 35 seconds. The Sleep statement runs on the internal computer clock and is independent of tick time once it is called.

My demo broker is an American broker. It appears they will not allow a simultaneous buy order and sell order to be active at the same time because the sell order did not launch,
and I never checked to see what the error number was.

Set the hour and minute variables to one minute before the news breaks, and let the "Delay" code take care of the rest.

Amended post: Perhaps the reason the sell order did not launch is because I had the MaxOrders variable set at "1", and I should have had it set at "2"

int MaxOrders=1;
int Delay;

int start(){


if(OrdersTotal()==MaxOrders) return(0);

if(Hour() == 8){

if(Minute() == 56){

Delay=40-Seconds();
Print("Delay = ",Delay);
Sleep(Delay*1000);
Print("Send Order");
OrderSend(Symbol(),OP_BUY,0.1,Ask,1,Ask-20*Point,Ask+30*Point,"BUYER",0,0,Green);
OrderSend(Symbol(),OP_SELL,0.1,Bid,1,Bid+20*Point,Bid-30*Point,"BUYER",0,0,Red);
}
}
return(0);
}



Reason: