cm-Nevalyashka-600

Author: Copyright � 2014, ������� ��������
Orders Execution
Checks for the total of open ordersChecks for the total of closed ordersIt automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
cm-Nevalyashka-600
//+------------------------------------------------------------------+
//|                               Copyright © 2014, Õëûñòîâ Âëàäèìèð |
//|                                                cmillion@narod.ru |
//|                                                                  |
//--------------------------------------------------------------------
#property copyright "Copyright © 2014, Õëûñòîâ Âëàäèìèð"
#property link      "http://cmillion.ru/"
#property version     "600.0"
#property description "Ñîâåòíèê îòêðûâàåò ïîçèöèþ â çàâèñèìîñòè îò çàêðûòèÿ ïðîøëîé ïîçèöèè. Åñëè ïîçèöèè íå áûëî òî â çàâèñèìîñòè îò íàïðàâëåíèÿ ïðîøëîé ñâå÷è"
#property description "Ïðè äîñòèæåíèå Ò/P ñëåäóþùèé îðäåð îòêðûâàåòñÿ â ýòó æå ñòîðîíó"
#property description "Ïðè äîñòèæåíèå S/L ñëåäóþùèé îòêðûâàåòñÿ â ïðîòèâîïîëîæíóþ ñòîðîíó"

 //--------------------------------------------------------------------
extern int    stoploss     = 100,
              takeprofit   = 100;
extern double risk         = 0.1; //ïðîöåíò îò äåïîçèòà äëÿ ðàññ÷åòà îáúåìà ïåðâîé ïîçèöèè
extern double KoeffMartin  = 2.0;
extern int    OkrLOT       = 2;//îêðóãëåíèå ëîòà
extern int    slippage     = 3;//Ìàêñèìàëüíî äîïóñòèìîå îòêëîíåíèå öåíû äëÿ ðûíî÷íûõ îðäåðîâ
extern int    MagicNumb    = 77;//Magic

double MINLOT,MAXLOT;
//--------------------------------------------------------------------
int init()
{
   MAXLOT = MarketInfo(Symbol(),MODE_MAXLOT);
   MINLOT = MarketInfo(Symbol(),MODE_MINLOT);
   return(0);
}
//--------------------------------------------------------------------
int start()
{
   for (int i=0; i<OrdersTotal(); i++)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumb)
         {
            return(0);
         }
      }
   }
   int tip=-1;
   double Lot=0;
   
   for (i=OrdersHistoryTotal()-1; i>=0; i--)
   {
      if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
      {
         if (OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumb)
         {
            if (OrderProfit()<0) 
            {
               Lot=lot(OrderLots(),KoeffMartin);
               tip=OrderType();
            }
            else tip=-1;
            break;
         }
      }
   }

   if (tip==-1)
   {
      Lot=lot(0,1);
      if (Open[1]>Close[1]) tip=OP_BUY;
      else tip=OP_SELL;
   }
   
   if (tip==OP_BUY) if (OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Bid,Digits),slippage,
                                    NormalizeDouble(Ask + stoploss*Point,Digits),
                                    NormalizeDouble(Bid - takeprofit*Point,Digits),NULL,MagicNumb,Blue)!=-1) Comment("Open Sell");
   if (tip==OP_SELL) if (OrderSend(Symbol(),OP_BUY ,Lot,NormalizeDouble(Ask,Digits),slippage,
                                    NormalizeDouble(Bid - stoploss*Point,Digits),
                                    NormalizeDouble(Ask + takeprofit*Point,Digits),NULL,MagicNumb,Blue)!=-1) Comment("Open Buy");
                                    
   return(0);
}
//--------------------------------------------------------------------
double lot(double l,double k)
{
   double ML = AccountFreeMargin()/MarketInfo(Symbol(),MODE_MARGINREQUIRED);
   if (k==1) l = ML*risk/100;
   else l = NormalizeDouble(l*k,OkrLOT);
   if (l>ML) l = ML;
   if (l>MAXLOT) l = MAXLOT;
   if (l<MINLOT) l = MINLOT;
   return(l);
}
//-----------------------------------------------------------------

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