Non Repaint Indicator
non-repaint indicator for the MetaTrader 4 (MT4) terminal that generates arrows can be quite complex

Creating a non-repaint indicator for the MetaTrader 4 (MT4) terminal that generates arrows can be quite complex, as the key aspect is ensuring that the arrows don't repaint or disappear after the bar closes. Below is an example of a simple non-repaint arrow indicator written in MQL4. This script will generate buy and sell arrows based on the crossing of a moving average with the price.
Non-Repaint Arrow Indicator
//+------------------------------------------------------------------+
//| NonRepaintArrows.mq4 |
//| Copyright 2024, Your Name |
//| Example Source Code |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
// Input parameters
input int MA_Period = 14;
input int ArrowShift = 0;
input double ArrowDistance = 15;
// Indicator buffers
double BuyBuffer[];
double SellBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0, BuyBuffer);
SetIndexStyle(0, DRAW_ARROW);
SetIndexArrow(0, 233); // Code for up arrow
SetIndexBuffer(1, SellBuffer);
SetIndexStyle(1, DRAW_ARROW);
SetIndexArrow(1, 234); // Code for down arrow
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 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[])
{
int start = MathMax(prev_calculated - 1, 1);
for(int i = start; i < rates_total; i++)
{
// Calculate the moving average
double ma = iMA(NULL, 0, MA_Period, 0, MODE_SMA, PRICE_CLOSE, i);
// Check for buy signal (close crosses above MA)
if(close[i-1] < ma && close[i] > ma)
{
BuyBuffer[i] = low[i] - ArrowDistance * Point;
SellBuffer[i] = EMPTY_VALUE;
}
// Check for sell signal (close crosses below MA)
else if(close[i-1] > ma && close[i] < ma)
{
SellBuffer[i] = high[i] + ArrowDistance * Point;
BuyBuffer[i] = EMPTY_VALUE;
}
else
{
BuyBuffer[i] = EMPTY_VALUE;
SellBuffer[i] = EMPTY_VALUE;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
How the Indicator Works
Moving Average: This example uses a simple moving average (SMA) as a signal line. The indicator generates buy arrows when the price closes above the moving average and sell arrows when the price closes below it.
Non-Repainting: The non-repainting feature is ensured by checking the condition based on the previous closed candle (i-1) and the current candle (i). Since it only places arrows after the candle has closed, the arrows won't disappear or move once placed.
Arrow Placement: Arrows are placed at a certain distance above or below the candles, defined by ArrowDistance. This makes it visually clear when a signal is generated.
No Repaint: The key to non-repainting is the condition check using the previous bar. This way, the arrow is only drawn when the condition is true for a completed bar.
Usage
Stochastic Oscillator: The Stochastic Oscillator measures the momentum of price changes and offers non-repaint signals based on overbought and oversold conditions. Relative Strength Index (RSI): RSI provides non-repaint signals related to the strength of a market trend
Apply to Chart: To use this indicator, copy the code into the MetaEditor and compile it. After compilation, apply it to the desired chart in MT4.
Customization: You can adjust the MA_Period, ArrowShift, and ArrowDistance parameters as needed for your trading strategy.
This code should give you a solid starting point for creating a non-repaint arrow indicator in MT4. You can further enhance it by adding more sophisticated logic or additional filters.
To prevent this repainting, we must rewrite our script so that it does not use values that fluctuate during the realtime bar. This will require using values from a bar that has elapsed (typically the preceding bar), or the open price, which does not vary in realtime.
Below, we will explore the top 10 best Indicators used among traders.
1 - Moving Average (MA) ...
2 - Relative Strength Index (RSI) ...
3 - Moving Average Convergence Divergence (MACD) ...
4 - Bollinger Bands. ...
5 - Volume. ...
6 - Stochastic Oscillator. ...
7 - Fibonacci Retracement. ...
8 - Average True Range (ATR)
About the Creator
Pooja Verma
Forexwebstore.com Discover the Best Forex Indicators for a Simple Strateg. This page features key technical indicators for the most popular currency pairs in real time.



Comments
There are no comments for this story
Be the first to respond and start the conversation.