_SET_BU_ON_TARGET

Author: Copyright � 2009, MetaQuotes Software Corp.
Orders Execution
Checks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
Miscellaneous
It issuies visual alerts to the screenIt plays sound alerts
0 Views
0 Downloads
0 Favorites
_SET_BU_ON_TARGET
//+------------------------------------------------------------------+
//|                                                      _SET_BU.mq4 |
//|                      Copyright © 2009, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
void start(){
  int stlw=MarketInfo(Symbol(),MODE_STOPLEVEL);
  int spr =MarketInfo(Symbol(),MODE_SPREAD);  
  double prise=WindowPriceOnDropped();
  if(prise==0){
    Alert("Öåíà íå îïðåäåëåíà!");
    return;
  } 
//----  
  for(int i=0;i<OrdersTotal();i++){
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){
      if(OrderSymbol()==Symbol()){
        if(OrderCloseTime()==0){
          if(MathAbs(OrderOpenPrice()-prise)<spr*Point*2){
            int ticket=OrderTicket();
          }
        }  
      }
    }
  }
  if(ticket<1){
    Alert("îðäåð íå íàéäåí!");
    return;  
  }
//----
  while(!IsStopped()){
    Sleep(300);
    if(ObjectFind("target")!=0){
      Alert("Íåò öåëåâîãî óðîâíÿ");
      return;
    }else{
      double target = nd(ObjectGet("target",OBJPROP_PRICE1));
    }
    if(OrderSelect(ticket,SELECT_BY_TICKET)){
      if(OrderType()>1){Alert("Íåâåðíûé òèï îðäåðà");return;}
      if(OrderCloseTime()!=0){Alert("îðäåð çàêðûò");return;}
      if(OrderType()==OP_BUY){if(target<OrderOpenPrice()){Alert("Ïåðåäâèíüòå öåëåâîé óðîâåíü âûøå!");return;}}
      if(OrderType()==OP_SELL){if(target>OrderOpenPrice()){Alert("Ïåðåäâèíüòå öåëåâîé óðîâåíü íèæå!");return;}}
      if(NormalizeDouble(OrderOpenPrice(),Digits)==NormalizeDouble(OrderStopLoss(),Digits)){Alert("ÁÓ óñòàíîâëåí");return;}
      if(OrderType()==0){Comment("Äèñòàíöèÿ äî öåëè  = ",(target - Bid)/Point);  
        if(Bid>target){
          if(Bid-OrderOpenPrice()>stlw*Point){
            if(!OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue)){
              Alert("Îøèáêà óñòàíîâêè ÁÓ ¹",GetLastError());
              return;
            }else{PlaySound("expert.wav");}
          }  
        }
      }
      if(OrderType()==1){Comment("Äèñòàíöèÿ äî öåëè  = ",(Ask - target)/Point);  
        if(Ask<target){
          if(OrderOpenPrice()-Ask>stlw*Point){
            if(!OrderModify(ticket,OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0,Blue)){
              Alert("Îøèáêà óñòàíîâêè ÁÓ ¹",GetLastError());
              return;
            }else{PlaySound("expert.wav");}
          }  
        }        
      }        
    }
  }
return;}
//+------------------------------------------------------------------+
double nd(double in){return(NormalizeDouble(in,MarketInfo(Symbol(),MODE_DIGITS)));}

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