Sadukey_exp

Profit factor:
0.59
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself
11 Views
0 Downloads
0 Favorites
Sadukey_exp
//+------------------------------------------------------------------+
//|                                                  Sadukey_exp.mq4 |
//+------------------------------------------------------------------+

#property  copyright "Copyright © 2009, "
#property link      ""

#include <stdlib.mqh>

extern int TakeProfit = 300;
extern int StopLoss = 200;
extern int TrailingStop = 120;
extern int TrailingStep = 20;
extern bool CloseOppositePosition = false;

extern double Lots = 0.1;      // ëîò
extern int Slippage = 1;

extern string s______ = "Ïàðàìåòðû èíäèêàòîðà Stoch";
extern int       KPeriod     =  30;
extern int       Slowing     =  10;
extern int       DPeriod     =  10;
extern string note4 = "0=sma, 1=ema, 2=smma, 3=lwma";
extern int       MAMethod    =   0;
extern string note5 = "0=high/low, 1=close/close";
extern int       PriceField  =   1;
extern string note6 = "overbought level";
extern int       overBought  =  60;
extern string note7 = "oversold level";
extern int       overSold    =  40;


#define Buy 0
#define Sell 1
#define Unknown 2

#define Up 0
#define Dn 1

double spread;

int BuyMagic = 5124000;
int SellMagic = 51250000;

bool CanOpenBuy = true;
bool CanOpenSell = true;

int prevBars = -1;

int init()
{
	spread = Ask - Bid;

	CanOpenBuy = true;
	CanOpenSell = true;

	BuyMagic = 5124000;
	SellMagic = 5125000;

	prevBars = -1;
	
	RunIndicator();
	
	return(0);
}

int start()
{
	DoTrail();
	int curBars = iBars(Symbol(), Period());
	if (prevBars == -1)
	{
		prevBars = curBars;
	}
	if (curBars == prevBars)
	{
		return;
	}
	// ïîÿâèëñÿ íîâûé áàð
	prevBars = curBars;
	
	double Stoch = iCustom(Symbol(), 0, "Color Stochastic", "", KPeriod, Slowing, DPeriod, "", MAMethod, "", PriceField, "", overBought, "", overSold, 1, 1);
	
	double Filter1 = iCustom(Symbol(), 0, "Figure", 0, 1);
	double Filter2 = iCustom(Symbol(), 0, "Figure", 2, 1);
	double Filter3 = iCustom(Symbol(), 0, "Figure", 3, 1);
	
	int Direction;
	
	if(Filter1 > Filter3 && Filter2 > Filter3)
	{
		CanOpenSell = true;
		if(Filter1 > Filter2 && Filter2 > Filter3)
		{
			Direction = Up;
		}
		else
		{
			Direction = Unknown;
		}
	}
	else if(Filter1 < Filter3 && Filter2 < Filter3)
	{
		CanOpenBuy = true;
		if(Filter1 < Filter2 && Filter2 < Filter3)
		{
			Direction = Dn;
		}
		else
		{
			Direction = Unknown;
		}
	}
	else
	{
		Direction = Unknown;
	}

	if(CanOpenBuy && Stoch >= overBought && Direction == Up)
	{
		if(CloseOppositePosition)
		{
			CloseAllSell();
		}
		CanOpenBuy = false;
		OpenBuy();
	}

	if(CanOpenSell && Stoch <= overSold && Direction == Dn)
	{
		if(CloseOppositePosition)
		{
			CloseAllBuy();
		}
		CanOpenSell = false;
		OpenSell();
	}

	return(0);
}

// ôóíêöèÿ ïðîãîíÿåò èíäèêàòîð íà èñòîðèè äî òåêóùåãî ìîìåíòà äëÿ òîãî, ÷òîá óñòàíîâèòü òåêóùåå íàïðàâëåíèå èíäèêàòîðà è 
// óñòàíîâèòü ïðàâèëüíûå çíà÷åíèÿ ïåðåìåííûõ, îòâå÷àþùèõ çà òîðãîâëþ
void RunIndicator()
{
	int i;
	
	for(i = 100; i >= 1; i--)
	{
		double Stoch = iCustom(Symbol(), 0, "Color Stochastic", "", KPeriod, Slowing, DPeriod, "", MAMethod, "", PriceField, "", overBought, "", overSold, 1, i);
	
		double Filter1 = iCustom(Symbol(), 0, "Figure", 0, i);
		double Filter2 = iCustom(Symbol(), 0, "Figure", 2, i);
		double Filter3 = iCustom(Symbol(), 0, "Figure", 3, i);
	
		int Direction;
	
		if(Filter1 > Filter3 && Filter2 > Filter3)
		{
			CanOpenSell = true;
			if(Filter1 > Filter2 && Filter2 > Filter3)
			{
				Direction = Up;
			}
			else
			{
				Direction = Unknown;
			}
		}
		else if(Filter1 < Filter3 && Filter2 < Filter3)
		{
			CanOpenBuy = true;
			if(Filter1 < Filter2 && Filter2 < Filter3)
			{
				Direction = Dn;
			}
			else
			{
				Direction = Unknown;
			}
		}
		else
		{
			Direction = Unknown;
		}

		if(CanOpenBuy && Stoch >= overBought && Direction == Up)
		{
			CanOpenBuy = false;
		}

		if(CanOpenSell && Stoch <= overSold && Direction == Dn)
		{
			CanOpenSell = false;
		}
	}
}

void OpenBuy()
{
	int i;		
	int Orders = OrdersTotal();
	double BuyOpen;
	double BuyTP = 0;
	double BuySL = 0;
	
	RefreshRates();
	BuyOpen  = Ask;
	if(TakeProfit != 0)
		BuyTP = BuyOpen + TakeProfit*Point;
	
	if(StopLoss != 0)
	{
		BuySL = BuyOpen - StopLoss*Point;
	}

	//----------------------------------
	datetime begin = TimeCurrent();
	int ticket = OrderSend(Symbol(), OP_BUY, Lots, BuyOpen, Slippage, BuySL, BuyTP, "", BuyMagic, 0, Blue);
	
	int error;
	if (ticket==-1)
	{
		while(ticket == -1 && TimeCurrent() - begin < 20)
		{
			error = GetLastError();
			Print("Îøèáêà îòêðûòèÿ îðäåðà BUY. " + ErrorDescription(error));
			Sleep(100);
			Print("Ïîâòîð");
			RefreshRates();

			BuyOpen  = Ask;
			if(TakeProfit != 0)
				BuyTP = BuyOpen + TakeProfit*Point;
			if(StopLoss != 0)
			{
				BuySL = BuyOpen - StopLoss*Point;
			}
		    ticket = OrderSend(Symbol(), OP_BUY, Lots, BuyOpen, Slippage, BuySL, BuyTP, "", BuyMagic, 0, Blue);
		}
		if(ticket == -1)
		{
			error = GetLastError();
			Print("Îøèáêà îòêðûòèÿ îðäåðà BUY. " + ErrorDescription(error));
		}
	}
	
	if (ticket != -1)
	{
		Print("Îòêðûòî BUY íà " + Symbol() + " " + Period() + " îáúåìîì " + Lots + "!");
	}	
}

void OpenSell()
{
	int i;
	int Orders = OrdersTotal();
	double SellOpen;
	double SellTP = 0;
	double SellSL = 0;

	RefreshRates();
	
	SellOpen = Bid;
	if(TakeProfit != 0)
		SellTP = SellOpen - TakeProfit*Point;
	if(StopLoss != 0)
	{
		SellSL = SellOpen + StopLoss*Point;
	}
	
	datetime begin = TimeCurrent();
   int ticket = OrderSend(Symbol(), OP_SELL, Lots, SellOpen, Slippage, SellSL, SellTP, "", SellMagic, 0, Red);

	int error;
	if (ticket==-1)
	{
		//error=GetLastError();
		//Print("SELL error(",error,"): ",ErrorDescription(error));
		while(ticket == -1 && TimeCurrent() - begin < 20)
		{
			error = GetLastError();
			Print("Îøèáêà îòêðûòèÿ îðäåðà SELL. " + ErrorDescription(error));
			Sleep(100);
			Print("Ïîâòîð");
			RefreshRates();

			SellOpen = Bid;
			if(TakeProfit != 0)
				SellTP = SellOpen - TakeProfit*Point;
			if(StopLoss != 0)
			{
				SellSL = SellOpen + StopLoss*Point;
			}

		    ticket = OrderSend(Symbol(), OP_SELL, Lots, SellOpen, Slippage, SellSL, SellTP, "", SellMagic, 0, Red);
		}
		if(ticket == -1)
		{
			error = GetLastError();
			Print("Îøèáêà îòêðûòèÿ îðäåðà SELL. " + ErrorDescription(error));
		}
	}

    if (ticket != -1)
   	{
		Print("Îòêðûòî SELL íà " + Symbol() + " " + Period() + " îáúåìîì " + Lots + "!");
	}
}

void DoTrail()
{
	double TickSize = 0;
	if(Digits == 5)
	{
		TickSize = 0.00005;
	}
	else
	{
		TickSize = 0;
	}
	for (int i=0; i < OrdersTotal(); i++) 
	{
		OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

		if (OrderSymbol() == Symbol())
		{		  
			if(OrderType() == OP_BUY)
			{
				if(OrderMagicNumber() == BuyMagic)
				{
					double newstop = (Bid - MathMod(Bid, TickSize)) - (TrailingStop*Point - MathMod(TrailingStop*Point, TickSize));
					
					if(newstop > OrderOpenPrice() && (OrderOpenPrice() > OrderStopLoss() || OrderStopLoss() == 0))
					{
						if(!OrderModify(OrderTicket(), OrderOpenPrice(), newstop, OrderTakeProfit(), 0, Pink))
						{
							Print("Íå ïîëó÷èëîñü ìîäèôèöèðîâàòü îðäåð ¹" + OrderTicket() + ". Îøèáêà¹" + GetLastError());
						}
					}
					else if (OrderStopLoss() > OrderOpenPrice() && newstop - OrderStopLoss() >= TrailingStep*Point)
					{
						if(!OrderModify(OrderTicket(), OrderOpenPrice(), newstop, OrderTakeProfit(), 0, Pink))
						{
							Print("Íå ïîëó÷èëîñü ìîäèôèöèðîâàòü îðäåð ¹" + OrderTicket() + ". Îøèáêà¹" + GetLastError());
						}
					}
				}
			}
			else if (OrderType() == OP_SELL)
			{
				if(OrderMagicNumber() == SellMagic)
				{
					newstop = (Ask - MathMod(Ask, TickSize)) + (TrailingStop*Point - MathMod(TrailingStop*Point, TickSize));
					if(newstop < OrderOpenPrice() && (OrderStopLoss() > OrderOpenPrice() || OrderStopLoss() == 0))
					{
						if(!OrderModify(OrderTicket(), OrderOpenPrice(), newstop, OrderTakeProfit(), 0 ,Pink))
						{
							Print("Íå ïîëó÷èëîñü ìîäèôèöèðîâàòü îðäåð ¹" + OrderTicket() + ". Îøèáêà¹" + GetLastError());
						}
					}
					else if(OrderStopLoss() < OrderOpenPrice() && OrderStopLoss() - (newstop) >= TrailingStep*Point)
					{
						if(!OrderModify(OrderTicket(), OrderOpenPrice(), newstop, OrderTakeProfit(), 0 ,Pink))
						{
							Print("Íå ïîëó÷èëîñü ìîäèôèöèðîâàòü îðäåð ¹" + OrderTicket() + ". Îøèáêà¹" + GetLastError());
						}
					}
				}
			}
		}
	}
}

void CloseAllSell()
{
	int i;
	int orders = OrdersTotal();
	bool result;
	datetime begin;
	
	if(orders > 0)
	{
		for(i = orders-1; i >= 0; i--)
		{
			if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) )
			{
				if(OrderSymbol() == Symbol() && OrderType() == OP_SELL && OrderMagicNumber() == SellMagic)
				{
					begin = TimeCurrent();
					result = OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Yellow);			// çàêðûâàåì âñå âñòðå÷íûå îðäåðà
					while(!result && TimeCurrent() - begin <= 30 && !IsTesting())
					{
						Sleep(100);
						RefreshRates();
						result = OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Yellow);			// çàêðûâàåì âñå âñòðå÷íûå îðäåðà
					}
					if(!result)
					{
						int error = GetLastError();
						Print("Îøèáêà çàêðûòèÿ îðäåðà SELL #" + OrderTicket() + " " + ErrorDescription(error));
					}
				}
			}
			else
			{
				Print("Íå óäàëîñü âûáðàòü îòêðûòûé îðäåð:" + ErrorDescription(error));
			}
		}
	}
}

void CloseAllBuy()
{
	int i;
	int Orders = OrdersTotal();
	bool result;
	datetime begin;
	
	if(Orders > 0)
	{
		for(i = Orders-1; i >= 0; i--)
		{
			if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES) )
			{
				if(OrderSymbol() == Symbol() && OrderType() == OP_BUY && OrderMagicNumber() == BuyMagic)
				{
					begin = TimeCurrent();
					result = OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Yellow);			// çàêðûâàåì âñå âñòðå÷íûå îðäåðà
					while(!result && TimeCurrent() - begin <= 30 && !IsTesting())
					{
						Sleep(100);
						RefreshRates();
						result = OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Yellow);			// çàêðûâàåì âñå âñòðå÷íûå îðäåðà
					}
					if(!result)
					{
						int error = GetLastError();
						Print("Îøèáêà çàêðûòèÿ îðäåðà BUY #" + OrderTicket() + " " + ErrorDescription(error));
					}
				}
			}
			else
			{
				Print("Íå óäàëîñü âûáðàòü îòêðûòûé îðäåð:" + ErrorDescription(error));
			}
		}
	}
}

int deinit()
{
	return(0);
}

Profitability Reports

USD/JPY Jul 2025 - Sep 2025
1.12
Total Trades 28
Won Trades 12
Lost trades 16
Win Rate 42.86 %
Expected payoff 0.96
Gross Profit 244.22
Gross Loss -217.33
Total Net Profit 26.89
-100%
-50%
0%
50%
100%
NZD/USD Jul 2025 - Sep 2025
1.08
Total Trades 22
Won Trades 13
Lost trades 9
Win Rate 59.09 %
Expected payoff 0.67
Gross Profit 194.70
Gross Loss -180.00
Total Net Profit 14.70
-100%
-50%
0%
50%
100%
EUR/USD Jul 2025 - Sep 2025
1.01
Total Trades 24
Won Trades 14
Lost trades 10
Win Rate 58.33 %
Expected payoff 0.08
Gross Profit 202.00
Gross Loss -200.00
Total Net Profit 2.00
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
0.82
Total Trades 14
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -1.02
Gross Profit 65.70
Gross Loss -80.00
Total Net Profit -14.30
-100%
-50%
0%
50%
100%
EUR/USD Oct 2025 - Feb 2026
0.67
Total Trades 50
Won Trades 30
Lost trades 20
Win Rate 60.00 %
Expected payoff -2.65
Gross Profit 267.40
Gross Loss -400.00
Total Net Profit -132.60
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
0.66
Total Trades 27
Won Trades 12
Lost trades 15
Win Rate 44.44 %
Expected payoff -3.76
Gross Profit 198.50
Gross Loss -300.00
Total Net Profit -101.50
-100%
-50%
0%
50%
100%
GBP/USD Jul 2025 - Sep 2025
0.58
Total Trades 27
Won Trades 15
Lost trades 12
Win Rate 55.56 %
Expected payoff -3.74
Gross Profit 139.00
Gross Loss -240.00
Total Net Profit -101.00
-100%
-50%
0%
50%
100%
USD/CAD Jul 2025 - Sep 2025
0.46
Total Trades 24
Won Trades 14
Lost trades 10
Win Rate 58.33 %
Expected payoff -3.28
Gross Profit 66.73
Gross Loss -145.48
Total Net Profit -78.75
-100%
-50%
0%
50%
100%
USD/CHF Jul 2025 - Sep 2025
0.45
Total Trades 24
Won Trades 11
Lost trades 13
Win Rate 45.83 %
Expected payoff -7.39
Gross Profit 146.75
Gross Loss -324.14
Total Net Profit -177.39
-100%
-50%
0%
50%
100%
AUD/USD Oct 2025 - Feb 2026
0.36
Total Trades 41
Won Trades 15
Lost trades 26
Win Rate 36.59 %
Expected payoff -8.07
Gross Profit 189.00
Gross Loss -520.00
Total Net Profit -331.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.29
Total Trades 13
Won Trades 5
Lost trades 8
Win Rate 38.46 %
Expected payoff -8.75
Gross Profit 46.20
Gross Loss -160.00
Total Net Profit -113.80
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
0.13
Total Trades 17
Won Trades 3
Lost trades 14
Win Rate 17.65 %
Expected payoff -14.37
Gross Profit 35.70
Gross Loss -280.00
Total Net Profit -244.30
-100%
-50%
0%
50%
100%
GBP/CAD Jul 2025 - Sep 2025
0.03
Total Trades 23
Won Trades 2
Lost trades 21
Win Rate 8.70 %
Expected payoff -12.62
Gross Profit 9.58
Gross Loss -299.95
Total Net Profit -290.37
-100%
-50%
0%
50%
100%

Comments