can someone help with this?

 

I wanted to code, when time = 6am,

I coded it as "if (Time[]= datetime(6:00))" but it gives tons of error.

If i add in a ( in front, the errors reduced to '(' - variable expected.

to me, the ( and ) are balanced; but why do I keep having such errors?

hope someone can help. Thanks.!

 

Time[x] is the time of a bar number x on the current chart, perhaps you mean current time is 6 am ? if you do then you can use TimeCurrent() this will only be equal to 6:00 for 60 seconds . . .

datetime is a variable type not a function so () cannot follow datetime . . . which 6am do you want ? today ? yesterday ? last Wednesday ?

 

How about ...

if( Hour()==6 && Minute()==0 ){
}
 

Hi dabbler, your suggestion works fine. Thanks. However, may i ask, why does the program give so much error, just because my logic is wrong? the logic error and the error with the '(' ')' does not seem related.

Hi Raptor, yup i meant if the time reaches 6am everyday, check for something; it's only at that one instance, I think your logic will work too?

 

further to the previous qn, is there something wrong with my expiration time for the below?

OrderSend (Symbol(),OP_SELLSTOP, lots, Bid,0, max+ (SL)*Point, Bid-(max-min),12:00,CLR_NONE);

I ran it and I have error code of 4062 - i see nothing suspicious except the tme.

 
yuan83:

further to the previous qn, is there something wrong with my expiration time for the below?

OrderSend (Symbol(),OP_SELLSTOP, lots, Bid,0, max+ (SL)*Point, Bid-(max-min),12:00,CLR_NONE);

I ran it and I have error code of 4062 - i see nothing suspicious except the tme.

1. Expiration time should be the future time from the time you send the order, like 3 days from now or 5 minutes from now. And remember that datetime (click that) is calculated in second.You also should check whether your broker allow the expiration time, otherwise your order may not get opened or get opened but will never expire.

2. You also have error 4062 - which is 'string parameter expected'. That happen because OrderSend() function has 11 input parameters (4 of them is default) and yet you only write 9 of them. Either write all of its 11 parameter of just (11 - 4) 7 of them.

3. You also try to send pending order of OP_SELLSTOP but use Bid price. That will be immediately opened as sell by broker. The price of sellstop should be lower than Bid and lower than MarketInfo's (click that) MODE_STOPLEVEL and MODE_FREEZELEVEL.

So the whole code of yours can be written like this.

OrderSend (
           Symbol(),                   // first parameters
           OP_SELLSTOP, 
           lots, 
           Bid - 100*Point,            // sellstop price 100 Point below Bid
           0, 
           max+ (SL)*Point, 
           Bid-(max-min), 
           "my comment",               // first default parameter. this is your error 4062 which what your MetaEditor expected
           0,
           (TimeCurrent() + 12*60*60), // expired 12 hours from now
           CLR_NONE                    // 11th parameter which also 4th default parameter.
           );

:D

 

zachy, thanks! didn't realise i missed that numbers of parameters, as i edited from another EA. thanks for the advices

 
dabbler:

How about ...


Hi Dabbler,

with regards tto your suggestion to use "if( Hour()==6 && Minute()==0 ){"

can i confirm that the EA will loop in for 1 min until the times goes to 6:01?? so if i only want to use it once at 6:00, i shoud indicate the seconds too?

Thanks.

 
yuan83:


Hi Dabbler,

with regards tto your suggestion to use "if( Hour()==6 && Minute()==0 ){"

can i confirm that the EA will loop in for 1 min until the times goes to 6:01?? so if i only want to use it once at 6:00, i shoud indicate the seconds too?

Thanks.

No, that is a very bad idea . . . you can't guarantee when a tick arrives, sometimes there can be no tick for a minute or more . . . use a bool type variable to record that you have done what you want to do at 6am . . then at 7 am reset it . . .
 

hmm very weird, i m just trying to test a simple breakout trade. why is it, instead of opening a pending order based on the max of previous 5 bars, is it opening a pending every hour.

hmm am i missing a 'reset' somewhere

Time[0]) return(0); Time0 = Time[0]; //every 5 min//

{ if (Hour() ==6 && Minute()==0 && Seconds() ==0)

max= iHighest(NULL,0,MODE_HIGH,5,1);
min = iLowest(NULL,0,MODE_LOW,5,1);
maxvalue = iHigh (NULL,0,max);
minvalue = iLow (NULL,0,min);


if(LOS==-1)
OrderSend (Symbol(),OP_SELLSTOP, lots, minvalue,0, maxvalue+ (SL)*Point, minvalue -(maxvalue-minvalue),0,0,(TimeCurrent() + 5*60*60),CLR_NONE);

 

Please use the SRC button . . .

{ if (Hour() ==6 && Minute()==0 && Seconds() ==0)    //  if at 6:00:00  do what ?

max= iHighest(NULL,0,MODE_HIGH,5,1);  //  do this line 

min = iLowest(NULL,0,MODE_LOW,5,1);
maxvalue = iHigh (NULL,0,max);
minvalue = iLow (NULL,0,min);


if(LOS==-1)
OrderSend (Symbol(),OP_SELLSTOP, lots, minvalue,0, maxvalue+ (SL)*Point, minvalue -(maxvalue-minvalue),0,0,(TimeCurrent() + 5*60*60),CLR_NONE);

what is the opening { for on the first line ?

Are you running this on a H1 chart or a M5 chart ?

Reason: