Quote:
|
Originally Posted by Altern8
Hi codersguru,
Just a quick question. I changed the script a little, by changing the Op_SELL to OP_SELLSTOP, and works good.
Is it possible/can you add a little slice of code, that will delete the pending order after 30mins if not trade was taken?
I have attached the script.
Thankyou
-A8
|
A8,
You can set the expiration parameter in the OrderSend function for the pending order like this code:
PHP Code:
//+------------------------------------------------------------------+
//| trade"sell".mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#include <stdlib.mqh>
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//+------------------------------------------------------------------+
//| script "sell" |
//+------------------------------------------------------------------+
extern double TakeProfit = 120;
extern double StopLoss = 15;
extern double Lots = 0.1;
extern double TrailingStop = 15;
extern double PipsFor = 10;
int start()
{
int ticket;
//----
while(true)
{
datetime close_time = CurTime() + TimeMinute(30);
Alert ("This order will be closed at: " + TimeToStr(close_time));
ticket=OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-PipsFor*Point,3,Ask+StopLoss*Point,Bid-TakeProfit*Point,"sell opened",255,close_time,Red);
if(ticket<=0)
{
int error=GetLastError();
Print("Error = ",ErrorDescription(error));
if(error==134) break; // not enough money
if(error==135) RefreshRates(); // prices changed
break;
}
//---- remove break statement below and take trading for all money
else { OrderPrint(); break; }
//---- 10 seconds wait
Sleep(10000);
}
return(0); // exit
}
if(TrailingStop>0)
{
if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
{
if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
return(0);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+