cm_script_OpenGrid

Author: Copyright � 2011, ������� ��������
Orders Execution
Checks for the total of open orders
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites
cm_script_OpenGrid
#property copyright "Copyright © 2011, Õëûñòîâ Âëàäèìèð"
#property link      "cmillion@narod.ru"
#property show_inputs
//--------------------------------------------------------------------
extern datetime TimeSet        = D'2011.12.10 17:47'; //Âðåìÿ âûñòàâëåíèÿ îðäåðîâ, åñëè òåêóùåå âðåìÿ áîëüøå óñòàíîâëåííîãî, òî âûñòàâëÿþòñÿ ñðàçó
extern bool     Stop           = true;     //îòêðûòü ñòîï îðäåðà
extern bool     Limit          = true;     //îòêðûòü ëèìèòíûå îðäåðà
extern bool     SELL           = true;     //îòêðûòü îðäåðà SELL
extern bool     BUY            = true;     //îòêðûòü îðäåðà BUY
extern string   __             = "";
extern double   FirstBuyStop   = 0;        //öåíà âûñòàâëåíèÿ ïåðâîãî BuyStop îðäåðà, åñëè 0 òî ïåðâûé BuyStop áóäåò âûñòàâëåí ïî öåíå Ask+delta
extern double   FirstSellStop  = 0;        //öåíà âûñòàâëåíèÿ ïåðâîãî SellStop îðäåðà, åñëè 0 òî ïåðâûé SellStop áóäåò âûñòàâëåí ïî öåíå Bid-delta
extern double   FirstBuyLimit  = 0;        //öåíà âûñòàâëåíèÿ ïåðâîãî BuyLimit îðäåðà, åñëè 0 òî ïåðâûé BuyLimit áóäåò âûñòàâëåí ïî öåíå Bid-delta
extern double   FirstSellLimit = 0;        //öåíà âûñòàâëåíèÿ ïåðâîãî SellLimit îðäåðà, åñëè 0 òî ïåðâûé SellLimit áóäåò âûñòàâëåí ïî öåíå Ask+delta
extern int      FirstStop      = 100;      //ðàññòîÿíèå (â ïóíêòàõ) îò òåêóùåé öåíû äî ïåðâîãî Stop îðäåðà â ñëó÷àå First..Stop=0 
extern int      FirstLimit     = 50;       //ðàññòîÿíèå (â ïóíêòàõ) îò òåêóùåé öåíû äî ïåðâîãî Limit îðäåðà â ñëó÷àå First..Limit=0
extern int      StepStop       = 30;       //ðàññòîÿíèå (â ïóíêòàõ) ìåæäó Stop îðäåðàìè
extern int      StepLimit      = 30;       //ðàññòîÿíèå (â ïóíêòàõ) ìåæäó Limit îðäåðàìè
extern string   _              = "";
extern int      Orders         = 5;        //êîë-âî îðäåðîâ ñåòêè
extern double   LotStop        = 0.5;      //îáúåì ïåðâîãî Stop îðäåðà
extern double   K_LotStop      = 1;        //óìíîæåíèå ëîòà Stop îðäåðîâ 
extern double   LotLimit       = 0.1;      //îáúåì ïåðâîãî Limit îðäåðà
extern double   K_LotLimit     = 2;        //óìíîæåíèå ëîòà Limit îðäåðîâ
extern int      stoploss       = 50;       //óðîâåíü âûñòàâëåíèÿ SL, åñëè 0, òî SL íå âûñòàâëÿåòñÿ
extern int      takeprofit     = 100;      //óðîâåíü âûñòàâëåíèÿ TP, åñëè 0, òî TP íå âûñòàâëÿåòñÿ
extern int      Expiration     = 1440;     //Ñðîê èñòå÷åíèÿ îòëîæåííîãî îðäåðà â ìèíóòàõ, åñëè 0, òî ñðîê íå îãðàíè÷åí (1440 - ñóòêè)
extern int      attempts       = 10;       //êîë-âî ïîïûòîê îòêðûòèÿ îðäåðà 
extern int      Magic          = 0;        //óíèêàëüíûé íîìåð îðäåðà
//--------------------------------------------------------------------
string txt;
int n,slippage=3,STOPLEVEL;
datetime expiration;
//--------------------------------------------------------------------
int start()
{
//===========================================================================================================================================   
//===========================================================================================================================================   
//===========================================================================================================================================   
/*============================================*/if (IsTesting() && OrdersTotal()>0) return;/*===============================================*/
//===========================================================================================================================================   
//===========================================================================================================================================   
//===========================================================================================================================================   
   if (Expiration>0) expiration=TimeCurrent()+Expiration*60; else expiration=0;
   Comment("Çàïóñê ñêðèïòà OpenStopOrderNetTime ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
   STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);
   if (Digits==3 || Digits==5) slippage=30;
   while (TimeCurrent()<TimeSet)
   {
      Sleep(1000);
      Comment("Ñêðèïò âûñòàâëåíèÿ ñåòêè îòëîæåííûõ îðäåðîâ Copyright © 2011 cmillion@narod.ru\n",
      TimeToStr(TimeCurrent(),TIME_SECONDS)," Äî âûñòàâëåíèÿ ñåòêè îñòàëîñü ",TimeToStr(TimeSet-TimeCurrent(),TIME_SECONDS));
      RefreshRates();
   }
   double PriceBS,PriceBL,PriceSS,PriceSL;
   double LOTs=LotStop;
   double LOTl=LotLimit;
   if (FirstBuyStop==0) PriceBS = NormalizeDouble(Ask+FirstStop*Point,Digits);
   else PriceBS = NormalizeDouble(FirstBuyStop,Digits);
   if ((PriceBS-Ask)/Point<STOPLEVEL) {Alert("Ïåðâûé îðäåð BuyStop íå ìîæåò áûòü óñòàíîâëåí áëèæå ÷åì ",STOPLEVEL," ï");return;}
   
   if (FirstSellStop==0) PriceSS = NormalizeDouble(Bid-FirstStop*Point,Digits);
   else PriceSS = NormalizeDouble(FirstSellStop,Digits);
   if ((Bid-PriceSS)/Point<STOPLEVEL) {Alert("Ïåðâûé îðäåð SellStop íå ìîæåò áûòü óñòàíîâëåí áëèæå ÷åì ",STOPLEVEL," ï");return;}
   
   if (FirstBuyLimit==0) PriceBL = NormalizeDouble(Bid-FirstLimit*Point,Digits);
   else PriceBL = NormalizeDouble(FirstBuyLimit,Digits);
   if ((Bid-PriceBL)/Point<STOPLEVEL) {Alert("Ïåðâûé îðäåð BuyLimit íå ìîæåò áûòü óñòàíîâëåí áëèæå ÷åì ",STOPLEVEL," ï");return;}
   
   if (FirstSellLimit==0) PriceSL = NormalizeDouble(Ask+FirstLimit*Point,Digits);
   else PriceSL = NormalizeDouble(FirstSellLimit,Digits);
   if ((PriceSL-Ask)/Point<STOPLEVEL) {Alert("Ïåðâûé îðäåð SellLimit íå ìîæåò áûòü óñòàíîâëåí áëèæå ÷åì ",STOPLEVEL," ï");return;}
   
   for (int i=1; i<=Orders; i++)
   {
      if (Stop)
      {
         if (BUY)
         {
            OPENORDER (OP_BUYSTOP,PriceBS,LOTs,i);
            PriceBS = NormalizeDouble(PriceBS+StepStop*Point,Digits);
         }
         if (SELL)
         {  
            OPENORDER (OP_SELLSTOP,PriceSS,LOTs,i);
            PriceSS = NormalizeDouble(PriceSS-StepStop*Point,Digits);
         }
      }
      LOTs=LOTs*K_LotStop;
      if (Limit)
      {
         if (BUY)
         {
            OPENORDER (OP_BUYLIMIT,PriceBL,LOTl,i);
            PriceBL = NormalizeDouble(PriceBL-StepLimit*Point,Digits);
         }
         if (SELL)
         {  
            OPENORDER (OP_SELLLIMIT,PriceSL,LOTl,i);
            PriceSL = NormalizeDouble(PriceSL+StepLimit*Point,Digits);
         }
      }
      LOTl=LOTl*K_LotLimit;
   }
   Comment("Ñêðèïò çàêîí÷èë ñâîþ ðàáîòó, âûñòàâëåíî ",n," îðäåðîâ  ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
return(0);
}
//--------------------------------------------------------------------
void OPENORDER(int ord,double Price,double LOT,int i)
{
   int error,err;
   double SL,TP;
   while (true)
   {  error=true;
      if (ord==OP_BUYSTOP) 
      {
         if (takeprofit!=0) TP  = NormalizeDouble(Price + takeprofit*Point,Digits); else TP=0;
         if (stoploss!=0)   SL  = NormalizeDouble(Price - stoploss*Point,Digits); else SL=0;     
         error=OrderSend(Symbol(),ord, LOT,Price,slippage,SL,TP,"http://cmillion.narod.ru",Magic,expiration,Blue);
      }
      if (ord==OP_SELLSTOP) 
      {
         if (takeprofit!=0) TP = NormalizeDouble(Price - takeprofit*Point,Digits); else TP=0;
         if (stoploss!=0)   SL = NormalizeDouble(Price + stoploss*Point,Digits);  else SL=0;              
         error=OrderSend(Symbol(),ord,LOT,Price,slippage,SL,TP,"http://cmillion.narod.ru",Magic,expiration,Red);
      }
      if (ord==OP_SELLLIMIT) 
      {
         if (takeprofit!=0) TP = NormalizeDouble(Price - takeprofit*Point,Digits); else TP=0;
         if (stoploss!=0)   SL = NormalizeDouble(Price + stoploss*Point,Digits);  else SL=0;              
         error=OrderSend(Symbol(),ord, LOT,Price,slippage,SL,TP,"http://cmillion.narod.ru",Magic,expiration,Blue);
      }
      if (ord==OP_BUYLIMIT) 
      {
         if (takeprofit!=0) TP  = NormalizeDouble(Price + takeprofit*Point,Digits); else TP=0;
         if (stoploss!=0)   SL  = NormalizeDouble(Price - stoploss*Point,Digits); else SL=0;     
         error=OrderSend(Symbol(),ord,LOT,Price,slippage,SL,TP,"http://cmillion.narod.ru",Magic,expiration,Red);
      }
      if (error==-1)
      {  
         txt=StringConcatenate(txt,"\nError ",GetLastError());
         if (ord==OP_BUYSTOP)   txt = StringConcatenate(txt,"  OPENORDER BUYSTOP ",  i,"   Ask =",DoubleToStr(Ask,Digits),"   Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Price-Ask)/Point,0),")  SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((Price-SL)/Point,0),")  TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((TP-Price)/Point,0),")  STOPLEVEL=",STOPLEVEL);
         if (ord==OP_SELLSTOP)  txt = StringConcatenate(txt,"  OPENORDER SELLSTOP ", i,"   Bid =",DoubleToStr(Bid,Digits),"   Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Bid-Price)/Point,0),")  SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((SL-Price)/Point,0),")  TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((Price-TP)/Point,0),")  STOPLEVEL=",STOPLEVEL);
         if (ord==OP_SELLLIMIT) txt = StringConcatenate(txt,"  OPENORDER SELLLIMIT ",i,"   Ask =",DoubleToStr(Ask,Digits),"   Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Price-Ask)/Point,0),")  SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((Price-SL)/Point,0),")  TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((TP-Price)/Point,0),")  STOPLEVEL=",STOPLEVEL);
         if (ord==OP_BUYLIMIT)  txt = StringConcatenate(txt,"  OPENORDER BUYLIMIT ", i,"   Bid =",DoubleToStr(Bid,Digits),"   Price =",DoubleToStr(Price,Digits)," (",NormalizeDouble((Bid-Price)/Point,0),")  SL =",DoubleToStr(SL,Digits)," (",NormalizeDouble((SL-Price)/Point,0),")  TP=",DoubleToStr(TP,Digits)," (",NormalizeDouble((Price-TP)/Point,0),")  STOPLEVEL=",STOPLEVEL);
         Print(txt);
         Comment(txt,"  ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
         err++;Sleep(1000);RefreshRates();
      }
      else 
      {
         Comment("Îðäåð ",error," óñïåøíî âûñòàâëåí ",TimeToStr(TimeCurrent(),TIME_DATE|TIME_SECONDS));
         n++;
         return;
      }
      if (err>attempts) return;
   }
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 ---