Proboy_zIG_demo





//+------------------------------------------------------------------+
//|                                                   Ïðîáîé zIG.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


extern int     TP             = 10; 
extern int     SL             = 20;
extern int     HourLife       = 24;    //Âðåìÿ æèçíè "îòëîæåííîãî îðäåðà"
extern bool    MoveOrder      = True;  //Äâèãàòü ëè "îòëîæåííûå îðäåðà"
extern int     deltaPoint     = 5;     //Øàã èçìåíåíèÿ "îòëîæåííîãî îðäåðà"
extern string  NameIndicator  = "Dex-zIG_DBO_v0.3_150107";
extern int     MAGIC          = 2007011201;

int    clModifyBuy, clModifySell;
int    SleepOk,Slippage,SleepErr;
#include <stdlib.mqh>
#include <stderror.mqh>
#include <TradeLib.mqh>
#include <a-SimpleTrailing.mqh>

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   int CountOrder;
   double Buy_zIG, Sell_zIG, Med_zIG;
   double FirstPrice, SecondPrice, FirstTP, SecondTP, FirstSL, SecondSL;
   double OrderPrice;
   int FirstType, SecondType;
//----
   CountOrder = OrdersCount(OP_BUYSTOP) + OrdersCount(OP_SELLSTOP) + OrdersCount(OP_BUY) + OrdersCount(OP_SELL);

   //Êðàñíûé - Sell, Ñèíèé - Buy
   Buy_zIG = iCustom(Symbol(), 0, NameIndicator, 2, 0);
   Sell_zIG = iCustom(Symbol(), 0, NameIndicator, 1, 0);

   if(CountOrder == 0)
   {
    Print("Sell_zIG = ", Sell_zIG, " Buy_zIG = ", Buy_zIG);
    //if(Med_zIG < Sell_zIG || Med_zIG > Buy_zIG) return(0);
    if(Sell_zIG > Buy_zIG) return(0);
    //Íåò íè îäíîãî îðäåðà => âûñòàâëÿåì "Ñòîïû"
    FirstType = OP_BUYSTOP;
    FirstPrice = NormalizeDouble(Buy_zIG, Digits);
    FirstSL = NormalizeDouble(FirstPrice - SL * Point, Digits);
    SecondPrice = NormalizeDouble(Sell_zIG, Digits);
    if(TP == 0)
    {
     FirstTP = 0;
     SecondTP = 0;
    }
    else
    {
     FirstTP = NormalizeDouble(FirstPrice + TP * Point, Digits);
     SecondTP = NormalizeDouble(SecondPrice - TP * Point, Digits);
    }
    SecondType = OP_SELLSTOP;
    SecondSL = NormalizeDouble(SecondPrice + SL * Point, Digits);
    Order(FirstType, Symbol(), 0.1,  FirstPrice, 
                                      FirstSL, 
                                      FirstTP, MAGIC, "Ïðîáîé zIG", TimeCurrent() + HourLife * 60 * 60);
    Order(SecondType, Symbol(), 0.1, SecondPrice, 
                                      SecondSL, 
                                      SecondTP, MAGIC, "Ïðîáîé zIG", TimeCurrent() + HourLife * 60 * 60);
    
    return(0);
   }
   if(CountOrder > 0)
   {
    //Åñòü õîòÿ áû îäèí îðäåð
    CountOrder = OrdersCount(OP_BUY) + OrdersCount(OP_SELL);
    if(CountOrder > 0)
    {
     //Îòêðûëñÿ ðûíî÷íûé îðäåð => Òðåéëèì
     if(UseTrailing)
       TrailingPositions();
    }
    
    CountOrder = OrdersCount(OP_BUYSTOP) + OrdersCount(OP_SELLSTOP);
    if(CountOrder > 0 && MoveOrder)
    {
     //Åñòü îòëîæåííûå îðäåðà È ñòîèò ïðèçíàê - äâèãàòü ñòîïû
     int orders = 0;
     int cnt = OrdersTotal();
     for (int i=0; i<cnt; i++) 
     {
      if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != MAGIC) continue;
      if (OrderType() == OP_BUYSTOP)
      {
       //Ïîéìàëè îðäåð BUYSTOP
       FirstPrice = NormalizeDouble(Buy_zIG, Digits);
       FirstSL = NormalizeDouble(FirstPrice - SL * Point, Digits);
       if(TP == 0)
       {
        FirstTP = 0;
       }
       else
       {
        FirstTP = NormalizeDouble(FirstPrice + TP * Point, Digits);
       }
       if(
          MathAbs(NormalizeDouble(OrderOpenPrice(), Digits) - FirstPrice) >= deltaPoint * Point
         )
       {
        OrderModify(OrderTicket(), FirstPrice, FirstSL, FirstTP, OrderExpiration());
       }
      }
      if (OrderType() == OP_SELLSTOP)
      {
       //Ïîéìàëè îðäåð SELLSTOP
       FirstPrice = NormalizeDouble(Sell_zIG, Digits);
       FirstSL = NormalizeDouble(FirstPrice + SL * Point, Digits);
       if(TP == 0)
       {
        FirstTP = 0;
       }
       else
       {
        FirstTP = NormalizeDouble(FirstPrice - TP * Point, Digits);
       }
       if(
          MathAbs(NormalizeDouble(OrderOpenPrice(), Digits) - FirstPrice) >= deltaPoint * Point
         )
       {
        OrderModify(OrderTicket(), FirstPrice, FirstSL, FirstTP, OrderExpiration());
       }
      }
     }
    }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:



Indicator Curves created:


Indicators Used:




Custom Indicators Used:
NameIndicator

Order Management characteristics:
Checks for the total of open orders

It can change open orders parameters, due to possible stepping strategy

Other Features: