Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites
TL_v2
//+------------------------------------------------------------------+
//|     Ñèòíèêîâ Âàëåðèé ßêîâëåâè÷          valerasva@mail.ru        |
//+------------------------------------------------------------------+

extern double Lot         = 0.01;
extern double TrSt        = 300;
extern double ÓðÑòîïîâ    = 100;
extern double Risk        = 0.1;
extern bool Îòîáðàæåíèå   = true;
extern bool Çâóê          = true;
extern double MAGICMA     = 55555;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
double line=0;
double line0=0;
double linek;
double Lots=(NormalizeDouble(AccountFreeMargin()*Risk/1000.0,2));
if(Lots<Lot) Lots=Lot;
//+-----------------------------------------------------------------  
for(int i = 0; i <= OrdersTotal(); i++) 
  {                
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber() == MAGICMA
 && (OrderType()==OP_SELL || OrderType()==OP_BUY)) bool BuyOp=true;  
if(OrderSymbol()==Symbol() && OrderMagicNumber() == MAGICMA
 && (OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT)) bool BuyStLi=true;
if(OrderSymbol()==Symbol() && OrderMagicNumber() == MAGICMA 
 && (OrderType()==OP_SELLLIMIT || OrderType()==OP_SELLSTOP)) bool SellStLi=true;  
   } 
//+-----------------------------------------------------------------
int obj_total=ObjectsTotal();
for(int k=0;k<obj_total;k++)
  {
if(ObjectType(ObjectName(k))!=OBJ_TREND) continue;
   {  
linek=ObjectGetValueByShift(ObjectName(k), 0);
    {    
if(Bid>linek-ÓðÑòîïîâ*Point && Bid<linek+ÓðÑòîïîâ*Point) line0=linek;
if(Bid>linek-ÓðÑòîïîâ*4*Point && Bid<linek+ÓðÑòîïîâ*4*Point) line=linek;      
    }
   }
  } 
//+-----------------------------------------------------------------    
if(BuyOp==false)
   {
if(Bid>line0 && line0!=0 && BuyStLi==false)   
      {
if(Îòîáðàæåíèå==false) OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Bid-ÓðÑòîïîâ*Point,0,"",MAGICMA);
if(Îòîáðàæåíèå==true) OrderSend(Symbol(),OP_BUY,Lots,Ask,5,Bid-ÓðÑòîïîâ*Point,0,"",MAGICMA,0,Green);
if(Çâóê) PlaySound("alert.wav");
      }              
if(Ask<line0 && line0!=0 && SellStLi==false)
      {     
if(Îòîáðàæåíèå==false) OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Ask+ÓðÑòîïîâ*Point,0,"",MAGICMA);
if(Îòîáðàæåíèå==true) OrderSend(Symbol(),OP_SELL,Lots,Bid,5,Ask+ÓðÑòîïîâ*Point,0,"",MAGICMA,0,Red);
if(Çâóê) PlaySound("alert.wav");
      } 
   }
//+-----------------------------------------------------------------    
if(Bid>line && line!=0 && BuyStLi==false && BuyOp==false)   
      {
if(Îòîáðàæåíèå==false) OrderSend(Symbol(),OP_BUYLIMIT,Lots,line+ÓðÑòîïîâ*Point,0,line-ÓðÑòîïîâ*Point,0,"",MAGICMA);
if(Îòîáðàæåíèå==true) OrderSend(Symbol(),OP_BUYLIMIT,Lots,line+ÓðÑòîïîâ*Point,0,line-ÓðÑòîïîâ*Point,0,"",MAGICMA,0,Green);
      }              
if(Bid>line && line!=0 && SellStLi==false && BuyOp==false)
      {     
if(Îòîáðàæåíèå==false) OrderSend(Symbol(),OP_SELLSTOP,Lots,line-ÓðÑòîïîâ*Point,0,line+ÓðÑòîïîâ*Point,0,"",MAGICMA);
if(Îòîáðàæåíèå==true) OrderSend(Symbol(),OP_SELLSTOP,Lots,line-ÓðÑòîïîâ*Point,0,line+ÓðÑòîïîâ*Point,0,"",MAGICMA,0,Red);
      }   
//+-----------------------------------------------------------------    
if(Bid<line && line!=0 && BuyStLi==false && BuyOp==false)   
      {
if(Îòîáðàæåíèå==false) OrderSend(Symbol(),OP_BUYSTOP,Lots,line+ÓðÑòîïîâ*Point,0,line-ÓðÑòîïîâ*Point,0,"",MAGICMA);
if(Îòîáðàæåíèå==true) OrderSend(Symbol(),OP_BUYSTOP,Lots,line+ÓðÑòîïîâ*Point,0,line-ÓðÑòîïîâ*Point,0,"",MAGICMA,0,Green);
      }              
if(Bid<line && line!=0 && SellStLi==false && BuyOp==false)
      {     
if(Îòîáðàæåíèå==false) OrderSend(Symbol(),OP_SELLLIMIT,Lots,line-ÓðÑòîïîâ*Point,0,line+ÓðÑòîïîâ*Point,0,"",MAGICMA);
if(Îòîáðàæåíèå==true) OrderSend(Symbol(),OP_SELLLIMIT,Lots,line-ÓðÑòîïîâ*Point,0,line+ÓðÑòîïîâ*Point,0,"",MAGICMA,0,Red);
      }                 
//+----------------------------------------------------------------- 
for(int cnt=0;cnt<OrdersTotal();cnt++)
    {
    OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      {
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
        {
        if(OrderType()==OP_BUY)   
          {
          if(Ask<line0 && Ask<line0-ÓðÑòîïîâ*Point/2 && line0!=0)
            {
            if(Îòîáðàæåíèå==false) OrderClose(OrderTicket(),OrderLots(),Bid,5); 
            if(Îòîáðàæåíèå==true) OrderClose(OrderTicket(),OrderLots(),Bid,5,Violet); 
            }
            if(OrderStopLoss()<(Bid-Point*TrSt) && (Bid-OrderOpenPrice())>Point*TrSt)  
            {                 
            OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrSt,OrderTakeProfit(),0);
            }
          }
        if(OrderType()==OP_SELL) 
          {
          if(Bid>line0 && Bid>line0+ÓðÑòîïîâ*Point/2 && line0!=0)
            {
            if(Îòîáðàæåíèå==false) OrderClose(OrderTicket(),OrderLots(),Ask,5); 
            if(Îòîáðàæåíèå==true)OrderClose(OrderTicket(),OrderLots(),Ask,5,Violet);
            }
          if(OrderStopLoss()>(Ask+Point*TrSt) && (OrderOpenPrice()-Ask)>Point*TrSt)  
            {                 
            OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrSt,OrderTakeProfit(),0);
            }
          }
        if(OrderType()==OP_BUYLIMIT)   
          {
          if(line==0)
            {
            OrderDelete(OrderTicket());  
            }
          if(line!=0 && line+ÓðÑòîïîâ*Point!=OrderOpenPrice())  
            {                 
            OrderModify(OrderTicket(),line+ÓðÑòîïîâ*Point,line-ÓðÑòîïîâ*Point,0,0);
            }
          }
        if(OrderType()==OP_SELLSTOP) 
          {
          if(line==0)
            {
            OrderDelete(OrderTicket());
            }
          if(line!=0 && line-ÓðÑòîïîâ*Point!=OrderOpenPrice())  
            {                 
            OrderModify(OrderTicket(),line-ÓðÑòîïîâ*Point,line+ÓðÑòîïîâ*Point,OrderTakeProfit(),0);
            }
          }
        if(OrderType()==OP_BUYSTOP)   
          {
          if(line==0)
            {
            OrderDelete(OrderTicket());  
            }
          if(line!=0 && line+ÓðÑòîïîâ*Point!=OrderOpenPrice())  
            {                 
            OrderModify(OrderTicket(),line+ÓðÑòîïîâ*Point,line-ÓðÑòîïîâ*Point,0,0);
            }
          }
        if(OrderType()==OP_SELLLIMIT) 
          {
          if(line==0)
            {
            OrderDelete(OrderTicket());
            }
          if(line!=0 && line-ÓðÑòîïîâ*Point!=OrderOpenPrice())  
            {                 
            OrderModify(OrderTicket(),line-ÓðÑòîïîâ*Point,line+ÓðÑòîïîâ*Point,OrderTakeProfit(),0);
            }
          }
        }
      }
    }
return(0);
  }
// the end.

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