stochastic_buy_sell_arrows
Download scriptThis tool is designed as a visual trading assistant for the MetaTrader platform, specifically created to identify potential "Buy" and "Sell" opportunities on a price chart. It automates the analysis of a technical indicator known as the Stochastic Oscillator, which helps traders determine whether a currency pair is currently overbought or oversold.
Core Logic and Functionality
The script monitors the market in real-time by tracking two specific movements within the Stochastic Oscillator:
1. Identification of Buy Signals (Oversold Conditions) The tool looks for moments when the price action suggests the asset may have been sold off too much. Specifically, it watches for a "crossover" where the indicator value moves from below a pre-defined "Oversold" threshold (the default is 20) to above it. When this specific shift occurs, the script places a Lawn Green arrow on the chart below the current price bar to signal a potential upward move.
2. Identification of Sell Signals (Overbought Conditions) Conversely, the tool monitors for moments when the asset may have been bought too aggressively. It watches for the indicator value to drop from above a pre-defined "Overbought" threshold (the default is 80) back down below it. When this happens, the script places a Deep Pink arrow on the chart above the price bar to signal a potential downward move.
Key Features for the User
- Visual Alerts: Instead of requiring the trader to watch the charts constantly, the script provides clear visual markers (arrows) at the exact moment the mathematical conditions are met.
- Multi-Channel Notifications: To ensure traders don't miss an entry point, the logic includes a notification system. When a signal is detected, the script can simultaneously trigger:
- Pop-up Alerts: A window notification on the trading platform.
- Email Alerts: A direct message sent to the user's registered email.
- Push Notifications: An alert sent directly to a mobile device.
- Smart Filtering: The script is programmed to ensure that it only sends one notification per candle. This prevents the system from "spamming" the user with multiple alerts if the price fluctuates rapidly within the same time frame.
- Customizable Parameters: Users can adjust the sensitivity of the indicator (KPeriod, DPeriod, and Slowing) and the specific thresholds for overbought/oversold levels to tailor the tool to different trading styles or specific currency pairs.
//+------------------------------------------------------------------+
//| Stochastic Buy Sell Arrows.mq4 |
//| Copyright 2016, ACB Forex Trading Solutions |
//| https://www.acbforextrading.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, ACB Forex Trading Solutions"
#property link "https://www.acbforextrading.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_color2 DeepPink
#property indicator_width1 1
#property indicator_width2 1
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
extern string Stochastic = "Configure Stochastic Settings";
extern int KPeriod = 5;
extern int DPeriod = 3;
extern int Slowing = 3;
extern int OverBought = 80;
extern int OverSold = 20;
extern string Alerts = "Configure Alerts";
extern bool PopUpAlert = true; //Popup Alert
extern bool EmailAlert = true; //Email Alert
extern bool PushAlert = true; //Push Notifications Alert
// UP and DOWN Buffers
double UP[];
double DOWN[];
// Distance of arrows from the high or low of a bar
int distance = 3;
double MyPoint;
datetime CTime;
int OnInit()
{
//--- indicator buffers mapping
//UP Arrow Buffer
SetIndexEmptyValue(0,0.0);
SetIndexStyle(0,DRAW_ARROW,0,EMPTY);
SetIndexArrow(0,233);
SetIndexBuffer(0,UP);
//DOWN Arrow Buffer
SetIndexEmptyValue(1,0.0);
SetIndexStyle(1,DRAW_ARROW,0,EMPTY);
SetIndexArrow(1,234);
SetIndexBuffer(1,DOWN);
//Auto Adjustment for broker digits
if (Digits()==5||Digits()==3){MyPoint=Point*10;} else{MyPoint=Point;}
CTime=Time[0];
//---
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
//--- delete an object from a chart
Comment("");
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---
Comment("www.ACBForexTrading.com");
int limit = rates_total;
int count=prev_calculated;
//Main function
for(int i=limit-count; i>=1;i--)
{
//Getting Stochastic buffer values using the iCustom function
double Stoch1 = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,i);
double Stoch2 = iStochastic(NULL,0,KPeriod,DPeriod,Slowing,MODE_SMA,0,MODE_MAIN,i+1);
if(Stoch1>OverSold && Stoch2<OverSold)
{
UP[i]=Low[i]-distance*MyPoint;
if(CTime!=Time[0])
{
if(PopUpAlert){Alert(Symbol()," ","Buy Arrow");}
if(EmailAlert){SendMail(Symbol()+" Buy Arrow"+"","Buy Signal");}
if(PushAlert){SendNotification(Symbol()+" Buy Arrow"+"");}
CTime=Time[0];
}
}
if(Stoch1<OverBought && Stoch2>OverBought)
{
DOWN[i]=High[i]+distance*MyPoint;
if(CTime!=Time[0])
{
if(PopUpAlert){Alert(Symbol()," ","Sell Arrow");}
if(EmailAlert){SendMail(Symbol()+" Sell Arrow"+"","Sell Signal");}
if(PushAlert){SendNotification(Symbol()+" Sell Arrow"+"");}
CTime=Time[0];
}
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
Comments