cm gread stop lock

Author: Copyright 2018, Vladimir Hlystov
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
cm gread stop lock
ÿþ#property copyright "Copyright 2018, Vladimir Hlystov"

#property link      "cmillion@narod.ru"

#property version   "1.00"

#property show_inputs

#property strict

#property description "!:@8?B 2KAB02;O5B A5BL ;>:>2KE AB>? >@45@>2 G5@57 7040==>5 @0AAB>O=85"

#property description ">B=>ABL >@45@>2 7028A8B >B @07=>AB8 ;>B>2 =0?@02;5=89"

#property description "@8<5@ 8<55< buy 1;>B 8 sell 2 ;>B0 G8A;> >@45@>2 A5B8 10 H03 5"

#property description "A>25B=8: 2KAB028B 10 buystop >@45@>2 =0 @0AAB>O=88 5 ? <564C A>1>9 ;>B>< 0,1"

//+------------------------------------------------------------------+

extern int   Orders   = 10;        //:>;-2> >@45@>2 

extern int   Step     = 10;        //H03 <564C >@45@0<8

//--------------------------------------------------------------------

void OnStart()

  {

   double MINLOT = MarketInfo(Symbol(),MODE_MINLOT);

   double MAXLOT = MarketInfo(Symbol(),MODE_MAXLOT);

   if (Digits==3 || Digits==5)

   {

      Step*=10;

   }

   double LB=0,LS=0;

   int i,tip;

   for (i=0; i<OrdersTotal(); i++)

   {    

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      { 

         if (OrderSymbol()==Symbol())

         { 

            tip = OrderType(); 

            if (tip==OP_BUY)             

            {  

               LB+=OrderLots();

            }                                         

            if (tip==OP_SELL)        

            {

               LS+=OrderLots();

            } 

         }

      }

   }

   if (LB==LS) return;

   double price=0;

   double lot=NormalizeDouble(MathAbs(LS-LB)/Orders,2);

   if (lot>MAXLOT) lot = MAXLOT;

   if (lot<MINLOT) lot = MINLOT;

   double STOPLEVEL=MarketInfo(Symbol(),MODE_STOPLEVEL);

   if (LB<LS) 

   {

      for (i=0; i<Orders; i++)

      {

         price=NormalizeDouble(Ask+Step*(i+1)*Point,Digits);

         if (price>Ask+STOPLEVEL*Point) 

            if (OPENORDER (OP_BUYSTOP,price,lot)) LB+=lot;

         if (LB>=LS) break;

      }

   }

   if (LB>LS) 

   {

      for (i=0; i<Orders; i++)

      {

         price=NormalizeDouble(Bid-Step*(i+1)*Point,Digits);

         if (price<Bid-STOPLEVEL*Point) 

            if (OPENORDER (OP_SELLSTOP,price,lot)) LS+=lot;

         if (LS>=LB) break;

      }

   }

}

//--------------------------------------------------------------------

bool OPENORDER(int ord,double Price,double LOT)

{

   int error,err=0;

   while (!IsStopped())

   {  

      error=OrderSend(Symbol(),ord,LOT,Price,0,0,0,"lock",0,0,clrBlue);

      if (error==-1)

      {  

         err++;

         Print("Error ",GetLastError()," Price=",Price," Bid=",Bid," LOT=",LOT);

         if (err>10) break;

         Sleep(1000);RefreshRates();

      }

      else return(true);

   }

return(false);

}                  

//--------------------------------------------------------------------



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