RSI Cross EA

Author: Copyright � 2007, MetaQuotes Software Corp.
Orders Execution
It automatically opens orders when conditions are reached
Indicators Used
Relative strength index
Miscellaneous
It issuies visual alerts to the screenIt plays sound alerts
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
RSI Cross EA
//+------------------------------------------------------------------+
//|                                                 RSI Cross EA.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

//---- Include
#include <stderror.mqh>
#include <stdlib.mqh>

//---- Extern Variables
extern int     RSI_Period        = 12;
extern int     RSISell           = 80;
extern int     RSIBuy            = 20;
extern int     applied_price = PRICE_CLOSE;

//---- Variables
double         RSICurrent,RSIPrevious;
int            counted_bars, nShift, limit, i;

//---- Prise de position
extern int     TakeProfit        = 15;
extern int     StopLoss          = 20;
int            MagicNumber       = 230307;
string         NameEA            = "RSI Cross EA";
double         myPrice, myStopLoss, myTakeProfit, myLots, PriceNextMove;
int            ticket, cnt, total, digits;
int            Slippage          =0;

//---- Optimisation des Lots
extern double  Lots              = 0.1;

//---  Debugage
extern bool    Debug;
int            OrderErr;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
   {
//---- Expert Advisor
      digits = MarketInfo(Symbol(),MODE_DIGITS);
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
   {
//----
   
//----
      return(0);
   }

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
   {
      counted_bars=IndicatorCounted();
//---- 
      if(counted_bars<0) 
         return(-1);
      if(counted_bars>0) 
         counted_bars--;
      limit=Bars;
//      for(i=0; i<limit; i++)
//         {
            RSICurrent = iRSI(NULL,0,RSI_Period,applied_price,0);
            RSIPrevious = iRSI(NULL,0,RSI_Period,applied_price,1);
//---- ALARM! ALARM!   
//---  Buy Alarm
            if(
            (RSICurrent >= RSIBuy
            && RSIPrevious < RSIBuy)
            )
               {
                  //ExtMapBuffer1[i] = Low[i] -nShift*Point;
                  Alert("RSI Cross EA Going for a BUY Trend Sesion ",RSICurrent," Price ",Close[1]," for ", Symbol(),"-",Period());
                  PlaySound("alert.wav");
//                  myLots = LotsOptimized();
                  myLots = Lots;
                  myPrice = MarketInfo(Symbol(), MODE_ASK);
                  myStopLoss = 0;
                  if ( StopLoss > 0 ) 
                     myStopLoss = myPrice - StopLoss * Point ;
                  myTakeProfit = 0;
                  if ( TakeProfit > 0 )
                     myTakeProfit = myPrice + TakeProfit * Point;
// Normalize all price / stoploss / takeprofit to the proper # of digits.
                  if (digits > 0)
                     {
                        myPrice = NormalizeDouble( myPrice, digits);
                        myStopLoss = NormalizeDouble( myStopLoss, digits);
                        myTakeProfit = NormalizeDouble( myTakeProfit, digits);
                     }
                  ticket=OrderSend( Symbol(), OP_BUY, myLots, myPrice, Slippage, myStopLoss, myTakeProfit, "FirstBuy", MagicNumber, 0, Green);
                  if (ticket > 0)
                     {
                        if (OrderSelect( ticket,SELECT_BY_TICKET, MODE_TRADES) )
                           {
                              if (Debug) 
                                 Print("BUY order opened : ", OrderOpenPrice());
                           }
                        else
                           {
                              OrderErr = GetLastError();
                              Print("Error opening BUY order : (" + OrderErr + ") " + ErrorDescription( OrderErr) );
                           }
                     }
               }
//---  Sell Alarm       
            if (
            (RSICurrent <= RSISell
            && RSIPrevious > RSISell)
            )
               {
                  //ExtMapBuffer2[i] = High[i] + nShift*Point;
                  Alert("RSI Cross EA Going for a SELL Trend Sesion ",RSICurrent," Price ",Close[1]," for ", Symbol(),"-",Period());
                  PlaySound("alert.wav");
                  myLots = Lots;
                  myPrice = MarketInfo(Symbol(), MODE_BID);
                  myStopLoss = 0;
                  if ( StopLoss > 0 ) 
                     myStopLoss = myPrice + StopLoss * Point ;
                  myTakeProfit = 0;
                  if ( TakeProfit > 0 )
                     myTakeProfit = myPrice - TakeProfit * Point;
// Normalize all price / stoploss / takeprofit to the proper # of digits.
                  if (digits > 0)
                     {
                        myPrice = NormalizeDouble( myPrice, digits);
                        myStopLoss = NormalizeDouble( myStopLoss, digits);
                        myTakeProfit = NormalizeDouble( myTakeProfit, digits);
                     }
                  ticket=OrderSend( Symbol(), OP_SELL, myLots, myPrice, Slippage, myStopLoss, myTakeProfit, "First Sell", MagicNumber, 0, Red);
                  if (ticket > 0)
                     {
                        if (OrderSelect( ticket,SELECT_BY_TICKET, MODE_TRADES) )
                           {
                              if (Debug) 
                                 Print("SELL order opened : ", OrderOpenPrice());
                           }
                        else
                           {
                              OrderErr = GetLastError();
                              Print("Error opening SELL order : (" + OrderErr + ") " + ErrorDescription( OrderErr) );
                           }
                     }
               }
//         }
//----
      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 ---