#Graal-CROSSmuvingi_v1

Author: Rosh

This script is designed to automatically execute trades on the MetaTrader platform based on a specific set of technical indicators. Here's how it works, in simple terms:

The script uses moving averages, which are like trend lines that smooth out price fluctuations over a period of time. It uses two moving averages: a faster one (reacts quickly to price changes) and a slower one (reacts more slowly).

The script also looks at momentum, which measures how quickly the price is changing.

The script watches for the following conditions:

  • Buy Signal: When the faster moving average crosses above the slower moving average, and the momentum is positive and increasing, it's considered a potential buying opportunity. The script looks at the current and previous values of these indicators to determine if this cross has occurred and if the momentum is indeed increasing. Additionally, the script has a "MomFilter", which needs to be exceeded by the momentum.

    Before placing a buy order, the script first closes any existing sell orders. Then, it places a buy order with pre-defined parameters, including the amount to trade, slippage (tolerance for price changes), and a take-profit level (the price at which the order will automatically close for a profit).

  • Sell Signal: Conversely, when the faster moving average crosses below the slower moving average, and the momentum is negative and decreasing, it's considered a potential selling opportunity. The same "MomFilter" applies but on the negative side, and the momentum is expected to decrease below that threshold.

    Before placing a sell order, the script closes any existing buy orders. It then places a sell order with similar parameters as the buy order, including a take-profit level.

The script also incorporates a mechanism to avoid placing orders on every single price tick. It checks whether a new bar has formed on the chart before evaluating the trading conditions. This helps prevent the script from overreacting to minor price fluctuations.

The script uses a "magic number" to identify its own trades, which allows it to manage and close only the orders that it has opened.

In summary, this script automatically monitors price trends and momentum, and enters buy or sell trades when specific conditions are met, aiming to profit from these movements while adhering to pre-set risk management parameters.

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
15 Views
0 Downloads
0 Favorites

Profitability Reports

GBP/USD Oct 2024 - Jan 2025
103.00 %
Total Trades 37
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 0.43
Gross Profit 521.90
Gross Loss -506.00
Total Net Profit 15.90
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
140.00 %
Total Trades 32
Won Trades 20
Lost trades 12
Win Rate 0.63 %
Expected payoff 3.55
Gross Profit 400.00
Gross Loss -286.50
Total Net Profit 113.50
-100%
-50%
0%
50%
100%
#Graal-CROSSmuvingi_v1
//+------------------------------------------------------------------+
//|                                            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=13;
extern int       SlowPeriod=34;
extern int       MomPeriod=14;
extern double    MomFilter=0.1;
extern double    PercentCapital=10.0;
extern double    Lots=0.1;
extern int       Slippage=3;
extern int       StopLoss=20;
extern int       TakeProfit=200;
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 ---