Author: Copyright � 2011, Verdi
Orders Execution
It automatically opens orders when conditions are reached
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
Net
//+-----------------------------------------------------------------------+
//|                                                               Net.mq4 |
//|Äëÿ ñòðàòåãèè ðàáîòû ñåòêîé îòëîæåííûõ limit-îðäåðîâ.                  |
//|Âûñòàâëåíèå ïàðàìåòðà Lot èä¸ò ïî àðèôìåòè÷åñêîé ïðîãðåññèè.           |
//|Ïîñëå çàêðûòèÿ ëþáîãî îðäåðà ðåêîìåíäóåòñÿ çàâåðøèòü îñòàâøèåñÿ ñäåëêè |
//|è ïåðåóñòàíîâèòü âñþ ñåòü.                                             |
//+-----------------------------------------------------------------------+
#property copyright "Copyright © 2011, Verdi"
#property link      "nemo811@mail.ru"
#property show_inputs
//--------------------------------------------------------------------
extern int     delta       = 20;     //øàã ñåòêè
extern int     MaxOrders   = 7;      //êîë-âî limit-îðäåðîâ ñåòêè
extern int     takeprofit  = 20;     //óðîâåíü âûñòàâëåíèÿ TP, åñëè 0, òî TP íå âûñòàâëÿåòñÿ               
extern int     zero_tp     = 1;      //êîýôôèöèåíò ðàñ÷¸òà takeprofit äëÿ âûõîäà â îáùèé ïðîôèò, åñëè 0, òî takeprofit ïðèìåò ñòàíäàðòíîå çàäàííîå çíà÷åíèå
extern int     stoploss    = 0;      //óðîâåíü âûñòàâëåíèÿ SL, åñëè 0, òî SL íå âûñòàâëÿåòñÿ
extern int     Magic       = 0;      //óíèêàëüíûé íîìåð îðäåðîâ ñåòêè 
extern bool    BUY         = false;  //îòêðûòü ñäåëêó BUY è ïîñòàâèòü ñåòêó BUY LIMIT
extern bool    SELL        = false;  //îòêðûòü ñäåëêó SELL è ïîñòàâèòü ñåòêó SELL LIMIT
extern double  Lot         = 0.1;    //îáú¸ì îòêðûâàåìîé ñäåëêè è ïåðâîãî limit-îðäåðà
//--------------------------------------------------------------------
double SL,TP,Price;
//--------------------------------------------------------------------
int start()
{
   for (int x=1; x<=1; x++)
   {
      if (BUY)
      {
         if (takeprofit!=0) TP  = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
         if (stoploss!=0)   SL  = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0;     
         OPENORDER ("Buy",Price,SL,TP,x);
      }
      if (SELL)
      {  
         if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP=0;
         if (stoploss!=0)   SL = NormalizeDouble(Bid + stoploss*Point,Digits);  else SL=0;              
         OPENORDER ("Sell",Price,SL,TP,x);
      }
   }
   for (int i=1; i<=MaxOrders; i++)
   {
      if (BUY)
      {
         Price = NormalizeDouble(Ask-delta*i*Point,Digits);
         if (takeprofit!=0) TP  = NormalizeDouble(Price + (takeprofit + delta*i*zero_tp/3)*Point,Digits); else TP=0;
         if (stoploss!=0)   SL  = NormalizeDouble(Price - stoploss*Point,Digits); else SL=0;     
         OPENORDER ("Buy Limit",Price,SL,TP,i);
      }
      if (SELL)
      {  
         Price = NormalizeDouble(Bid+delta*i*Point,Digits);
         if (takeprofit!=0) TP = NormalizeDouble(Price - (takeprofit + delta*i*zero_tp/3)*Point,Digits); else TP=0;
         if (stoploss!=0)   SL = NormalizeDouble(Price + stoploss*Point,Digits);  else SL=0;              
         OPENORDER ("Sell Limit",Price,SL,TP,i);
      }
   }
return(0);
}
//--------------------------------------------------------------------
void OPENORDER(string ord,double Price,double SL,double TP,int i)
{
   int ticket = -1;
   int err;
   while (ticket<0)
   {
      if (ord=="Buy") ticket=OrderSend(Symbol(),OP_BUY, Lot,NormalizeDouble(Ask,Digits),3,SL,TP,"Magic_" + Magic,Magic,0);
      if (ord=="Sell") ticket=OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),3,SL,TP,"Magic_" + Magic,Magic,0);
      if (ord=="Buy Limit") ticket=OrderSend(Symbol(),OP_BUYLIMIT, Lot*i,Price,3,SL,TP,StringConcatenate("¹"+i,"  Magic_" + Magic),Magic,0);
      if (ord=="Sell Limit") ticket=OrderSend(Symbol(),OP_SELLLIMIT,Lot*i,Price,3,SL,TP,StringConcatenate("¹"+i,"  Magic_" + Magic),Magic,0);
      Message(Magic);
      if (ticket==-1)
      {  
         ShowERROR();
         err++;Sleep(2000);RefreshRates();
      }
      if (ticket!=-1 || err >10) return;
   }
return;
}                  
//--------------------------------------------------------------------
void Message(string Magic) {
  Comment("Magic_" + Magic);
  Print("Magic_" + Magic);
}                                      
//--------------------------------------------------------------------
void ShowERROR()
{
   int err=GetLastError();
   switch ( err )
   {                  
      case 1:   return;
      case 2:   Alert("Íåò ñâÿçè ñ òîðãîâûì ñåðâåðîì ",Symbol());return;
      case 3:   Alert("Error íåïðàâèëüíûå ïàðàìåòðû ",Symbol());return;
      case 130: Alert("Error áëèçêèå ñòîïû   Ticket ",Symbol());return;
      case 134: Alert("Íåäîñòàòî÷íî äåíåã   ",Symbol());return;
      case 146: Alert("Error Ïîäñèñòåìà òîðãîâëè çàíÿòà ",Symbol());return;
      case 129: Alert("Error Íåïðàâèëüíàÿ öåíà ",Symbol());return;
      case 131: Alert("Error Íåïðàâèëüíûé îáúåì ",Symbol());return;
      case 4200:Alert("Error Îáúåêò óæå ñóùåñòâóåò ",Symbol());return;
      default:  Alert("Error  " ,err," ",Symbol());return;
   }
}
//--------------------------------------------------------------------

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 ---