ShadowTrader 1.2_D1_EURUSD





//+------------------------------------------------------------------+
//|                                                   ShadowTrader   |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//|                                                             v1.2 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

extern double Lots     = 0.01;
extern int TakeProfit  =   90;
extern int StopLoss    =   30;
extern int hour        =   12; // 12 is for GMT+2 The time, after which the order will be closed
extern int limit       =    2; // Level of setting the postponed order

static int magicNumber = 23456;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
   return(0);
}

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
   return(0);
}

static datetime prev_min = D'1.1.1'; // Previous minimum
static datetime prev_max = D'1.1.1'; // Previous maximum

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   double iFractals_up = 0; // Maximum
   double iFractals_lo = 0; // Minimum
   double TP = 0, SL = 0, price = 0;
   bool order_buy  = false,
        order_sell = false;

   // If there are 2 open orders - no longer it is discovered
   for (int cnt = 0; cnt < OrdersTotal(); cnt++)
   {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES) == false)
         continue;
         
      if ((OrderSymbol() != Symbol()) || (OrderMagicNumber() != magicNumber))
         continue;

      if ((OrderType() != OP_SELL) && (OrderType() != OP_BUY))
         continue;

      switch (OrderType())
      {
         case OP_BUY :
         {
            price     = Bid; 
            order_buy = true;
         } break;
         
         case OP_SELL: 
         { 
            price      = Ask; 
            order_sell = true;
         } break;
      }
            
      // The time elapsed...
      if ((CurTime() - OrderOpenTime()) > hour * 3600)
      {
         OrderClose(OrderTicket(), OrderLots(), price, 3, Red);
         return (0);
      }
   }
   
   // Free Margin remainder
   if (AccountFreeMargin() < 1000 * Lots)
      return (0);
   
   for (int i = 0; i < Bars; i++)
   {
     iFractals_up = iFractals(NULL, 0, MODE_UPPER, i);
     iFractals_lo = iFractals(NULL, 0, MODE_LOWER, i);

      if ((iFractals_up != 0) || (iFractals_lo != 0))
         break;
   }

   // New maximum ?
   if ((iFractals_up != 0) && (Time[i] != prev_max) && (i < 3) && (order_buy == false))
   {
      prev_max = Time[i];
      
      // Let us open the postponed order.
      price = High[i] + limit * Point;
      SL    = price - StopLoss   * Point;
      TP    = price + TakeProfit * Point;      
      OrderSend(Symbol(), OP_BUYSTOP, Lots, price, 3, SL, TP, "OP_BUYSTOP", magicNumber, 0, Blue);
      
      Sleep(10000);
      
      // Let us open the basic order.
      SL = Bid + StopLoss   * Point;
      TP = Bid - TakeProfit * Point;
      OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, price, TP, "OP_SELL", magicNumber, 0, Blue);
   }

   // New minimum ?
   if ((iFractals_lo != 0) && (Time[i] != prev_min) && (i < 3) && (order_sell == false))
   {
      prev_min = Time[i];

      // Let us open the postponed order.
      price = Low[i] - limit * Point;
      SL    = price + StopLoss   * Point;
      TP    = price - TakeProfit * Point;
      OrderSend(Symbol(), OP_SELLSTOP, Lots, price, 3, SL, TP, "OP_SELLSTOP", magicNumber, 0, Blue);      

      Sleep(10000);

      SL = Ask - StopLoss   * Point;
      TP = Ask + TakeProfit * Point;
      OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, price, TP, "OP_BUY", magicNumber, 0, Yellow);
   }
   return(0);
}
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains the highest prices of each bar
Series array that contains the lowest prices of each bar


Indicator Curves created:


Indicators Used:

Fractals


Custom Indicators Used:

Order Management characteristics:
Checks for the total of open orders

It Closes Orders by itself
It automatically opens orders when conditions are reached

Other Features: