Author: Igor Morozov
Orders Execution
It automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategyChecks for the total of open orders
Indicators Used
MACD Histogram
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
11.00 %
Total Trades 693
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -14.19
Gross Profit 1161.00
Gross Loss -10992.00
Total Net Profit -9831.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
12.00 %
Total Trades 685
Won Trades 140
Lost trades 545
Win Rate 0.20 %
Expected payoff -14.05
Gross Profit 1268.00
Gross Loss -10894.00
Total Net Profit -9626.00
-100%
-50%
0%
50%
100%
MACD5MIN
//+------------------------------------------------------------------+
//|                                                     MACD5MIN.mq4 |
//|                                                     Igor Morozov |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Igor Morozov"
#property link      ""

//---- input parameters
extern int       FastEMA=10;
extern int       SlowEMA=26;
extern int       Divergence=8;
extern int       StopLoss=20;
extern int       TakeProfit=20;
extern int       MagicNumber=10268;

int ticket;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----
   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
{
//----
   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----
	ticket=GetTicket(MagicNumber);
	switch(ticket)
	{
		case 0: // look for entry
		{
			double curMACD=iMACD(NULL,PERIOD_M5,FastEMA,SlowEMA,1,PRICE_CLOSE,0,1);
			double priMACD=iMACD(NULL,PERIOD_M5,FastEMA,SlowEMA,1,PRICE_CLOSE,0,2);
			// buy signal
			if(curMACD>=Divergence*Point&&priMACD<Divergence*Point) 
				OrderSend(Symbol(),OP_BUY,1,Ask,2,
						Ask-StopLoss*Point,Ask+TakeProfit*Point,"",
						MagicNumber,0,Blue);
			// sell signal
			if(curMACD<=Divergence*Point*(-1)&&priMACD>Divergence*Point*(-1)) 
				OrderSend(Symbol(),OP_SELL,1,Bid,2,
						Bid+StopLoss*Point,Bid-TakeProfit*Point,"",
						MagicNumber,0,Red);
			break;
		}
		default: // look for exit
		{
			if(OrderSelect(ticket,SELECT_BY_TICKET))
			{
				switch(OrderType())
				{
					case OP_BUY:
					{
						if(Bid-OrderOpenPrice()>TakeProfit*Point*0.8)
						{
							double newsl=MathMin(
									OrderOpenPrice()+TakeProfit*Point*0.5,
									Bid-(MarketInfo(Symbol(),MODE_STOPLEVEL)+1)*Point);
							OrderModify(ticket,0,newsl,OrderTakeProfit(),0,Aqua);
						}
						break;
					}
					case OP_SELL:
					{
						if(OrderOpenPrice()-Bid>TakeProfit*Point*0.8)
						{
							newsl=MathMax(
									OrderOpenPrice()-TakeProfit*Point*0.5,
									Ask+(MarketInfo(Symbol(),MODE_STOPLEVEL)+1)*Point);
							OrderModify(ticket,0,newsl,OrderTakeProfit(),0,Orange);
						}
						break;
					}
				}
			}
		}
	}	   
//----
   return(0);
}
//+------------------------------------------------------------------+

int GetTicket(int magic)
{
	for(int i=0;i<OrdersTotal();i++)
	{
		if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
		{
			if(OrderSymbol()==Symbol()&&OrderMagicNumber()==magic)
				return(OrderTicket());
		}
	}
	return(0);
}

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