cm-script-Open_Order_Time

Author: Copyright � 2014, ������� ��������
0 Views
0 Downloads
0 Favorites
cm-script-Open_Order_Time
#property copyright "Copyright © 2014, Õëûñòîâ Âëàäèìèð"
#property link      "cmillion@narod.ru"
#property show_inputs
#property description "Ñêðèïò îòêðûòèÿ ðûíî÷íûõ ïîçèöèé â óêàçàííîå âðåìÿ"
#property strict
//--------------------------------------------------------------------
extern int      stoploss       = 50,       //óðîâåíü âûñòàâëåíèÿ SL, åñëè 0, òî SL íå âûñòàâëÿåòñÿ
                takeprofit     = 50,       //óðîâåíü âûñòàâëåíèÿ TP, åñëè 0, òî TP íå âûñòàâëÿåòñÿ
                MaxOrders      = 1,        //êîë-âî îðäåðîâ
                Magic          = 123456;   //óíèêàëüíûé íîìåð îðäåðà
extern double   LotBuy         = 0.1;      //îáúåì îðäåðà åñëè 0 òî íå îòêîûâàòü
extern double   LotSell        = 0.1;      //îáúåì îðäåðà åñëè 0 òî íå îòêîûâàòü
extern datetime TimeSet        = D'2014.08.25 15:00'; //Âðåìÿ âûñòàâëåíèÿ îðäåðîâ, åñëè òåêóùåå âðåìÿ áîëüøå óñòàíîâëåííîãî, òî âûñòàâëÿþòñÿ ñðàçó
extern int      attempts       = 10;       //êîë-âî ïîïûòîê îòêðûòèÿ
string txt;
int n,slippage=3;
double STOPLEVEL;
//--------------------------------------------------------------------
int start()
{
   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 © 2014 cmillion@narod.ru\n",
      TimeToStr(TimeCurrent(),TIME_SECONDS)," Äî âûñòàâëåíèÿ ïîçèöèé îñòàëîñü ",TimeToStr(TimeSet-TimeCurrent(),TIME_SECONDS));
   }
   RefreshRates();

   for (int i=1; i<=MaxOrders; i++)
   {
      if (LotBuy>0)
      {
         OPENORDER (OP_BUY,NormalizeDouble(Ask,Digits),LotBuy,i);
      }
      if (LotSell>0)
      {  
         OPENORDER (OP_SELL,NormalizeDouble(Bid,Digits),LotSell,i);
      }
   }
   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=0,TP=0;
   while (true)
   {  error=true;
      RefreshRates();
      if (ord==OP_BUY) 
      {
         if (takeprofit>=STOPLEVEL) TP  = NormalizeDouble(Price + takeprofit*Point,Digits); else TP=0;
         if (stoploss>=STOPLEVEL)   SL  = NormalizeDouble(Price - stoploss*Point,Digits);   else SL=0;     
         error=OrderSend(Symbol(),OP_BUY, LOT,Price,slippage,SL,TP,"http://cmillion.ru",Magic,0,Blue);
      }
      if (ord==OP_SELL) 
      {
         if (takeprofit>=STOPLEVEL) TP = NormalizeDouble(Price - takeprofit*Point,Digits); else TP=0;
         if (stoploss>=STOPLEVEL)   SL = NormalizeDouble(Price + stoploss*Point,Digits);   else SL=0;              
         error=OrderSend(Symbol(),OP_SELL,LOT,Price,slippage,SL,TP,"http://cmillion.ru",Magic,0,Red);
      }
      if (error==-1)
      {  
         txt=StringConcatenate(txt,"\nError ",GetLastError());
         if (ord== 1) txt = StringConcatenate(txt,"  OPENORDER BUY ",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==-1) txt = StringConcatenate(txt,"  OPENORDER SELL ",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 ---