Proffessor_v2_2011

Author: Copyright � 2011, MetaQuotes Software Corp.
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Movement directional index
0 Views
0 Downloads
0 Favorites
Proffessor_v2_2011
//+------------------------------------------------------------------+
//|                                           Proffessor_v1_2011.mq4 |
//|                      Copyright © 2011, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern double lot=0.01;
extern int MAX_Lines       = 5;     //ìàêñèìàëüíîå êîëëè÷åñòâî îòëîæåííûõ îðäåðîâ êàæäîãî íàïðàâëåíèÿ  
extern double klot           = 1;      //êîýôôèöèåíò óìíîæåíèÿ ëîòîâ ïðè óäàëåíèè îò öåíû  
extern double pluslot      =0.01;      //êîýôôèöèåíò äîëèâêè ëîòà ïðè óäàëåíèè îò öåíû
extern double Delta1       =30;     //ïåðâàÿ äåëüòà îò öåíû äëÿ ñòîïîâîãî îðäåðà
extern int Delta           = 30;        //ðàññòîÿíèå ìåæäó ëèìèòíûìè îðäåðàìè  
extern double ProfitClose     = 0.8;        //çàêðûâàòü âñå îðäåðà ïðè ïîëó÷åíèè ïðîôèòà(â äîëëàðàõ)  
extern double f            =40;  //ïàðàìåòð ãðàíèöû ôëåòà ïî ADX
extern double bar        = 2;   //ñäâèã ïî áàðàì ADX
extern double timeframe  = 1;  //òàéìôðåéì äëÿ èíäèêàòîðà ADX 0-òåêóùèé,1-1ìèíóòà, 2-5ìèíóò, 3-15ìèíóò, 4-30ìèíóò, 5-1÷àñ
                             //6-4÷àñà, 7-äåíü, 8-íåäåëÿ, 9-ìåñÿö
extern int magic           = 12345; 
extern int StartHour=0;       //÷àñ íà÷àëà ðàáîòû ñîâåòíèêà
extern int EndHour=24;     //÷àñ îêîí÷àíèÿ ðàáîòû ñîâåòíèêà
int init() {
      Comment("ProfessorSoft_v1_2011");
      return (0);
  
}

int deinit() {
      Comment("");
      return (0);
}

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
bool ticket;
double Lots;
int x;
bool trade=false;
trade=true;
double iflet,ibuy,isell;
int _timeframe;
if(timeframe==1)_timeframe=1;
else if(timeframe==0)_timeframe=0;
else if(timeframe==2)_timeframe=5;
else if(timeframe==3)_timeframe=15;
else if(timeframe==4)_timeframe=30;
else if(timeframe==5)_timeframe=60;
else if(timeframe==6)_timeframe=240;
else if(timeframe==7)_timeframe=1440;
else if(timeframe==8)_timeframe=10080;
else _timeframe=43200;

   if(OrdersTotal()==0 && trade==true && time()==true)
   {
   ticket=-1;
    iflet=iADX( Symbol(), _timeframe, 14, PRICE_CLOSE,MODE_MAIN, bar); 
    ibuy=iADX( Symbol(), _timeframe, 14, PRICE_CLOSE,MODE_PLUSDI, bar); 
    isell=iADX(  Symbol(), _timeframe, 14, PRICE_CLOSE,MODE_MINUSDI, bar); 
      
      if(iflet<f && ibuy>isell)
      {
               Lots=lot;
               ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",magic,0,Blue);
                if(ticket==-1)return(0);
               OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
       
                for(x=1;x<=MAX_Lines;x++)
               {
                Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                  OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-(Delta1+x*Delta)*Point,3,0,0,"",magic,0,Blue);
                  OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+x*Delta*Point,3,0,0,"",magic,0,Red);     
               }
      
      
      }
      else if(iflet<f && ibuy<isell)
      {
                  Lots=lot;
                  ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",magic,0,Red); 
                   if(ticket==-1)return(0);
                  OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                    for(x=1;x<=MAX_Lines;x++)
                  {
                     Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                     OrderSend(Symbol(),OP_BUYLIMIT,Lots,Ask-x*Delta*Point,3,0,0,"",magic,0,Blue);
                     OrderSend(Symbol(),OP_SELLLIMIT,Lots,Bid+(Delta1+x*Delta)*Point,3,0,0,"",magic,0,Red);     
                  }
      }
       else if(iflet>f && ibuy>isell)
      {
                   Lots=lot;
                   ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"",magic,0,Blue);
                    if(ticket==-1)return(0);
                   OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-Delta1*Point,3,0,0,"",magic,0,Red);
       
                    for(x=1;x<=MAX_Lines;x++)
                   {
                    Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                      OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-(Delta1+x*Delta)*Point,3,0,0,"",magic,0,Blue);
                      OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+x*Delta*Point,3,0,0,"",magic,0,Red);     
                   }
      }
       else if(iflet>f && ibuy<isell)
      {
                  Lots=lot;
                  ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"",magic,0,Red); 
                   if(ticket==-1)return(0);
                  OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+Delta1*Point,3,0,0,"",magic,0,Blue);
                    for(x=1;x<=MAX_Lines;x++)
                  {
                     Lots=NormalizeDouble(Lots*klot,2)+pluslot;
                     OrderSend(Symbol(),OP_SELLSTOP,Lots,Bid-x*Delta*Point,3,0,0,"",magic,0,Blue);
                     OrderSend(Symbol(),OP_BUYSTOP,Lots,Ask+(Delta1+x*Delta)*Point,3,0,0,"",magic,0,Red);     
                  }
      }
      else return(0);
     
   }
  
  
      
      if(OrdersTotal()>0)
    {
     Comment("Balance  ",AccountBalance(),"\nEquity  ",AccountEquity(),"\n  Profit  ",OrdersProfit());
      if(OrdersProfit()>=ProfitClose)
      {
         for (int i=OrdersTotal()-1;i>=0;i--)
         {
          //  bool error=true;
            OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
            if(OrderType()==OP_BUY) 
            {
            OrderClose(OrderTicket(),OrderLots(),Bid,3,Blue);
         //   error=false;
            }
            if(OrderType()==OP_SELL) 
            {
            OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
          //  error=false;
            }
            Sleep(1000);
            if(OrderType()>1 ) OrderDelete(OrderTicket());
         }
      }
    }
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+

   bool time()
 {
   if (StartHour<EndHour) 
      {if (Hour()>=StartHour && Hour()<EndHour) return(true); else return(false);}
   if (StartHour>EndHour) 
      {if (Hour()>=EndHour && Hour()<StartHour) return(false); else return(true);}
 }
 
double OrdersProfit()
{
   
  double rezultSymb=0;
  string SMB=Symbol();
  int i;
  for (i=OrdersTotal()-1;i>=0;i--)
   {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true)
     {
      if(OrderSymbol()!= SMB) continue;
      if(OrderType()==OP_BUY || OrderType()==OP_SELL)
       {
        rezultSymb+=OrderProfit();
       } 
     }
   }
  return(rezultSymb);


}

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---