You'd better search here or you google - many solution exists!

6691

44

Yes, I do know that. I have found many solutions for displaying some kinds of S/R levels but I couldnt have found this one Im interested in. I believe I would be able to put this into the code myself but I just need some idea to push me - not sure in this moment how to put this into the code this...

44

I did the hard way... Below is the code which SHOULD BE capable of doing what I described above...

However, it shows me error during backtest "Array out of Range." Unfortunately, I don't understand the explanation very well... I thought this line would solve it but it did not. (Bars > Number_of_candles)

Any help? (I read what the error means but I dont get it)

//+------------------------------------------------------------------+ //| support_resistance.mq4 | //| LJ | //+------------------------------------------------------------------+ #property copyright "LJ" #property link "lukas.janca@icloud.com" #property version "1.00" #property strict input int Number_of_candles = 15; //Number of candles which are necessary to create S/R levels int OnInit() { Alert("EA is ON"); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { Alert("EA is OFF"); } void OnTick() { int static NewBar = Bars; if(NewBar != Bars && Bars > Number_of_candles) { NewBar = Bars; double static level_high; int PS = Number_of_candles+1; Print("Level High = ", level_high); if(High[PS] >= High[PS-1] && High[PS] >= High[PS+1]) { if(PS-1 == 1) { level_high = High[PS]; } if(High[PS] >= High[PS-2] && High[PS] >= High[PS+2]) { if(PS-1 == 2) { level_high = High[PS]; } if(High[PS] >= High[PS-3] && High[PS] >= High[PS+3]) { if(PS-1 == 3) { level_high = High[PS]; } if(High[PS] >= High[PS-4] && High[PS] >= High[PS+4]) { if(PS-1 == 4) { level_high = High[PS]; } if(High[PS] >= High[PS-5] && High[PS] >= High[PS+5]) { if(PS-1 == 5) { level_high = High[PS]; } if(High[PS] >= High[PS-6] && High[PS] >= High[PS+6]) { if(PS-1 == 6) { level_high = High[PS]; } if(High[PS] >= High[PS-7] && High[PS] >= High[PS+7]) { if(PS-1 == 7) { level_high = High[PS]; } if(High[PS] >= High[PS-8] && High[PS] >= High[PS+8]) { if(PS-1 == 8) { level_high = High[PS]; } if(High[PS] >= High[PS-9] && High[PS] >= High[PS+9]) { if(PS-1 == 9) { level_high = High[PS]; } if(High[PS] >= High[PS-10] && High[PS] >= High[PS+10]) { if(PS-1 == 10) { level_high = High[PS]; } if(High[PS] >= High[PS-11] && High[PS] >= High[PS+11]) { if(PS-1 == 11) { level_high = High[PS]; } if(High[PS] >= High[PS-12] && High[PS] >= High[PS+12]) { if(PS-1 == 12) { level_high = High[PS]; } if(High[PS] >= High[PS-13] && High[PS] >= High[PS+13]) { if(PS-1 == 13) { level_high = High[PS]; } if(High[PS] >= High[PS-14] && High[PS] >= High[PS+14]) { if(PS-1 == 14) { level_high = High[PS]; } if(High[PS] >= High[PS-15] && High[PS] >= High[PS+15]) { if(PS-1 == 15) { level_high = High[PS]; } if(High[PS] >= High[PS-16] && High[PS] >= High[PS+16]) { if(PS-1 == 16) { level_high = High[PS]; } if(High[PS] >= High[PS-17] && High[PS] >= High[PS+17]) { if(PS-1 == 17) { level_high = High[PS]; } if(High[PS] >= High[PS-18] && High[PS] >= High[PS+18]) { if(PS-1 == 18) { level_high = High[PS]; } if(High[PS] >= High[PS-19] && High[PS] >= High[PS+19]) { if(PS-1 == 19) { level_high = High[PS]; } if(High[PS] >= High[PS-20] && High[PS] >= High[PS+20]) { if(PS-1 == 20) { level_high = High[PS]; } } } } } } } } } } } } } } } } } } } } } } }

Moderator

9641

Number_of_candles = 15 int PS = Number_of_candles+1; //PS=16

when you reach

if(High[PS] >= High[PS-17] && High[PS] >= High[PS+17])

PS-17 is [-1]

There is no such bar, so you get "array out of range"

44

Oh! How easy... Thank you very much! when I finish this one, I will upload it here for benefits of others

44

Tried to put it into the indicator to draw a line on the graph... I cannot figure it out how... again. Anybody? you might see the mistake immediately...

//+------------------------------------------------------------------+ //| test.mq4 | //| LJ | //+------------------------------------------------------------------+ #property copyright "LJ" #property link "lukas.janca@icloud.com" #property version "1.00" #property strict #property indicator_chart_window // v/mimo okno #property indicator_buffers 1 //množství buferů #property indicator_plots 1 //počet linií? //--- plot barsToProcess #property indicator_label1 "barsToProcess = 100" #property indicator_type1 DRAW_LINE #property indicator_color1 Green #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- indicator buffers double Buffer1[]; input int Number_of_candles = 15; int OnInit() { IndicatorShortName("S/R levels"); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,Buffer1); return(0); return(INIT_SUCCEEDED); } 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 counted_bars=IndicatorCounted(); int static NewBar = Bars; for(int i = 0; i < Bars; i++) { if(NewBar != Bars && Bars > Number_of_candles) { NewBar = Bars; double static level_high; int PS = Number_of_candles+1; if(High[PS] >= High[PS-1] && High[PS] >= High[PS+1] && PS >= 2) { if(PS-1 == 1) { level_high = High[PS]; } if(High[PS] >= High[PS-2] && High[PS] >= High[PS+2] && PS >= 3) { if(PS-1 == 2) { level_high = High[PS]; } if(High[PS] >= High[PS-3] && High[PS] >= High[PS+3] && PS >= 4) { if(PS-1 == 3) { level_high = High[PS]; } if(High[PS] >= High[PS-4] && High[PS] >= High[PS+4] && PS >= 5) { if(PS-1 == 4) { level_high = High[PS]; } if(High[PS] >= High[PS-5] && High[PS] >= High[PS+5] && PS >= 6) { if(PS-1 == 5) { level_high = High[PS]; } if(High[PS] >= High[PS-6] && High[PS] >= High[PS+6] && PS >= 7) { if(PS-1 == 6) { level_high = High[PS]; } if(High[PS] >= High[PS-7] && High[PS] >= High[PS+7] && PS >= 8) { if(PS-1 == 7) { level_high = High[PS]; } if(High[PS] >= High[PS-8] && High[PS] >= High[PS+8] && PS >= 9) { if(PS-1 == 8) { level_high = High[PS]; } if(High[PS] >= High[PS-9] && High[PS] >= High[PS+9] && PS >= 10) { if(PS-1 == 9) { level_high = High[PS]; } if(High[PS] >= High[PS-10] && High[PS] >= High[PS+10] && PS >= 11) { if(PS-1 == 10) { level_high = High[PS]; } if(High[PS] >= High[PS-11] && High[PS] >= High[PS+11] && PS >= 12) { if(PS-1 == 11) { level_high = High[PS]; } if(High[PS] >= High[PS-12] && High[PS] >= High[PS+12] && PS >= 13) { if(PS-1 == 12) { level_high = High[PS]; } if(High[PS] >= High[PS-13] && High[PS] >= High[PS+13] && PS >= 14) { if(PS-1 == 13) { level_high = High[PS]; } if(High[PS] >= High[PS-14] && High[PS] >= High[PS+14] && PS >= 15) { if(PS-1 == 14) { level_high = High[PS]; } if(High[PS] >= High[PS-15] && High[PS] >= High[PS+15] && PS >= 16) { if(PS-1 == 15) { level_high = High[PS]; } if(High[PS] >= High[PS-16] && High[PS] >= High[PS+16] && PS >= 17) { if(PS-1 == 16) { level_high = High[PS]; } if(High[PS] >= High[PS-17] && High[PS] >= High[PS+17] && PS >= 18) { if(PS-1 == 17) { level_high = High[PS]; } if(High[PS] >= High[PS-18] && High[PS] >= High[PS+18] && PS >= 19) { if(PS-1 == 18) { level_high = High[PS]; } if(High[PS] >= High[PS-19] && High[PS] >= High[PS+19] && PS >= 20) { if(PS-1 == 19) { level_high = High[PS]; } if(High[PS] >= High[PS-20] && High[PS] >= High[PS+20] && PS >= 21) { if(PS-1 == 20) { level_high = High[PS]; } } } } } } } } } } } } } } } } } } } } } Print("Level High = ", level_high); Buffer1[i]=level_high; } } return(rates_total); }

Hello guys,

I have a question about recognizing supports and resistance levels in MQL? My idea is this:

-input int checkbars = X; (in order to make it easy, lets imagine this variable is 21

-if 21st bars´ highs on each side (to the left and to the right on the graph) are above from the certain bar's high, it would draw a horizontal line on that price level which is highest

-Thus, the indicator would be checking from the bar 21 (considering 0 = current unclosed bar)

-by the variable checkbars we could change the sensitivity. Higher value – lower sensitivity and vice versa

-on the picture are the S/R levels. To explain further: the higher line would be where it is, if the “checkbars” would be 21 or less. If it was 22, then the indicator or function would also count in the next large bar penetrating this level. Thus, the line would not be created where it is… Also if we set the checkbars to 5, then the line would be created on the highest high on the visible graph in this picture

I believe it has some sense but I have to admit, that my programming skills finish right here and I have to ask for help - how would you make such an indicator? because of optimalization it is necessary to have the possibility to change the variable "checkbars", if it wasnt, I would just put this into endless conditions if(...) and would not bother you...

Any help much appreciated!

The difference from the standard ZigZag indicator is the following: instead of calculating new extremum points based on the number of bars, it uses the distance between the high and the low to calculate the extremum points. In addition, this distance is calculated dynamically on default and depends on price fluctuations for a selected period and the multiplier. The distance can be set as a fixed number. In addition, it displays the reversal line, reaching which the previous extreme point is fix

We present you an effective software solution for arbitrage between brokers. The Arbitrage on the market became widespread due to decentralization. There are many liquidity providers, whose quotes differ for various reasons. By tracking the dynamics of changes in the quotes of different brokers, it is possible to determine the delayed and leading brokers, thereby predicting the future prices of the delayed broker for a short time. Knowing these prices and using efficient built-in software filte

Does not support hedging orders on a single symbol on MT5 MultiMTCopier MT5Receiver - new and improved multi-terminal positions copier for your real/demo account, works faster, requires less, flexible in managing and upgrading, new information support. This Expert Advisor is designed for the MetaTrader 5 terminal, trades will be copied into this terminal. MultiMTCopier: The EA will copy all positions without delays Additionally integrated notification in situations requiring user attention

Fast Copy MT5 allows to copy trades between different MetaTrader 5 (netting)(hedge) and MetaTrader 4 accounts in any direction and amount, quickly and easily (without loading the system). Any type of copying is available MT5 —> MT5 MT5 —> MT4 MT4 —> MT5 MT4 —> MT4 * For any interaction with the MT4, it is necessary to additionally install Fast Copy MT4 Main functionalities One tool for sending and receiving transactions: [master] > [slave] operation mode can be selected in

This is an utility for automatic scaling of a chart and making at least 140 bars visible in it. This is necessary for a correct wave analysis according to the Bill Williams' strategy "Trading Chaos". The utility can be used on any timeframe available in МetaТrader 5. It draws a vertical line through the first bar the calculation starts from. This line allows you to see the probable starting point of the wave sequence along with a sufficient number of bars displayed in the chart. It also makes t

The main purpose of the indicator is to detect and mark trade signals on the histogram of the Awesome Oscillator according to the strategies "Trading Chaos, second edition" and "New Trading Dimensions". The indicator detects and marks the following trade signals: "Two peaks" - Divergence. The signal "Second wise-man" - third consequent bar of the Awesome Oscillator after its color is changed. The histogram crosses the zero line. The signal "Saucer".The indicator includes a signal block th

The PZ Day Trading indicator detects reversals in a zig-zag fashion, without repainting or backpainting. Based on breakouts of variable lengths, the indicator uses only price action to pick trades and reacts to the market very fast. The positional accuracy of its signals offers huge opportunity for profits, easily up to 80% winners. Amazingly easy to tradeChart statistics will help you to optimize your tradingIt works on every single timeframe without fine tuningThe indicator analyzes its own q

VirtualTradePad - is a contol panel for working with orders in МetaТrader 5 : buy, sell, buystop, buylimit, sellstop, selllimit, close, delete, modify, tralling stop. VirtualTradePad won 2nd prize in the "Best Control Panel in the MQL5 Language" Contest. The panel consists of 5 tabs. Demo versions: VirtualTradePad PositionsStyle VirtualTradePad Ordersstyle VirtualTradePad SignalsStyleDemo version of the panel - VirtualTradePad LiteProfit or Loss PadINFO PadYou can also try this panel for

This product is similar to Tick volume analizer Expert Advisor, however it is implemented as an indicator. Release of this product is stipulated by the fact, that it is not possible to run two EAs in the same window. Tick volume is equal to amount of ticks at the unit of time. There is direct correlation between tick volume and real amount of deals. Every change of the price is a result of a real request to perform a deal. Consequently, fewer requests we have, the less price changes we get, an

Informer for VPS - report on the state of your account via e-mail. Useful for controlling your Expert Advisors that run on a VPS or a dedicated computer. Information about open positions and last deals for a day, week, month or year grouped by currency pairs. Adjustable periodicity of reports and depth of deals included in the report. A possibility to add own comment to each report. You will receive reports on e-mail with specified periodicity: from 15 minutes to once a day. The reports are se

The Spread 2 Pair indicator visualizes moments of two instruments' convergence (collapse) start. Signals are not delayed so you can timely enter and exit the market. This indicator is developed for pairs trading and creation of your own trading system based on difference in movements of trading instruments. Unlike most of multi-currency indicators, the Spread Pair indicator does not load CPU, calculations are immediately performed, it is non-redrawable. Settings of every currency pair provi

The indicator of support and resistance levels. A very good helper, fits any style of trading. It has a lot of parameters for adjustment.

The economic calendar is made in the form of an Expert Advisor that downloads the data from one of the most popular Forex sites (forexfactory.com/calendar.php). The data is presented in two ways. The first (primary) is represented as icons with detailed information about the event. The second is displayed as a line with a news description. Economic Calendar downloads published news in real mode with the possibility to adjust the spacing of data validation and user-friendly customizable graphical

The Expert Advisor uses the strategy of trading the Fibonacci levels. As the basis for placing a grid, the EA uses the ZigZag indicator (included in the standard MetaTrader delivery). First, the EA determines the trend direction. To do that, according to the Dow theory, it uses the last two Highs and last two Lows of the ZigZag. If the last High is higher than the previous and the last Low is higher than the previous, the EA considers the trend to be ascending. If the last High is lower

The main purpose of the indicator is to determine and mark trade signals on the histogram of the Accelerator Oscillator, which were described by Bill Williams in his book "New Trading Dimensions". The list of signals: The buy signal when the indicator histogram is below the zero line. The sell signal when the indicator histogram is below the zero line.The sell signal when the indicator histogram is above the zero line. The buy signal when the indicator histogram is above the zero line. The

The script is intended for automatic placing of Sell Stop pending orders, Stop Losses and Take Profits on the user specified levels. This script is not that useful as "Virtual pending buy stop", since short positions are opened as Bid price crosses the levels. Thus spread widening is not dangerous. Nevertheless, you need to have this script to prevent unwanted hitting of the Stop Loss levels. Main Purposes: Automation of the process of placing the Sell Stop pending orders, Stop Losses and T

qAutoActivation indicator is one of the main components of Trading Chaos Expert trading expert panel. The indicator displays the current trend on the current timeframe. This is the first indicator that is attached to the chart and saved in the trading complex template. It defines what trading signals from the expert panel should be automated for market entry (bullish or bearish ones). When the trend changes, the indicator changes the line color and, at the same time, highlights the trading pane

IShift Lite is a lite version of IShift, and it doesn't include the tick chart. IShift Lite allows: perform trade operations directly from the depth of market with a "single touch"; automatically place Stop Loss and Take Profit; move position to breakeven; move Stop Loss along the price; automatically calculate the volume of an order depending on a fixed risk level or a fixed margin level.The program includes a visual help system. Note: the demonstration version downloaded via the "Demo

This is a panel for controlling the profit/loss in dollars, pips or % of balance. A new function for trailing profits has been implemented. The panel can be used as a virtual Stop Loss or Take Profit. It also features the emergency button - CLOSE ALL. You can also try the full version of the VirtualTradePad for mt5 panel, as well as the Profit or Loss for mt4 panel Other versions in this collection: VirtualTradePad for mt5 Digit Market Time Pad Market Time Pad Scalper PadMain f

The indicator is intended for determining the spread and swap size, the distance for setting stop orders and stop losses from the current price allowed and the risk per 1 point in the deposit currency. The indicator informs a trader about possible additional expenses and profits connected with transferring a position to the next trade session of the financial instrument. It also informs about the spread size and the distance of pending orders, stop loss and trailing from the current price. In a

The script is intended for automatic placing of Buy Stop pending orders, Stop Losses and Take Profits on the user specified levels. Main Purposes: Avoiding unwanted entering a long position in case of false hitting the level as a result of widening of the spread by a dealing center. Avoiding unwanted triggering of a Stop Loss in case a quote pierces a significant level (fractal) without further confirmation with the close price. Setting a necessary virtual order and entering the market in

Times & Sales is a famous (and old!) trading tool. However, it is not present in MetaTrader 5 as a built-in tool. DeltaTrader now presents this indicator for MetaTrader! It has the following characteristics: Two flag modes: FOREX and EXCHANGE FOREX: black color: last price = 1-Minute opening price / blue color: last price < 1-Minute opening price / green color: last price > 1-Minute opening price. EXCHANGE: black color: last price = between quotes / blue color: last price = bid price / gre

Safe Automatic is a safe MetaТrader 5 trading robot working autonomously on a VPS server. The good results are achieved on EURUSD. Trading Strategy The EA applies modified versions of a trend-following strategy, half-pyramiding, scalping, Elliott Wave method and speculating trading with a deposit protection. The EA switches the strategies automatically. The robot does not trade at night from 10 p.m. to 4 a.m. (server time). The robot was tested in the special tester on real ticks. Empirical e

The script creates account summary report in a separate window. The report can be created for all deals and on deals for selected financial instruments. It is possible to specify a time interval of calculation and save report to htm-file. The script creates account summary report in a separate window. The report can be created for all deals and for deals of the selected financial instruments. It is possible to specify a time interval of calculation and save report to htm-file. Input par

Does not support hedging orders on a single symbol on MT5 MultiMTCopier MT5Source - new and improved multi-terminal positions copier for your real / demo account, works faster, requires less, flexible in managing and upgrading, new information support. This expert is designed for terminal MetaTrader5 from which the position will be copied. MultiMTCopier: The EA will copy all positions without delays Additionally integrated notification in situations requiring user attention Buttons for re

HWAFM (the harmonic wave analysis of the financial markets) Harmonic trading involves searching for certain price patterns (specimens) and Fibo numbers in order to define highly probable price reversal points. The method is based on the assumption that trade patterns or cycles repeat themselves just like in real life. The main objective is to identify these patterns, as well as position entries/exits. The analyzer is based on a high degree of probability, which is confirmed by the price movemen

Trading Chaos Expert Lite is a light version of Trading Chaos Expert. In the Lite version it is not possible to receive the table of trading signals, automatically place pending orders based on them and maintain open positions for multiple symbols at the same time in one window. Only the Current Chart mode is available. In all other features the panel is fully consistent with the basic version of the Expert Advisor. This is, rather, a well thought out trader's assistant which is not easy to do

Exp COPYLOT CLIENT for MT5 is a copier for the МetaТrader 5 platform. It copies forex trades from any accounts. Including those from terminals МТ5 and МТ4. Setup Install the Expert Advisor in the terminal where you want to copy trades. Specify any text label name as pathRead, for example, "COPY". This should match the master terminal (to bind the two terminals). To copy trades, you need to install the free Master copier in the terminal from where you want to copy the trades: COPYLOT

Percent Crosshair is a powerful and easy percentage measure tool. Measure the chart percentage very quick! Don't waste your time anymore! Just attach the Percent Crosshair indicator in the chart, select crosshair mode at toolbars or press "Ctrl+F" and start using the crosshair as you always do! The percent measure will be next to the indicative price. Customize your indicator the way you want! There are 4 entry parameters: Positive % color: set the desired color when % is positive. Negat

The script allows users to easily close positions if their profit/loss reaches or exceeds a value specified in pips. Please set slippage value first. Sometimes some positions do not close due to high volatility of the market. Please set larger slippage or restart the script.