You didn't post a topic yet. Let us show you how to make your first topic and upload your favorite forex robot. Guide me

Skip to forum content

Pages 1

You must login or register to post a reply


Posts: 4
Please rate this topic
Current rating: 0
Votes: 0

Embed topic to your site

Finding Max/Min Indicator Values in Given Range

Topic: Finding Max/Min Indicator Values in Given Range

Hey, I am currently customizing an RVI indicator for eventual use in an EA.  I figured it would be easier to check my work if I can actually see the results before moving on to back-testing.

The basic idea is to take the last 300 bars of the RVI (an indicator without fixed max/min's) and determine & draw lines at RviMax, RviMin, RviMid (middle), and some other calculated levels.  Essentially I want to establish a recent RVI range without changing how the indicator naturally calculates/displays. This range should update in real-time, only changing if a new max/min is established (on bar close), or if the existing max/min turns older than 300 bars.

I think I am pretty close to the desired result.  The indicator will find the MaxRVI when loaded and will display that value in the buffer correctly for all previous bars up to 300.  However after the Max/Min's the values get a little crazy.  It seems for the very recent candles (about 0-30) RviMax will be set to ANY local peak (even if clearly below the actual 300 bar max) and will continue to post lower and lower values until it reaches 0.00.  Once the RVI returns to positive territory, RviMax begins to follow RVI back up again.
I cannot see why the actual max/min values in the array are ignored in favor of less extreme values for the most recent bars. I suspect this has something to do with how I set up the array (RVIArray) or with how I used ArrayMaximum/ArrayMinimum, but I can't say for sure. Does anyone have any idea?

I have attached the mql4 file and picture outlining the issue.

Post's attachments

image__6.png 183.77 kb, 17 downloads since 2018-02-07 

R_RVI.mq4 13.16 kb, 12 downloads since 2018-02-07 


Re: Finding Max/Min Indicator Values in Given Range

After a closer look, it looks like the output in the Experts tab where I have all the data printing shows the correct value (or very close to it).  But the Data window shows incorrect data for the most recent bars. So i guess the real question is will an EA use the data-window values, or the buffer values in the log? My gut tells me the buffer values will be used, but since the variables being given for both are exactly the same I cannot say for sure. Any thoughts?

Print("MAX BAR ", RviMax_Bar);  //This Block prints all values to log
   Print("MIN BAR ", RviMin_Bar); 
   Print("RVI MAX ", RviMax);
   Print("RVI MIN ", RviMin);
   Print("RVI Range ",RviRange);
   Print("RVI ULimit ",RVI_UL);
   Print("RVI LLimit ",RVI_LL);
   Print("RVI MidLevel ",RVI_Mid);
   ExtRVI_MinBar_Buffer[x]=RviMin_Bar;  //This Block passes calculated values to buffers (not plotted)


3 (edited by R87.FX 03-01-18 17:27:09)

Re: Finding Max/Min Indicator Values in Given Range

Alright I made some good progress and figured I would share what I have.  The main thing was changing where the variables for the custom RVI levels are called.  I guess you can call a variable for a for() iteration such as “x” for counting in the middle of the code, but calling variables that will be used to pass data to buffers needs to be declared at the top.  Kind of seems obvious now, but there you go –lesson learned.  This fixed the problem with incorrect buffer values being shown for certain candles within the 300 bar range.  Now the buffer values are consistent for all bars, as they should be.

The drawing of the levels is still not how it should be,although the levels it draws when the indicator is loaded is correct.  Eventually the idea is to have the actual buffers do the drawing, or at the very least have the ObjectCreate Horizontal lines update when new highs/lows of the RVI are made or old ones expire.  Since the main goal for me is to use this in an EA, and since the buffers update correctly, this aesthetic task is not priority.  So, this will work when you call this indicator through iCustom() in an Expert Adviser.  But if you want to use the indicator visually you will need to remove and reload the indicator when lines need to be redrawn.

Also worth noting are a few quirks with this indicator that have popped up.  First, when using this indicator for back-testing with an EA, it will load 3 or more versions of the indicator at the end (even if the back-test is in visual mode with this indicator already loaded).  I’m not sure if this is just something that happens at the end, or if the EA I have is actually using three versions of the indicator during the test.  The second quirk is that the back-tests using this indicator are very slooow.  A test period of 2 years took a good 10 hours to complete where as all of my custom EA’s with more standard indicators take 10 minutes TOPS.  So if anyone has any ideas of how I can make the code more efficient, I am all ears.

Anyway, I hope this helps someone out there and if anyone has any tips they would be greatly appreciated. 

[Final Note:  I have cleaned up the code a little bit, but this is still a work in progress.  Therefore there is some unused code in therefor features that have not been implemented yet or for testing purposes.]

Post's attachments

R_RVI.ex4 13.66 kb, file has never been downloaded. 

R_RVI.mq4 13.98 kb, file has never been downloaded. 


4 (edited by R87.FX 04-03-18 21:13:06)

Re: Finding Max/Min Indicator Values in Given Range

UPDATE: I made the levels update on each new candle so now it runs as it should.  I should note,though, that I wanted to do this with either ObjectSet or ObjectMove, but for now I am just deleting and redrawing each line on each new candle.  I have also added a DeInt function to properly remove the indicator after it is removed. The issue I mentioned before about multiple versions of this same indicator being used during expert testing was a mistake in the EA and not this indicator, so no worries there. I also think the slowness of the tests is an issue with the EA and not this indicator. I have also cleaned out a lot of the unnecessary code used for testing to make it slightly easier to read. One exception to this is measuring the direction bias (“DirBias”) of a trend based on the RVI values.  This is a feature that has not been built out yet.

Anyway, I think this custom indicator is pretty much complete except for a few possible changes here and there.  I think I will stop providing updates since I will be moving on to another portion of the overall project. I hope this helps some trader out there trying to tackle a similar problem.  Please feel free to use this code as your own, as a whole or in part. And if you are a beginner and have any questions specifically related to this indicator, please feel free to contact me. 

Final Note: While this indicator has performed well overall during my testing, I will have a much more experienced MQL4 programmer look over my code before I go live and I strongly suggest you do the same.  This is the first indicator I customized and I barely put any effort into error handling. Don’t lose money because of my laziness - do your due diligence!

Post's attachments

R_RVI.ex4 14.33 kb, file has never been downloaded. 

R_RVI.mq4 14.03 kb, file has never been downloaded. 


Posts: 4

Pages 1

You must login or register to post a reply

Recommended Forum Topics!

Sunmoon EA- (updated over $281,000 profit)

Scalper_GU- ( tested with over $10,700,000 profit)

Three moving averages EA- (updated over $650,000 profit)

Session Breakouts EA 2019- (updated over $2,900,000 profit)

probando el EA EAmymoneypro - ( tested with over $3,000,000 profit)

EA banyubiru 147, my first self-coding- (updated over $642,700 profit)

EA_PropatternFX_V3.1- ( tested with over $30,000 profit)

Trillion Dollar Pips - (tested with over 4,000% profit)

Forex Luxury EA- ( tested with over $164,000 profit)

EA- CSBL- ( tested with over $69,000 profit)

Profit alone is very profitable- (updated over $71,000 profit)

Renko scalper- (updated over $80,000 profit)

EA-Budak-Ubat-v1.51- (updated over $47,000 profit)

ea hokky- (updated over $459,000 profit)

Winner Fx Pro v2 - (updated over 15,700% profi)

need good setting- (updated over $78,000 profit)

Best Things In life Are Free - (tested with profit over 800%)

Renko EMA Robot v9.1 - (tested with over 1,300% profit)

Turbo Scalper EA- (updated over $360,000 profit)

af global - (tested with over $84,150 profit)

Grid Master EA- ( tested with over $283,100 profit)

EA- ( tested with over $20,700 profit)

EA's collection number 2- ( tested with over $39,000 profit)

EA FIBO- ( tested with over $15,300 profit)

EA MiFx V2.2- ( tested with over $293,700 profit)

No Sleep EA! Tested with 8900% Profit!

profit box v7- (updated over $34,700 profit)

Super Hacked Pro EA - Updated over 211,400% profit!

Found EA fix system EURUSD M30- (updated over $29,300 profit)

Moby-Dick v2.7_2- (updated over $150,000 profit)

Hello to you I have EA the profit- ( tested with over $20,500 profit)

Super Scalping EA - (tested with over 1,800% profit) 

Sofy Robot - ( tested with over $100,000 profit)

EA Laba-Laba- (updated over $7,500 profit)

new robot - (updated over 47,500% profit)

super profit EA robot for eurusd gbpusd-(tested with over1000% profit)

EA's collection number 3 - (tested with over 2,200% profit)

forexthaipop EA - updated - over 42,800% profit.

Cobweb EA - (tested with over 3,000% profit)

frorex line 7 ea - (tested with over 1200% profit)

AF SCALPER - updated - over 13,000% profit.

EA Combo (tested with over 2,900% profit) 

Mart EA - (tested with over 1000% profit)

Expert Advisor - (Envelopes - tested with over $93,000 profit)

SuperWinForexThai - (tested with over 3,500% profit) 

EU Profit - (tested with over 1,700% profit)

Test this Monkeypips v120 - updated - over 2,900% profit.

1 min scalper - (updated over 2,500% profi)

EA 5 Digit - (updated over 20,000% profi)

5 minute scalper - (updated over 3,400% profi)

robot antares - (updated over 1300% profit)

EA ej (Forex Robot) - (tested with over 3,800% profit)

Stochastic Oscillator EA Basic - (updated over 2,300% profit)

New Robot - (updated over 9,200% profit)

EA hobeet - (tested with over 2,400% profit)

ThunderBird Ea - (tested with over 1000% profit) 

AFGlobal Expert Advisor - (tested with over $84,150 profit)

EA Trump_s Golden Dream - (tested with over 1000% profit) 

Good EA (updated 148 000% profit)

EA free - (tested with over 1,600% profit)

Forex Robot! Updated! - - (tested with over 37,000% profit)

Dieser Roboter läuft Sehr gut - (tested with over 2,100% profit)

THE BEST EA IN THE WORLD - (tested with over 1,600% profit)

EA Tengri 1.4A MARTINGALE - (tested with over 1,300% profit)

New Forex Robot - (tested with over 3,300% profit)

El Bosonaro profitable Renko EA - (tested with over 1000% profit)

EUREKA V7.2 - (tested with over 5,200% profit)

Last Posts

  • 23/04: EA-Breeze ( very good ea )
  • 23/04: TSR 2018
  • 23/04: As each trader is different
  • 23/04: robot double ema
  • 23/04: EA fly higher v5
  • 22/04: New EA
  • 22/04: IO9
  • 22/04: EA- CSBL- ( tested with over $69,000 profit)
  • 22/04: Comparto mis EA
  • 22/04: New EA swingTrade
  • 22/04: EA_PropatternFX_V3.1- ( tested with over $30,000 profit)
  • 22/04: Trillion Dollar Pips - (tested with over 4,000% profit)
  • 22/04: Life Changer EA
  • 21/04: London Breakout EA
  • 21/04: Create Money everyday with EA Happy Fast Money
  • 21/04: Rainbow Indicator With Signal Arrow
  • 21/04: This will accurately increase your assets
  • 21/04: Broker choice process
  • 21/04: Forex line
  • 21/04: FBS bonus programs are scam
  • 21/04: Looking for a decompiler i have a prfotiable ea
  • 21/04: Forex Luxury EA- ( tested with over $164,000 profit)
  • 21/04: timeframe for different ea
  • 20/04: Do we know about oders, buy & sell stops?
  • 20/04: free forex scapling daily
  • Online Users & Stats

    • Total number of registered users: 31,904
    • Newest registered user: Mite
    • Total number of topics: 11,928
    • Total number of posts: 38,512

    Online users: 1,943 guests, 218 Members:

    007isrisk, adamvega, Addyson, admin, aghahaideralikhan, Ahmad_777, Ahmed Essam, ahmed_maneim, akunrahasiainstagram, alan.81, Alphonse Elponcho, amdpc93, Anass Remmal, andrescuartas69, Andrey Clover, andydrae67, Animali, Anthony Khoury, armycm48, arod3096, Ashrof Khalin, Auro, axel7969, ayman107a, b78sandeau, ball2goal, Bandeauman Gjc RG, bestkid321, Bhavesh Sankhala, bhaveshsx4, bittradinginvestor, bogdan.dima74, braga1, bugattitrader, bwadd100, Coolbro15, cosminb, cruelzhang, danidu1613, danixsanc, davbene74, deckardbcn, Denver Raubenheimer, Diego Rivera-Muñoz Jaúregui, dinkokaraval4ev, diwomartew, diy13245679,, Donovan Sissing, Douglas Millan, dvorynen, EAInspirer, Easy-Read, enaso, eric.charette, eskadra.m, etrader, farmabioq, feilang220, Felipe Adorno, ferranbvalores, fgamarrac, flsekme, Forex Stock Trading, Forex Trader, ForexBond, forexnfx, franck0naka, Fxmaster, Galassi Umberto, gatello2000, Geraldo Gaspar, geswanky, godscp87, gtreeby2, gwhite2203, Gys Burger, henroo, hertzognel36, hgerena, ian.kungu, ifilex, Invinci4, jaffarmsh, jameshill55, jaume1981, jbarrero22, jdeben66, Jean Trading, jmvr30i, JoakimKarlsson, Joe0013, joelgathoni, joemotho, john.solgaard, Joonas Klemetso, Jose Ferreira Nascimento, Jose Pereira, Josemari Fernandez Liencres Alarcon, joskerone, jozmik, jsoleg, judeekatherinexx, juris.gulans, jy00196721, jyameogo87, khaleel.mohamed, KingAriza, kozura, kris69one, Kyosuke Tagawa, lawrencetownsendnz, Leonardo Nery, leoncloete, linn14, machemitoccafa, machs_nochmal, MagerMoLcH4, mahesh.bhagwat999, maheshsavaliya900, Mardy777, MarianNick123, Martin Kirschner, mathisonrichard, mauran, Maurilio7, maxheadroom, mbutt74, medinaccl, Mhakimsedhi, mikeb4, Mite, mogumogu, moreenlawson71, morinocofx, mt4talkjbentz, murugeswaranb, muzzicato75, Nareshkumar Patel, Nehal Soni, neovo007, nesanherba, Neville Carr, newsfarda, nicouz, nileshpatel, Njabulo Malindzisa, nmail1251, NUwansrilal334, Ofer Maimoni, olegsbajuks, otomc, Paresh Shah, parmi99, pat.garal572, patrickkw, Paulo Roberto Velasco Harnés, paverman, pawelandrzej42, pitso2009, pook110, prsilvioalves, Raul IG, Razior, redking012, renolim.wg, reynier.punisher.barnard, rezapars, rgomezvinas, ricopernambucano, rockingrohitj, Rodrigo Rissato de Paula, rugira82, ryustar0211, samlum, sandesh, sasastephe, saviotrader, sergeik, shahinn, shereen.mikhail, siamiri2009, sivonaldomilanez, skarlos1991, sparco21, SrTrader, stefan78calcan, SuperItalianboy, tajjamal477, tanpcccbtl,, tatendamut, taw_in, tellanup, Thammarat Baokhao, TheChinaTown, Thomaslomax, tiabaa123, topaz790, tradingralf, Tron, umt4, Vilas Korke, vufx1972, WEALTHANAND, Wei Deng, why, willemdev, william.yc.hui, xirixiao, yahavuzan, yossivano, zaki2317, ZHANG, zjbcreate, Алексей Отмахов, عزالدين بالنور, สมบัติ แสนบุตร


    NOTE: Hacked or illegal versions of copyrighted Forex robots are highly prohibited on If you upload any illegal version of any copyrighted Forex robot, your forum account will be banned. No exceptions.


    IMPORTANT: is a public Forex forum, where forum members can upload open source Forex robots to share with other members. forum does not sell or rent Forex robots, and does not provide guarantee or support for the uploaded Forex robots! If you have any question about any Forex robot, please open a forum topic! If you have a question about your forum account, contact:


    Disclaimer - No representation is being made that any Forex account will or is likely to achieve profits or losses similar to those shown on backtests in this forum. In fact, there are frequently sharp differences between hypothetical performance results and the actual results subsequently achieved by any particular trading program. Hypothetical trading does not involve financial risk, and no hypothetical trading record can completely account for the impact of financial risk in actual trading. 
    All information on this forum is for educational purposes only and is not intended to provide financial advice. Any statements posted by forum members about profits or income expressed or implied, do not represent a guarantee. Your actual trading may result in losses as no trading system is guaranteed. You accept full responsibilities for your actions, trades, profit or loss, and agree to hold the MT4talk team and forum members of this information harmless in any and all ways.

    Copyright Forum Rules - Privacy Policy.