//+------------------------------------------------------------------+
//| MomentumPivot_Alert.mq4|
//| Copyright 2023, Trading Forum |
//| Custom Indicator for Scalping|
//+------------------------------------------------------------------+
#property copyright "YourForumName"
#property link "
http://yourforumlink.com"
#property version "1.00"
#property strict
//--- Indicator Settings
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
// Plot Arrows
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrLime
#property indicator_width1 2
#property indicator_label1 "Buy Signal"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrRed
#property indicator_width2 2
#property indicator_label2 "Sell Signal"
//--- Input Parameters
input int FastEMA_Period = 9; // Fast EMA Period (Short Term)
input int SlowEMA_Period = 21; // Slow EMA Period (Trend Filter)
input int RSI_Period = 14; // RSI Period
input int RSI_UpperLimit = 60; // Upper Threshold for Sell setup
input int RSI_LowerLimit = 40; // Lower Threshold for Buy setup
input double ProximityPips = 2.5; // How close price must be to Slow EMA (in pips)
//--- Buffers
double BuyBuffer[];
double SellBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, BuyBuffer);
SetIndexArrow(0, 233); // Arrow Up symbol
SetIndexBuffer(1, SellBuffer);
SetIndexArrow(1, 234); // Arrow Down symbol
Indicator_Name = "Momentum Pivot Tool";
return(INIT_SUCCESS);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration |
//+------------------------------------------------------------------+
int OnCalculate(const int &shifted, const int &prev_shifted, const int &prev_calculated)
{
int limit = ItemsInHistorySize;
if(prev_calculated == 0) limit = Bars - 1;
for(int i=limit; i>=0; i--)
{
// Fetch Indicator Values
double fastEMA = iMA(NULL, 0, FastEMA_Period, 0, MODE_EMA, PRICE_CLOSE, i);
double slowEMA = iMA(NULL, 0, SlowEMA_Period, 0, MODE_EMA, PRICE_CLOSE, i);
double rsiValue = iRSI(NULL, 0, RSI_Period, PRICE_CLOSE, i);
double currentPrice = Close
;
// Check Proximity (Convert Pips to Points based on digits)
double pointsAdjustment = Point * 10;
if(Digits == 3 || Digits == 5) pointsAdjustment = Point * 10;
else pointsAdjustment = Point;
bool isNearEMA = MathAbs(currentPrice - slowEMA) < (ProximityPips * 10 * Point);
// Logic for Buy Signal: Fast EMA > Slow EMA + RSI below threshold + Price near SL_EMA
if(fastEMA > slowEMA && rsiValue < RSI_LowerLimit && isNearEMA)
{
BuyBuffer = Low - (10 * Point); // Place arrow slightly below low
// Alert logic (only on the latest candle)
if(i == 0 && prev_calculated != 0) TriggerAlert("Buy Signal Detected!");
}
else BuyBuffer = EMPTY_VALUE;
// Logic for Sell Signal: Fast EMA < Slow EMA + RSI above threshold + Price near SL_EMA
if(fastEMA < slowEMA && rsiValue > RSI_UpperLimit && isNearEMA)
{
SellBuffer = High + (10 * Point); // Place arrow slightly above high
// Alert logic (only on the latest candle)
if(i == 0 && prev_calculated != 0) TriggerAlert("Sell Signal Detected!");
}
else SellBuffer = EMPTY_VALUE;
}
return(rates_total);
}
void TriggerAlert(string message)
{
static datetime lastAlert = 0;
if(Time[0] != lastAlert)
{
Alert(message, " on ", Symbol());
SendNotification(message); // Sends alert to mobile phone if configured
lastAlert = Time[0];
}
}
// Helper for calculation
int ItemsInHistorySize() { return Bars; }