//+------------------------------------------------------------------+
//|                                                send_buy&sell.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
#property show_inputs
#property strict

//---- Parametres Externes
input bool      EcnBroker      = true;   
extern double   BuyLots        = 0.01;
extern int      BuyStopLoss    = 20;
extern int      BuyTakeProfit  = 20;
extern double   SellLots       = 0.01;
extern int      SellStopLoss   = 20; 
extern int      SellTakeProfit = 20;


bool dummyResult;

//+------------------------------------------------------------------+
//| script "send pending order with expiration data"                 |
//+------------------------------------------------------------------+
void OnStart()
{
   int    bticket,sticket;
   //double point;
//----
   //point=MarketInfo(Symbol(),MODE_POINT);
  // expiration=CurTime()+PERIOD_D1*60;
//----
   while(true)
   {
    if (!EcnBroker)
     
         bticket = OrderSend(_Symbol,OP_SELL,SellLots,Bid,0,Bid+SellStopLoss*_Point*pow(10,_Digits%2),Bid-SellTakeProfit*_Point*pow(10,_Digits%2),"SELL",NULL,0,clrRed);
    else bticket = OrderSend(_Symbol,OP_SELL,SellLots,Bid,0,0,0,"SELL",NULL,0,clrRed);
    
    if(EcnBroker && bticket>-1)
    {
       dummyResult = OrderModify(bticket,OrderOpenPrice(),Bid+SellStopLoss*_Point*pow(10,_Digits%2),Bid-SellTakeProfit*_Point*pow(10,_Digits%2),0,clrRed);
    }
      if(bticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",bticket); break; }
      //---- 10 seconds wait
      Sleep(1000000);
     }
     while(true)
     {
      if (!EcnBroker)
           sticket = OrderSend(_Symbol,OP_BUY,BuyLots,Ask,0,Ask-BuyStopLoss*_Point*pow(10,_Digits%2),Ask+BuyTakeProfit*_Point*pow(10,_Digits%2),"BUY",NULL,0,clrLime);
      else sticket = OrderSend(_Symbol,OP_BUY,BuyLots,Ask,0,0,0,"BUY",NULL,0,clrLime);
      
      if(EcnBroker && sticket>-1) 
      {
        dummyResult = OrderModify(sticket,OrderOpenPrice(),Ask-BuyStopLoss*_Point*pow(10,_Digits%2),Ask+BuyTakeProfit*_Point*pow(10,_Digits%2),0,clrLime);
      }
      if(sticket<=0) Print("Error = ",GetLastError());
      else { Print("ticket = ",sticket); break; }
      //---- 10 seconds wait
      Sleep(1000000);
     }
//----
   //return(0);
  }
//+------------------------------------------------------------------+