trading on time basis, not tick basis... any suggestions? - page 2

 

Hi Guys

You need to use this


if(TimeSeconds(TimeCurrent()) > 40){


If you read the explanation of Seconds() in MetaEditor it says "(this value will not change within the time of the program execution). "


Also check the other quantities.

 

deymer,


The code I posted works, however, if you want to implement Ruptor's suggestion and eliminate the "Delay" variable you have to reinsert the "while" loop otherwise you are back to being dependent on the incoming ticks. And, if you reinsert the "while" loop it has to be placed AFTER the conditional-if that checks "Minute()" otherwise it too is subject to the constraint that Ruptor pointed out in the previous post.


The following code revisions work, but there are some caveats you need to be aware of:


1. MT4 cannot handle concurrent trade orders (ie the TradeContext issue) therefore you will have to implement error correction code --- check our previous thread on this last week as I provided a link for you regarding error correction code.


2. I commented out the "sell" OrderSend to avoid the TradeContext issue. The code as written will issue two buys order (sometimes). I say sometimes because after the first order is filled, the code as written waits one more tick before executing the code a second time (note this tick issue goes away when you implement error correction code) because the second order will be filled before the "break" statement is encountered. The reason the second order is not filled sometimes is because too much time lapses and the the Hour/Minute requirements are no longer valid.


3. I left the "Print" statements in so you can see how the code progresses. When you finalize your EA simply delete them, or do so even sooner if you want.


4. The print statements will give you a good idea of the timing associated with "sending" the order and when the trade server fills the order.


int MaxOrders=2;

int start(){

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

if(Hour() == 18){

if(Minute() == 21){

while(!IsStopped()){
Print("Countdown to Trade Launch (in Secs) ",40-TimeSeconds(TimeCurrent()));
if(TimeSeconds(TimeCurrent())>40){

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); need to add error correction code to avoid TradeContext error
break;
}
Sleep(1000);
}

}
}
return(0);
}