Graal-FxProg_team

Author: Rosh

This script is an automated trading system for the MetaTrader platform. Here's how it works:

Overall Strategy:

The script aims to identify potential buying or selling opportunities based on the relationship between two moving averages (a "fast" one and a "slow" one) and a momentum indicator. Think of it as trying to catch trends early by looking for confirmation signals from these different indicators.

Key Components and their Logic:

  1. Input Parameters (Customizable Settings):

    • FastPeriod, SlowPeriod, MomPeriod: These are numbers that determine how far back the script looks when calculating the moving averages and the momentum. Shorter periods make the indicators more sensitive to recent price changes, while longer periods smooth out the data.
    • MomFilter: A threshold for the momentum. The momentum needs to be above this level to consider a buy and below the negative of this level to consider a sell. It acts as a filter to avoid trades based on weak momentum.
    • PercentCapital, Lots: Determine the size of the trades. Lots specifies a fixed size but this script does not use the PercentCapital to change the lot size.
    • Slippage: The maximum acceptable difference between the requested price and the actual price when the order is executed. It is a parameter of risk.
    • StopLoss, TakeProfit: These define how much the price needs to move against or in favor of the trade before it's automatically closed, limiting potential losses or securing profits.
    • ExpertMagicNumber: A unique identifier for the script's orders. This allows the script to manage only its own trades and not interfere with other trades.
  2. Moving Averages (MAs):

    • The script calculates two Exponential Moving Averages (EMAs): a "fast" EMA and a "slow" EMA. The "fast" EMA reacts more quickly to price changes than the "slow" EMA.
    • The script compares the current and previous values of the MAs.
  3. Momentum Indicator:

    • The script calculates the momentum of the price. Momentum is a measure of the speed of price change.
    • The script compares the current and previous values of the momentum indicator and uses MomFilter to determine if the momentum is strong enough.
  4. Trading Logic:

    • Buy Signal:
      • The script checks if the "fast" EMA is currently above the "slow" EMA, and was below it in the previous period (a "crossover"). This suggests an upward trend.
      • It also checks if the momentum is above a certain positive threshold (MomFilter) and is increasing (current momentum is greater than previous momentum). This confirms the upward trend.
      • If both conditions are met, the script closes any existing sell orders and opens a buy order.
    • Sell Signal:
      • The script checks if the "fast" EMA is currently below the "slow" EMA, and was above it in the previous period (a "crossover"). This suggests a downward trend.
      • It also checks if the momentum is below a certain negative threshold (-MomFilter) and is decreasing (current momentum is less than previous momentum). This confirms the downward trend.
      • If both conditions are met, the script closes any existing buy orders and opens a sell order.
  5. Order Management

    • Before opening a new order, the script closes the opposite order.

In Simple Terms:

The script is like a trend-following robot. It watches the price movements, calculates some averages and momentum, and tries to identify when a new trend is starting. If it thinks the price is going up, it buys. If it thinks the price is going down, it sells. It also includes basic risk management features like stop-loss and take-profit to protect against losses and secure gains.

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 indicatorMomentum indicator
2 Views
0 Downloads
0 Favorites

Profitability Reports

GBP/USD Oct 2024 - Jan 2025
18.00 %
Total Trades 80
Won Trades 73
Lost trades 7
Win Rate 0.91 %
Expected payoff -4.09
Gross Profit 73.00
Gross Loss -399.90
Total Net Profit -326.90
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
18.00 %
Total Trades 75
Won Trades 60
Lost trades 15
Win Rate 0.80 %
Expected payoff -3.55
Gross Profit 60.00
Gross Loss -326.40
Total Net Profit -266.40
-100%
-50%
0%
50%
100%
Graal-FxProg_team
//+------------------------------------------------------------------+
//|                                            Graal-FxProg_team.mq4 |
//|                                                             Rosh |
//|               http://www.investo.ru/forum/viewtopic.php?t=124777 |
//+------------------------------------------------------------------+
#property copyright "Rosh"
#property link      "http://www.investo.ru/forum/viewtopic.php?t=124777"

//---- input parameters
extern int       FastPeriod=5;
extern int       SlowPeriod=21;
extern int       MomPeriod=14;
extern double    MomFilter=0.004;
extern double    PercentCapital=10.0;
extern double    Lots=0.1;
extern int       Slippage=3;
extern int       StopLoss=10;
extern int       TakeProfit=10;
extern int       ExpertMagicNumber=2002;
int myBars;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int cnt;
  double curFastMA=iMA(NULL,0,FastPeriod,0,MODE_EMA,PRICE_CLOSE,1);
  double curSlowMA=iMA(NULL,0,SlowPeriod,0,MODE_EMA,PRICE_OPEN,1);
  double prevFastMA=iMA(NULL,0,FastPeriod,0,MODE_EMA,PRICE_CLOSE,2);
  double prevSlowMA=iMA(NULL,0,SlowPeriod,0,MODE_EMA,PRICE_OPEN,2);
  double curMom=iMomentum(NULL,0,MomPeriod,PRICE_CLOSE,1)-100.0;
  double prevMom=iMomentum(NULL,0,MomPeriod,PRICE_CLOSE,2)-100.0;
//----
   if (Bars!=myBars)
      {
      myBars=Bars;
      if (curFastMA>curSlowMA && prevFastMA<prevSlowMA && curMom>MomFilter && curMom>prevMom)
         {
         if (OrdersTotal()>0)
            {
            for (cnt=OrdersTotal()-1;cnt>=0;cnt--)
               {
               OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
               if (OrderType()==OP_SELL) {OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,White);Sleep(30000);}
               }
            }
         OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,Ask+TakeProfit*Point,"buy",ExpertMagicNumber,0,Blue);
         }
      if (curFastMA<curSlowMA && prevFastMA>prevSlowMA && curMom<-MomFilter && curMom<prevMom)
         {
         if (OrdersTotal()>0)
            {
            for (cnt=OrdersTotal()-1;cnt>=0;cnt--)
               {
               OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
               if (OrderType()==OP_BUY) {OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,White);Sleep(30000);}
               }
            }
         OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,0,Bid-TakeProfit*Point,"sell",ExpertMagicNumber,0,Red);
         }
      }
//----
   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 ---