C Orders Counter

C Orders Counter
Download ALL MT4 scripts (424)
YouTube Video Thumbnail



Similar MetaTrader Tools

C Orders Counter

Info

The C Orders Counter is a Script for MetaTrader 4 that description:the class corderscounter was developed for counting orders with various filters, including symbol of currency, magic number, and order status (either closed or opened). Below is a description of the public methods of this class.

Usage

This tool is typically used for enhancing chart analysis and decision making.

Platform

This Script works exclusively on MetaTrader 4 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL4/Scripts folder via File ? Open Data Folder in MetaTrader 4.


How to Install and Use C Orders Counter

1. Installation: Move your script file into the MQL/Scripts directory and restart the platform.

2. Execution: Drag the script onto a chart; it will perform a one-time action, such as closing all open orders or clearing chart objects.

3. Editing: Use MetaEditor (F4) to modify code, click "Compile," and verify no errors appear in the terminal before running.

4. Removing: Scripts stop automatically, but you can remove them manually by right-clicking the chart and choosing "Remove Script."

Frequently Asked Questions

Q: How are scripts different from EAs? A: Scripts execute a single action and then stop; EAs monitor the market and trade continuously.

Q: Can I assign a hotkey to a script? A: Yes, right-click the script in the Navigator, select "Set Hotkey," and define your preferred keyboard shortcut.

Q: Why did my script stop? A: Scripts are designed to stop immediately after finishing their programmed command; this is normal behavior.

What this tool does

Description:The class COrdersCounter was developed for counting orders with various filters, including symbol of currency, magic number, and order status (either closed or opened).

Typical Use Case

This Script excels in automated trading and technical analysis on MetaTrader 4.

Compatible Platform & Setup

This Script works on MetaTrader 4. Place the file in the MQL4/Scripts folder and restart the terminal.

Description & Settings

Related: script to close all orders - another powerful script for MetaTrader 4 traders.

Description:

The class COrdersCounter was developed for counting orders with various filters, including symbol of currency, magic number, and order status (either closed or opened).

Also recommended: trailing stop for all orders - similar script with strong performance on MetaTrader 4.


Below is a description of the public methods of this class.



Constructors:

Method

Description

corderscounter(void)

Default constructor.

corderscounter(int magic, string symbol, int counter_mode = mode_trades)

Parameters:

magic
- Integer value of the magic number for order filtering. If magic = 0, it is not used.

symbol
- Symbol of the instrument. If symbol = "", it is not used.

counter_mode
- Specifies the order pool (either closed or opened orders). Accepts 2 values: mode_trades (default) - opened orders, mode_history - closed orders.



Methods:

Method

Description

void refreshdata(void)

Updates order data. This method must be called before using getorderscount(), gettotalprofit(), getmarketvolume(), and gettotalvolume().

int getorderscount(int type)

Returns the count of orders of a specific type. Parameters:
type - Type of orders. Allowed values:

op_buy - Market buy orders
op_sell - Market sell orders
op_selllimit - Sell limit orders
op_buylimit - Buy limit orders
op_sellstop - Sell stop orders
op_buystop - Buy stop orders
If type = -1, returns the total count of all orders.

int getlastorder()

Returns the ticket number of the last closed/opened order in the retrieved list.

int getfirstorder()

Returns the ticket number of the first closed/opened order in the retrieved list.

profitdata gettotalprofit()

Returns an instance of the struct profitdata, containing total profit/loss of the retrieved list.
The struct profitdata contains fields:

double currency - Profit/loss in currency
double points - Profit/loss in points

double getmarketvolume()

Returns the total volume of market trades in the retrieved list.

double gettotalvolume()

Returns the total volume for all orders in the retrieved list.

void setmagicnumber(int magic)

Sets the magic number. Parameters:
magic - New value for the magic number.

void setsymbol(string symbol)

Sets the symbol value. Parameters:
symbol - New symbol value of currency.

void setmode(int mode)

Sets the order pool. Parameters:
mode - Pool type: mode_trades - opened orders, mode_history - closed orders.

int getmagicnumber()

Returns the magic number used for order filtering.

string getsymbol()

Returns the symbol value.

int getmode()

Returns the type of the current order pool: mode_trades - opened orders, mode_history - closed orders.

You may also like: scripts for placing stop and limit orders - excellent alternative for script users on MetaTrader 4.

Source Code

#property copyright "robotfx"
#property link "https://robotfx.org"
#property strict
#property version   "1.00"
struct profitdata
{
public:
   double currency;
   double points;
};

.......

Leave your opinion, ask a question, share some knowledge

⚠ Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.