Log in or register to download this file!
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.
Download the files:
MT4talk members reviews.
This robot is tested REAL-TIME on the LQDFX Forex account.
You may want to open an LQDFX Forex account to get the same trading results!
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) ExtRVI_MaxBar_Buffer[x]=RviMax_Bar; ExtRVI_Max_Buffer[x]=RviMax; ExtRVI_Min_Buffer[x]=RviMin; ExtRVI_UL_Buffer[x]=RVI_UL; ExtRVI_LL_Buffer[x]=RVI_LL; ExtRVI_Mid_Buffer[x]=RVI_Mid;
(edited by R87.FX 03-01-18 09:27:09)
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.]
(edited by R87.FX 04-03-18 13:13:06)
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!
- Total number of registered users: 67,641
- Registered users today: 5
- Newest registered user: fexyfex
- Total number of topics: 11,670
- Total number of posts: 38,349
Online users: 4,521 guests, 210 Members:
35267775, abdogi, Abdul Goni, Abu Fateh, Abu Trader, adexlaw, admin, agunes, Ahmad AA, akinnx, Ali H Wolde, Alongkot Noichaiboon, amlcfs, andengmel, Anst, AnuKajorn, Anzer, arays, Arley Markiewicz, ary, Ashish Ramanandi, Babz, banca, bevanh, Bhimkanta Kandel, bit18, Blue devil, Borman2020, born1889, brolyssj2020, CAI, Cesarsr, chet, Chillies95, Chrity, Collin Smith, dada4k, Daily, Damouh, Denis Maxime, Deriv, dillyman219, Duyhai, EA Tester Team Manager, Eduardo Mauro, Edvard, elmina12, Elvis88, Émìr Ådhä Ibråhìm, Emir Rs, Eon, epifreak, eryk342003, ettienepretorius, expedite, facemedia, Fantastic4s, fexyfex, fmchawki, franck0naka, Francolegend, Frangran, FXlife, George Bayss, gerencia, getmoney84, globalalert, grx70j, GUILLE1177, guydesquartes, hamad, Harryz, Hasan Osama, HaVaTaMpA, Heckenlooper71, Herbert Oropesa, Herry Van Java, Hesham Hesham, hosseinabx816, İdil Kocman, ikida, Ilgizonith84, Indrajit Bhapkar, inspiration2u, ITCM, Ivanyiu9999, jairam.1983, jamesi1, janavas, Jason Sharpe, jiang, Joenathan, John Fitzgerald, jreffgrimm, Julianto, kaky, Kale, Kanaimba Ua Lucky, Katapult, kausa1990, Kgvikram, Khhasan9, kimfin, kkman168, Klausix, ks261, Kuatch, larryyam, laurent.teitgen, leonlaitl, Lerato's, LUCKNOTSKILL, Luis Hernández, Mahavindra Zaid Ifansyah, majujaya, Managerr TeamnClub, Martini, Masem, mates3000, Mathilde Mthld, megatronpr, menocino, Micael Salewski Aguiar, miccaluko, Milad, mkcell, Mmminatalk, MoHaMaDd, Mohammad Salehi, morakileneo, nawikjabi, neffy, neybug, Ngọc Minh, Nik Ahir, nj620903, Ntqndo1994, Nuno Amorim, ozkanim, ozumba, patriklb, paulwalker, Petr Čurda, Phetego, Pimook Chokdamrongsuk, pom, Poolhouse, pr-systems, psraju, ptitdiim, rabbaniazam2120, rainer3770, Raja67, Rajsi, Redzwang, Reza Roozbeh, rezababaee, Ricky Baptiste, Robin Daubner, Roman Mehmood, rprabhakaran123, runti, saad, sabseal, samhagin, sanjeewatechno, sanong1968, satheeshvalluru, sbm, SEKSON, serginhovgp, sjp974run, sjust2fast, Skhona, Slade, smorrison49, sombrero7, songq8888, suvuong, Tajiri01, Tasos Karas, Thamsanqa1236, thepcyber, Thitiwas Wattakawanich, Tolkien_12, tomato, Trader Allan, tskabilan, turlesito, TWJFL, Vlantag, voggi2000, waleman, walidshahbudin, Warta Pati, Wayne Barry, wolf1210, wuxianyan, xbrtrading, Yagami, yaxir, yildiz, ymindrags, yunmr2000, Zacharias Zack Papazachariou, zedeai, Zhiyong Fang, Zul Fattah, דרור וסרמן, ศุภสินธุ์ คลองน้อย
MT4talk is a User Generated Content website. All content uploaded to MT4talk by our users (MT4talk forum members) is User Generated Content. Please note that MT4talk doesn't sell Forex robots and does not provide support for the uploaded Forex robots. MT4talk only sells PRO membership. PRO membership is unlimited download access in every forum topic and forum posts.
We testing Forex robots in REAL-TIME! We testing some robots on a demo account but in real-time. We are not financial consultants and we can't push you to risk your money. We are just trying to find good market analysis solutions from different strategies to help our community.
CFTC RULE 4.41 – HYPOTHETICAL OR SIMULATED PERFORMANCE RESULTS HAVE CERTAIN LIMITATIONS. UNLIKE AN ACTUAL PERFORMANCE RECORD, SIMULATED RESULTS DO NOT REPRESENT ACTUAL TRADING. ALSO, SINCE THE TRADES HAVE NOT BEEN EXECUTED, THE RESULTS MAY HAVE UNDER-OR-OVER COMPENSATED FOR THE IMPACT, IF ANY, OF CERTAIN MARKET FACTORS, SUCH AS LACK OF LIQUIDITY. SIMULATED TRADING PROGRAMS, IN GENERAL, ARE ALSO SUBJECT TO THE FACT THAT THEY ARE DESIGNED WITH THE BENEFIT OF HINDSIGHT. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFIT OR LOSSES SIMILAR TO THOSE SHOWN.
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 or the MT4talk EA Tester Team 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.
Affiliates Disclaimer - The site may contain links to affiliate websites, and we receive an affiliate commission for any sign up that trade by you on the affiliate website using such links. Our affiliate partners includes the following: FXOpen, FBS, LQDFX, MyForexVPS.