Orders Execution
Indicators Used
0
Views
0
Downloads
0
Favorites
Profitability Reports
AUD/USD
Oct 2024 - Jan 2025
4.00 %
Total Trades
2
Won Trades
0
Lost trades
0
Win Rate
0.00 %
Expected payoff
-2755.00
Gross Profit
200.00
Gross Loss
-5710.00
Total Net Profit
-5510.00
-100%
-50%
0%
50%
100%
GBP/USD
Oct 2024 - Jan 2025
0.00 %
Total Trades
1
Won Trades
0
Lost trades
1
Win Rate
0.00 %
Expected payoff
-6260.00
Gross Profit
0.00
Gross Loss
-6260.00
Total Net Profit
-6260.00
-100%
-50%
0%
50%
100%
RSI-R2 EA Ver1.1-original
//+------------------------------------------------------------------+
//| |
//| RSI-R2.mq4 - Ver 1.1 @ 04/10/2007 by Bluto |
//| |
//| Rev 1.1 - Enhanced Money Mgmt & Optimized RSI Periods Per Pairs | |
//+------------------------------------------------------------------+
#property copyright "Bluto"
#property link "None"
extern double LotSize=10;
extern int Slippage=3;
extern double StopLoss=0;
extern double TakeProfit=700;
extern double RiskPercent=2.0;
extern bool UseMoneyMgmt=false;
extern bool BrokerPermitsFractionalLots = true;
extern int RSI_Period=4;
extern double RSI_Overbought_Value = 75.0;
extern double RSI_Oversold_Value = 25.0;
int MagicNumber=0;
int ticket;
int OpenBuyOrders=0;
int OpenSellOrders=0;
int BuyCount=0,SellCount=0;
int i;
bool Buy_Mode=false, Sell_Mode=false;
double RSI_Day_1=0, RSI_Day_2=0, RSI_Day_3=0, SMA200_Day3=0;
double MM_MinLotSize=0;
double MM_MaxLotSize=0;
double MM_LotStep=0;
double MM_Decimals=0;
double MM_OrderLotSize=0;
int MM_AcctLeverage=0;
int MM_CurrencyLotSize=0;
int init()
{
if (Symbol()=="AUDCADm" || Symbol()=="AUDCAD") {MagicNumber=200001;RSI_Period=5;}
if (Symbol()=="AUDJPYm" || Symbol()=="AUDJPY") {MagicNumber=200002;RSI_Period=7;}
if (Symbol()=="AUDNZDm" || Symbol()=="AUDNZD") {MagicNumber=200003;RSI_Period=6;}
if (Symbol()=="AUDUSDm" || Symbol()=="AUDUSD") {MagicNumber=200004;RSI_Period=4;}
if (Symbol()=="CHFJPYm" || Symbol()=="CHFJPY") {MagicNumber=200005;RSI_Period=4;}
if (Symbol()=="EURAUDm" || Symbol()=="EURAUD") {MagicNumber=200006;RSI_Period=2;}
if (Symbol()=="EURCADm" || Symbol()=="EURCAD") {MagicNumber=200007;RSI_Period=3;}
if (Symbol()=="EURCHFm" || Symbol()=="EURCHF") {MagicNumber=200008;RSI_Period=3;}
if (Symbol()=="EURGBPm" || Symbol()=="EURGBP") {MagicNumber=200009;RSI_Period=2;}
if (Symbol()=="EURJPYm" || Symbol()=="EURJPY") {MagicNumber=200010;RSI_Period=4;}
if (Symbol()=="EURUSDm" || Symbol()=="EURUSD") {MagicNumber=200011;RSI_Period=4;}
if (Symbol()=="GBPCHFm" || Symbol()=="GBPCHF") {MagicNumber=200012;RSI_Period=6;}
if (Symbol()=="GBPJPYm" || Symbol()=="GBPJPY") {MagicNumber=200013;RSI_Period=4;}
if (Symbol()=="GBPUSDm" || Symbol()=="GBPUSD") {MagicNumber=200014;RSI_Period=3;}
if (Symbol()=="NZDJPYm" || Symbol()=="NZDJPY") {MagicNumber=200015;RSI_Period=6;}
if (Symbol()=="NZDUSDm" || Symbol()=="NZDUSD") {MagicNumber=200016;RSI_Period=7;}
if (Symbol()=="USDCHFm" || Symbol()=="USDCHF") {MagicNumber=200017;RSI_Period=4;}
if (Symbol()=="USDJPYm" || Symbol()=="USDJPY") {MagicNumber=200018;RSI_Period=4;}
if (Symbol()=="USDCADm" || Symbol()=="USDCAD") {MagicNumber=200019;RSI_Period=2;}
if (MagicNumber==0) {MagicNumber = 200999;}
return(0);
}
int deinit()
{
return(0);
}
int start()
{
Calc_Money_Management();
SMA200_Day3 = iMA(NULL,PERIOD_D1,200, 0, MODE_SMA, PRICE_CLOSE, 1);
RSI_Day_1 = iRSI(NULL, PERIOD_D1, RSI_Period, PRICE_CLOSE, 3);
RSI_Day_2 = iRSI(NULL, PERIOD_D1, RSI_Period, PRICE_CLOSE, 2);
RSI_Day_3 = iRSI(NULL, PERIOD_D1, RSI_Period, PRICE_CLOSE, 1);
if (RSI_Day_1 < 65 && RSI_Day_2 < RSI_Day_1 && RSI_Day_3 < RSI_Day_2 && Close[1] > SMA200_Day3)
{
Buy_Mode=true;
} else {
Buy_Mode=false;
}
if (RSI_Day_1 > 35 && RSI_Day_2 > RSI_Day_1 && RSI_Day_3 > RSI_Day_2 && Close[1] < SMA200_Day3)
{
Sell_Mode=true;
} else {
Sell_Mode=false;
}
if (OpenBuyOrders == 1 && iRSI(NULL, PERIOD_D1, RSI_Period, PRICE_CLOSE, 1) > RSI_Overbought_Value)
{
CloseLongs(MagicNumber);
OpenBuyOrders = 0;
BuyCount=0;
}
if (OpenSellOrders == 1 && iRSI(NULL, PERIOD_D1, RSI_Period, PRICE_CLOSE, 1) < RSI_Oversold_Value)
{
CloseShorts(MagicNumber);
OpenSellOrders = 0;
SellCount=0;
}
//----- Count number of existing open buy & sell orders; update trailing stops.
OpenBuyOrders=0;
OpenSellOrders=0;
// Manage Paraolic SAR
for (i = 0; i <= OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == MagicNumber))
{
if (OrderType() == OP_BUY)
{
OpenBuyOrders++;
if ((iSAR(NULL,0,0.02,0.2,1) > OrderStopLoss()) && (Bid > iSAR(NULL,0,0.02,0.2,1)) && (OrderOpenPrice() < iSAR(NULL,0,0.02,0.2,1)) && (iSAR(NULL,0,0.02,0.2,1) > iSAR(NULL,0,0.02,0.2,2)))
{
OrderModify(OrderTicket(),OrderOpenPrice(),iSAR(NULL,0,0.02,0.2,1),OrderTakeProfit(),0,Blue);
Print("Order # ",OrderTicket()," updated at ",Hour(),":",Minute(),":",Seconds());
return(0);
}
}
if (OrderType() == OP_SELL)
{
OpenSellOrders++;
if ((iSAR(NULL,0,0.02,0.2,1) < OrderStopLoss()) && (Ask < iSAR(NULL,0,0.02,0.2,1)) && (OrderOpenPrice() > iSAR(NULL,0,0.02,0.2,1)) && (iSAR(NULL,0,0.02,0.2,1) < iSAR(NULL,0,0.02,0.2,2)))
{
OrderModify(OrderTicket(),OrderOpenPrice(),iSAR(NULL,0,0.02,0.2,1),OrderTakeProfit(),0,Blue);
Print("Order # ",OrderTicket()," updated at ",Hour(),":",Minute(),":",Seconds());
return(0);
}
}
}
}
//----- Generic order handler.
//----- If we have a new buy signal, close existing sell orders; if we have a new sell signal, close existing buy orders; reset order counters.
//----- Next, create new buy or sell order.
if (Buy_Mode==true && OpenBuyOrders==0)
{
if(OpenSellOrders > 0)
{
CloseShorts(MagicNumber);
OpenSellOrders = 0;
}
if(OpenBuyOrders == 0)
{
ticket = OpenPendingOrder(OP_BUY,MM_OrderLotSize,Ask,Slippage,Bid,StopLoss,TakeProfit,"RSI-R2",MagicNumber,0,Lime);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
else
{
OpenBuyOrders++;
}
}
}
if (Sell_Mode==true && OpenSellOrders==0)
{
if(OpenBuyOrders > 0)
{
CloseLongs(MagicNumber);
OpenBuyOrders = 0;
}
if (OpenSellOrders == 0)
{
ticket = OpenPendingOrder(OP_SELL,MM_OrderLotSize,Bid,Slippage,Ask,StopLoss,TakeProfit,"RSI-R2",MagicNumber,0,HotPink);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
else
{
OpenSellOrders++;
}
}
}
return(0);
}
//----- Order Processing Functions
void CloseLongs(int MagicNumber)
{
int trade;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==false)
continue;
if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
continue;
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Blue);
}//for
}
void CloseShorts(int MagicNumber)
{
int trade;
for(trade=OrdersTotal()-1;trade>=0;trade--)
{
if(OrderSelect(trade,SELECT_BY_POS,MODE_TRADES)==false)
continue;
if(OrderSymbol()!=Symbol()||OrderMagicNumber()!=MagicNumber)
continue;
if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
}//for
}
int OpenPendingOrder(int pType,double pLots,double pLevel,int sp, double pr, int sl, int tp,string pComment,int pMagic,datetime pExpiration,color pColor)
{
int ticket=0;
int err=0;
int c = 0;
int NumberOfTries = 10;
switch (pType)
{
case OP_BUY:
for(c = 0 ; c < NumberOfTries ; c++)
{
RefreshRates();
ticket=OrderSend(Symbol(),OP_BUY,pLots,Ask,sp,StopLong(Bid,sl),TakeLong(Bid,tp),pComment,pMagic,pExpiration,pColor);
if (ticket > 0) break;
err=GetLastError();
if(err==0)
{
break;
}
else
{
if(err==4 || err==137 ||err==146 || err==136) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
Print("Error Code= ", err);
break;
}
}
}
break;
case OP_SELL:
for(c = 0 ; c < NumberOfTries ; c++)
{
RefreshRates();
ticket=OrderSend(Symbol(),OP_SELL,pLots,Bid,sp,StopShort(Ask,sl),TakeShort(Ask,tp),pComment,pMagic,pExpiration,pColor);
if (ticket > 0) break;
err=GetLastError();
if(err==0)
{
break;
}
else
{
if(err==4 || err==137 ||err==146 || err==136) //Busy errors
{
Sleep(5000);
continue;
}
else //normal error
{
Print("Error Code= ", err);
break;
}
}
}
break;
}
return(ticket);
}
double StopLong(double price,int stop)
{
if(stop==0)
return(0);
else
return(price-(stop*Point));
}
double StopShort(double price,int stop)
{
if(stop==0)
return(0);
else
return(price+(stop*Point));
}
double TakeLong(double price,int take)
{
if(take==0)
return(0);
else
return(price+(take*Point));
}
double TakeShort(double price,int take)
{
if(take==0)
return(0);
else
return(price-(take*Point));
}
void Calc_Money_Management()
{
MM_AcctLeverage = AccountLeverage();
MM_MinLotSize = MarketInfo(Symbol(),MODE_MINLOT);
MM_MaxLotSize = MarketInfo(Symbol(),MODE_MAXLOT);
MM_LotStep = MarketInfo(Symbol(),MODE_LOTSTEP);
MM_CurrencyLotSize = MarketInfo(Symbol(),MODE_LOTSIZE);
if(MM_LotStep == 0.01) {MM_Decimals = 2;}
if(MM_LotStep == 0.1) {MM_Decimals = 1;}
if(BrokerPermitsFractionalLots == true)
{
if (UseMoneyMgmt == true)
{
MM_OrderLotSize = AccountEquity() * (RiskPercent * 0.01) / (MM_CurrencyLotSize / MM_AcctLeverage);
MM_OrderLotSize = StrToDouble(DoubleToStr(MM_OrderLotSize,MM_Decimals));
if (MM_OrderLotSize < MM_MinLotSize) {MM_OrderLotSize = MM_MinLotSize;}
if (MM_OrderLotSize > MM_MaxLotSize) {MM_OrderLotSize = MM_MaxLotSize;}
}
else
{
MM_OrderLotSize = LotSize;
if (MM_OrderLotSize < MM_MinLotSize) {MM_OrderLotSize = MM_MinLotSize;}
if (MM_OrderLotSize > MM_MaxLotSize) {MM_OrderLotSize = MM_MaxLotSize;}
}
}
else
{
if (UseMoneyMgmt == true)
{
MM_OrderLotSize = AccountEquity() * (RiskPercent * 0.01) / (MM_CurrencyLotSize / MM_AcctLeverage);
MM_OrderLotSize = MathRound(MM_OrderLotSize);
if (MM_OrderLotSize < MM_MinLotSize) {MM_OrderLotSize = MM_MinLotSize;}
if (MM_OrderLotSize > MM_MaxLotSize) {MM_OrderLotSize = MM_MaxLotSize;}
}
else
{
MM_OrderLotSize = LotSize;
if (MM_OrderLotSize < MM_MinLotSize) {MM_OrderLotSize = MM_MinLotSize;}
if (MM_OrderLotSize > MM_MaxLotSize) {MM_OrderLotSize = MM_MaxLotSize;}
}
}
return(0);
}
Comments
Markdown Formatting Guide
# H1
## H2
### H3
**bold text**
*italicized text*
[title](https://www.example.com)

`code`
```
code block
```
> blockquote
- Item 1
- Item 2
1. First item
2. Second item
---