script with future order

[Deleted]  

i want to run a script in specific hour

put two orders from the price in the future ( buy stop and sell stop )

how to i create the script ?

Ubzen
5300
Ubzen  

Here, try this:

//#################################################################
//#################################################################
extern double Lots=0.1;
extern int Future_Pips=20;
//#################################################################
//#################################################################
int start(){
//#################################################################
//#################################################################
int      Digit_Info= MarketInfo(Symbol(),MODE_DIGITS);
int      Stop_Info=  MarketInfo(Symbol(),MODE_STOPLEVEL);
int      Slippage=   MarketInfo(Symbol(),MODE_SPREAD);
double   Point_Info= MarketInfo(Symbol(),MODE_POINT);
//#################################################################
//#################################################################
double   Ask_Norm=NormalizeDouble(Ask,Digit_Info);
double   Bid_Norm=NormalizeDouble(Bid,Digit_Info);
//#################################################################
//#################################################################
double Pip_Multiple=Point_Info;
if(Digit_Info==3){Pip_Multiple=0.01;}
if(Digit_Info==5){Pip_Multiple=0.0001;}
//#################################################################
//#################################################################
double Future_PriceBuy=Ask_Norm+(Future_Pips*Pip_Multiple);
if(Future_PriceBuy<Ask_Norm+(Stop_Info*Point_Info)){
   Future_PriceBuy=Ask_Norm+(Stop_Info*Point_Info);
}
//----------
double Future_PriceSell=Bid_Norm-(Future_Pips*Pip_Multiple);
if(Future_PriceSell>Bid_Norm-(Stop_Info*Point_Info)){
   Future_PriceSell=Bid_Norm-(Stop_Info*Point_Info);
}
//#################################################################
//#################################################################
OrderSend(Symbol(),OP_BUYSTOP,Lots,Future_PriceBuy,
Slippage,0,0,"Gabriel_BuyStop",3,0,Green);
//----------
OrderSend(Symbol(),OP_SELLSTOP,Lots,Future_PriceSell,
Slippage,0,0,"Gabriel_SellStop",3,0,Red);
//#################################################################
//#################################################################
return(0);}
//#################################################################
//#################################################################
Files:
gabriel3.mq4  3 kb
William Roeder
25824
William Roeder  

Can't do it. pending order have an expiration time but no start time.

Have the script wait until the proper time.

Ubzen
5300
Ubzen  
WHRoeder:

Can't do it. pending order have an expiration time but no start time.

Have the script wait until the proper time.


So then, would I need to give it a continuous loop to monitor what time it is? My thinking is he could just run it at the particular hour or turn it into an ea and add the -if hour() - etc.
[Deleted]  
ubzen:

So then, would I need to give it a continuous loop to monitor what time it is? My thinking is he could just run it at the particular hour or turn it into an ea and add the -if hour() - etc.


thanks for the proffesional answer .

about the time of the running script .

i need the ask price in the future and orders are relative to the price in specific hour .

is it possible to make pending the script outside the code .so execute it in the future hour ?

Ubzen
5300
Ubzen  

Scripts are designed to be run Once. Therefore, what you're looking for is an EA. If that's the case then research datetime() functions. Just add if Hour(?) then Order_Send.

 

You may also be able to achieve this with Scripts and Infinite loops like while(0==0) then if(Hour(?)) but I have no experience with this and heard it can cause computer to freeze. Sorry I cannot create an EA for you, but you can add it yourself.

[Deleted]  
ubzen:

Scripts are designed to be run Once. Therefore, what you're looking for is an EA. If that's the case then research datetime() functions. Just add if Hour(?) then Order_Send.

You may also be able to achieve this with Scripts and Infinite loops like while(0==0) then if(Hour(?)) but I have no experience with this and heard it can cause computer to freeze. Sorry I cannot create an EA for you, but you can add it yourself.


so what is the different between the two method ?

can i use input time parameter and the code will execute only if the time match the input .

does it matter if i use ea or script ? i want the code to run only if the time is match .

Ubzen
5300
Ubzen  

gabriel3: can i use input time parameter and the code will execute only if the time match the input. Yes

The difference between the two is the EA would do it automatically. For the script, you'll have to run the script at the right time for it to do something. If you already know the time to run the script then what's the point of a time filter. Well I guess it'll protect you from running it in any other hour, I guess.

William Roeder
25824
William Roeder  
extern int when=1;
start(){
  while (Hour() != when) { // Invalid/illegal for an indicator
     sleep(60000);
     RefreshRates();
  }
   ...
[Deleted]  

i think this is better then i wrote

i wrote condition :

extern int day_ = 1 ;
extern int hour_ = 14;
extern int minute_ = 17;

if ( DayOfWeek() == day_ && Hour()== hour_ && Minute() == minute_ )

Ubzen
5300
Ubzen  
Yeah it's much better and easier on your system resources too. That's why he's the man.