ExpertTrendStrenghtEMA

Author: mandorr@gmail.com
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicator
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
46.00 %
Total Trades 22
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -81.18
Gross Profit 1504.00
Gross Loss -3290.00
Total Net Profit -1786.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
37.00 %
Total Trades 28
Won Trades 6
Lost trades 22
Win Rate 0.21 %
Expected payoff -198.25
Gross Profit 3305.00
Gross Loss -8856.00
Total Net Profit -5551.00
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
93.00 %
Total Trades 19
Won Trades 8
Lost trades 11
Win Rate 0.42 %
Expected payoff -9.26
Gross Profit 2186.00
Gross Loss -2362.00
Total Net Profit -176.00
-100%
-50%
0%
50%
100%
ExpertTrendStrenghtEMA
// ExpertTrendStrenghtEMA.mq4
// Ñîâåòíèê

#property copyright   "mandorr@gmail.com"

extern int StopLoss=0;
extern int TakeProfit=0;
extern double Lots=1;
extern bool MoneyManagement=false;
extern int MarginPercent=20;


void start()
   {
   if (Bars<1000 || IsTradeAllowed()==false) return;
   int trend=0;
   double x1=TrendStrength(1);
   if (x1>0) trend++;
   if (x1<0) trend--;
   if (TotalBuy () >0 && trend<0) CloseBuy ();
   if (TotalSell() >0 && trend>0) CloseSell();
   if (TotalBuy ()==0 && TotalSell()==0 && trend>0) OpenBuy ();
   if (TotalBuy ()==0 && TotalSell()==0 && trend<0) OpenSell();
   }


double TrendStrength(int shift)
   {
   double x0, x1, x2, x3, x4, x5, x6, x7, sum;
   x0=iMA(NULL,0,11,0,MODE_EMA,PRICE_CLOSE,shift);
   x1=iMA(NULL,0, 5,0,MODE_EMA,PRICE_CLOSE,shift);
   x2=iMA(NULL,0,10,0,MODE_EMA,PRICE_CLOSE,shift);
   x3=iMA(NULL,0,15,0,MODE_EMA,PRICE_CLOSE,shift);
   x4=iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,shift);
   x5=iMA(NULL,0,25,0,MODE_EMA,PRICE_CLOSE,shift);
   x6=iMA(NULL,0,30,0,MODE_EMA,PRICE_CLOSE,shift);
   x7=iMA(NULL,0,40,0,MODE_EMA,PRICE_CLOSE,shift);
   sum=(x0-x1)+(x0-x2)+(x0-x3)+(x0-x4)+(x0-x5)+(x0-x6)+(x0-x7);
   return (sum/7);
   }


void CloseBuy()
   {
   for (int i=OrdersTotal()-1; i>=0; i--)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()!=Symbol() || OrderType()!=OP_BUY) continue;
      OrderClose(OrderTicket(),OrderLots(),Bid,2);
      }
   }


void CloseSell()
   {
   for (int i=OrdersTotal()-1; i>=0; i--)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()!=Symbol() || OrderType()!=OP_SELL) continue;
      OrderClose(OrderTicket(),OrderLots(),Ask,2);
      }
   }


void OpenBuy()
   {
   double lots=LotsCounting();
   double loss=0; if (StopLoss>0) loss=Ask-StopLoss*Point;
   double profit=0; if (TakeProfit>0) profit=Ask+TakeProfit*Point;
   if (OrderSend(Symbol(),OP_BUY,lots,Ask,2,loss,profit,"",0,0)==0)
      Print("Open a order failed with error #",GetLastError());
   }


void OpenSell()
   {
   double lots=LotsCounting();
   double loss=0; if (StopLoss>0) loss=Bid+StopLoss*Point;
   double profit=0; if (TakeProfit>0) profit=Bid-TakeProfit*Point;
   if (OrderSend(Symbol(),OP_SELL,lots,Bid,2,loss,profit,"",0,0)==0)
      Print("Open a order failed with error #",GetLastError());
   }


int TotalBuy()
   {
   int count=0;
   for (int i=0; i<OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()==Symbol() && OrderType()==OP_BUY) count++;
      }
   return (count);
   }


int TotalSell()
   {
   int count=0;
   for (int i=0; i<OrdersTotal(); i++)
      {
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if (OrderSymbol()==Symbol() && OrderType()==OP_SELL) count++;
      }
   return (count);
   }


double LotsCounting()
   {
   double lots=Lots;
   if (MoneyManagement)
      {
      lots=NormalizeDouble((MarginPercent*AccountFreeMargin()/100000),1);
      if (lots>10) lots=NormalizeDouble(lots,0);
      }
   if (lots<0.1) lots=0.1;
   return (lots);
   }

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