can someone help with this? - page 2

 
onewithzachy:

1. ...

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.

Once you get into the default parameter region you can just stop at any point. In other words OrderSend can be sent with 7, 8, 9, 10 or 11 parameters. The remaining parameters will be the default values. The only thing you must be sure of is that the parameters are given in exactly the correct order. You can't just omit parameters at random. The omission has to start from the "right hand end" of the list if you like. I hope I have explained this adequately.
 
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);

Yes. You cannot set a SELLSTOP at the current Bid price.

You are omitting parameters at random from the OrderSend. You can stop putting in parameters at any time in sequence. You can't stop for a while then start up again. If you need to go up to the expiration time you need to supply all the earlier parameters. There is no need to supply later parameters.

You datetime constant is badly formed. Should be like this

https://docs.mql4.com/basis/types/datetime

These are absolute times and not what you are looking for. I assume you want to expire the order at 12:00 on the same day as the order was placed. You are going to have to put some more code in there to make that happen. It won't happen as easily as you hope.

 
To find out about order types such as SELL STOP orders use the Help in the MetaTrader, Help | Help Topics | Contents | Trading | Order Types. There is an excellent picture in there of the four pending order types.
 
dabbler:
These are absolute times and not what you are looking for. I assume you want to expire the order at 12:00 on the same day as the order was placed.
#define HR1200 43200 // 12 * 3600
#define HR2400 86400
datetime now = TimeCurrent(),
         bod = now - now % HR2400, // Midnight
         exp = bod + HR1200;       // Noon
if (exp < now) exp += HR2400;      // Expire tomorrow
 
WHRoeder:

Ah yes, a neat piece of code :-)

I might write it as ...

#define HR1200 43200 // 12 * 60 * 60
#define HR2400 86400 // 24 * 60 * 60; the number of seconds in a day

datetime now = TimeCurrent();
datetime bod = now - (now % HR2400); // Midnight, where "bod" means Beginning Of Day. Note that (now % HR2400) is the number of seconds past midnight
datetime exp = bod + HR1200;         // Noon
if( exp < now )
    exp += HR2400;      // Expire tomorrow if we are already past the expiration time today
 

Hi raptor,

sorry for the late reply.

what does SRC means?

anyway

1) at 6am, it looks at the past 5 bars to find the max and min

2) I am looking at the H1 chart, sorry please ignore the comments

3) there is a {, but also a }. i thought it will be good to put everything inside a {}

Thanks.

 

Hi WHRoeder, dabbler,

apologies, i changed to

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-20*Point,0, maxvalue+ (SL)*Point, minvalue -(maxvalue-minvalue),0,0,(TimeCurrent() + 5*60*60),CLR_NONE);

but still, it seem to put pending orders at each of the next 6 bars. which is not what i want.

any suggestion? Thanks.

 
yuan83:

Hi raptor,

sorry for the late reply.

1. what does SRC means?

anyway

2) at 6am, it looks at the past 5 bars to find the max and min

3) I am looking at the H1 chart, sorry please ignore the comments

4) there is a {, but also a }. i thought it will be good to put everything inside a {}

Thanks.

1. Please use this to post code . . . it makes it easier to read.

2. No at 6am it does the first line, at any other time it does the other lines . . .

4. Use braces { } when you need to . . . a Function, a loop, a bunch of code to be executed as a result of an if test . . . this is related to 2.

 
yuan83:

3) there is a {, but also a }. i thought it will be good to put everything inside a {}

You do not put braces (curly brackets) in code for the reason "I thought it will be good".

This code ..

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);

is read by the compiler as

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);

When the if statement is true the following line is executed. That is not what you want. ALL the code you want to be executed as a result of the if statement being true is put into a BLOCK defined by the braces.

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);
}

Now this can get a bit confusing since there are many ways of indenting the text and positioning the braces. BUT the compiler doesn't care. You could (and some people do) format the same code in weird ways.

if (Hour() ==6 && Minute()==0 && Seconds() ==0)  // this is bizarre but still works
                                                                           {
   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);                                           }

The compiler doesn't care. It is us hoomins that have to read and understand the code.

Reason: