Author: Copyright 2023, Woohaeng
Price Data Components
Orders Execution
It automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
MakeOrder
//+------------------------------------------------------------------+
//|                                                    MakeOrder.mq4 |
//|                                         Copyright 2023, Woohaeng |
//|                                       https://www.wolfzone.co.kr |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, Woohaeng"
#property link      "https://www.wolfzone.co.kr"
#property version   "1.00"
#property strict
#property script_show_inputs

enum EOT {
   BUY = OP_BUY,
   SELL = OP_SELL
};

//--- input parameters
input int      MAGIC_NUMBER = 0;       // Magic number
input EOT      ORDER_TYPE = OP_BUY;    // Order type
input double   ORDER_LOTS = 0.01;      // Order lots
input int      TAKE_PROFIT_POINT = 0;  // Take-profit point(option)
input int      STOP_LOSS_POINT = 0;    // Stop-loss point(option)
input string   COMMENT = "force new";  // Comment
input int      MAXIMUM_SLIPPAGE = 100; // Maximum slippage

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
   if (MAGIC_NUMBER < 0) {
      Print("Invalid magic number!");
      return INIT_FAILED;
   }

   if (ORDER_LOTS <= 0.0 && ORDER_LOTS > 100) {
      Print("Invalid order lots!");
      return INIT_FAILED;
   }

   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart() {
   if (ORDER_TYPE == OP_BUY) {
      double takeProfit = TAKE_PROFIT_POINT > 0 ? NormalizeDouble(Ask + (TAKE_PROFIT_POINT * Point()), Digits) : 0;
      double stopLoss = STOP_LOSS_POINT > 0 ? NormalizeDouble(Ask - (STOP_LOSS_POINT * Point()), Digits) : 0;

      int res = OrderSend(Symbol(), OP_BUY, ORDER_LOTS, Ask, MAXIMUM_SLIPPAGE, stopLoss, takeProfit, COMMENT, MAGIC_NUMBER, 0, clrBlue);
      if (res < 0) {
         Print("OrderSend error with error #", GetLastError());
         return;
      }
   } else if (ORDER_TYPE == OP_SELL) {
      double takeProfit = TAKE_PROFIT_POINT > 0 ? NormalizeDouble(Bid - (TAKE_PROFIT_POINT * Point()), Digits) : 0;
      double stopLoss = STOP_LOSS_POINT > 0 ? NormalizeDouble(Bid + (STOP_LOSS_POINT * Point()), Digits) : 0;

      int res = OrderSend(Symbol(), OP_SELL, ORDER_LOTS, Bid, MAXIMUM_SLIPPAGE, stopLoss, takeProfit, COMMENT, MAGIC_NUMBER, 0, clrRed);
      if (res < 0) {
         Print("OrderSend error with error #", GetLastError());
         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 ---