//+------------------------------------------------------------------+
//| RSI and Moving Average EA |
//+------------------------------------------------------------------+
#property strict
input int rsi_period = 14; // Period for RSI
input int ma_period = 14; // Period for Moving Average
double CalculateRSI(int period);
double CalculateMA(int period);
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Cleanup
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double rsi = CalculateRSI(rsi_period);
double ma = CalculateMA(ma_period);
// Example: Buy signal if RSI < 30 and price above MA
if(rsi < 30 && Close[1] > ma)
{
// Buy logic here
}
// Example: Sell signal if RSI > 70 and price below MA
if(rsi > 70 && Close[1] < ma)
{
// Sell logic here
}
}
//+------------------------------------------------------------------+
//| Function to calculate RSI |
//+------------------------------------------------------------------+
double CalculateRSI(int period)
{
double rsi = iRSI(_Symbol, _Period, period, PRICE_CLOSE, 0);
return(rsi);
}
//+------------------------------------------------------------------+
//| Function to calculate Moving Average |
//+------------------------------------------------------------------+
double CalculateMA(int period)
{
double ma = iMA(_Symbol, _Period, period, 0, MODE_SMA, PRICE_CLOSE, 0);
return(ma);
}
//| RSI and Moving Average EA |
//+------------------------------------------------------------------+
#property strict
input int rsi_period = 14; // Period for RSI
input int ma_period = 14; // Period for Moving Average
double CalculateRSI(int period);
double CalculateMA(int period);
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
// Cleanup
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
double rsi = CalculateRSI(rsi_period);
double ma = CalculateMA(ma_period);
// Example: Buy signal if RSI < 30 and price above MA
if(rsi < 30 && Close[1] > ma)
{
// Buy logic here
}
// Example: Sell signal if RSI > 70 and price below MA
if(rsi > 70 && Close[1] < ma)
{
// Sell logic here
}
}
//+------------------------------------------------------------------+
//| Function to calculate RSI |
//+------------------------------------------------------------------+
double CalculateRSI(int period)
{
double rsi = iRSI(_Symbol, _Period, period, PRICE_CLOSE, 0);
return(rsi);
}
//+------------------------------------------------------------------+
//| Function to calculate Moving Average |
//+------------------------------------------------------------------+
double CalculateMA(int period)
{
double ma = iMA(_Symbol, _Period, period, 0, MODE_SMA, PRICE_CLOSE, 0);
return(ma);
}
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.