| stevehopwoodforex.com https://www.stevehopwoodforex.com/phpBB3/ Print view |
|
| Need some help to sort out an error https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=831 |
Page 1 of 2 |
| Author: | s01 [ Sat Sep 22, 2012 8:28 pm ] |
| Post subject: | Need some help to sort out an error |
Hi again, I just cannot wrap my head around this seemingly insignificant error, but try as I may, I cannot get rid of it. Might help if some new eyes looked at it and, then I could bang my head on the desk for not seeing it. I have the 2 lines marked with the error, but its a : invalid integer number as parameter 2 for SetIndexDrawBegin function .... Thank's agin in advance for any help in this. Steve / s01 Code: Select all |
|
| Author: | NeoTrader [ Sat Sep 22, 2012 9:40 pm ] |
| Post subject: | Re: Need some help to sort out an error |
hi s01, Just took a quick look at your code, SetIndexDrawBegin needs that both parameters are integer... you defined TrendBuffer and LoBuffer as double. If it is possible try to set them as int and look what happens. You can also look in the mql documentation for type casting to see how mql casts the different types. If the type change does not work try the following (or vice versa): Since mql has not a conversion function for DoubleToInteger the only alternative is to write it yourself (eg. Code: Select all Code: Select all hope that one of this will help you to find a solution. happy weekend, NeoTrader - |
|
| Author: | gaheitman [ Sat Sep 22, 2012 9:48 pm ] |
| Post subject: | Re: Need some help to sort out an error |
SetIndexDrawBegin() expects a regular ol' number as the second parameter. You are passing an array. Take a look at the example in the help -- well, it's not a great example. Generally the function is used to keep the indicator from drawing until it has enough data (left to right) to show correct information. So, if you need at least 100 candles before you can calculate your value, you would use 100 as the second parameter. I usually leave these calls out entirely unless I need them to prevent a divide by zero error. George |
|
| Author: | garyfritz [ Sat Sep 22, 2012 11:51 pm ] |
| Post subject: | Re: Need some help to sort out an error |
That seems pretty convoluted. Why not just return(MathRound(dbl)); ? (Or MathFloor(), depending on what you want.) I'm pretty sure MQL will properly convert the double MathRound() return value to Integer, since the DoubleToInt return value is integer. If not, you could just assign MathRound(dbl) to an int and then return that. |
|
| Author: | s01 [ Sun Sep 23, 2012 3:36 am ] |
| Post subject: | Re: Need some help to sort out an error |
LOL, Guys, Now totaly confused ... I understand from the Empty4 documentation that the begin wants a number, but then in the sample it has text.... Copy/Paste from the Empty4 website void SetIndexDrawBegin(int index, int begin) Sets the bar number (from the data beginning) from which the drawing of the given indicator line must start. The indicators are drawn from left to right. The indicator array values that are to the left of the given bar will not be shown in the chart or in the DataWindow. 0 will be set as default, and all data will be drawn. Parameters: index - Line index. Must lie between 0 and 7. begin - First drawing bar position number. Sample: int init() { //---- 2 additional buffers are used for counting. IndicatorBuffers(3); //---- drawing settings SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3); SetIndexDrawBegin(0,SignalSMA); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2); //---- 3 indicator buffers mapping SetIndexBuffer(0,ind_buffer1); SetIndexBuffer(1,ind_buffer2); SetIndexBuffer(2,ind_buffer3); //---- name for DataWindow and indicator subwindow label IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")"); //---- initialization done return(0); } So .. remember a coder I am not, just a regular guy tryin to figure this Empty4 out. I did not write this code, its an indicator I have had for a long time. But that error always bugged me. So just trin to fix someone elses mess. The indicator as it is now works, just has that constant error message. So I want a number there? Or not? Very confusing in the documentation. If I place a number there,min number of bars counted or some such, then how do I recall to get the line drawn again? |
|
| Author: | garyfritz [ Sun Sep 23, 2012 4:47 am ] |
| Post subject: | Re: Need some help to sort out an error |
George is right. You passed an array (your buffers, TrendBuffer and LoBuffer) as the second parameter. The Empty4 doc says the second parameter is supposed to be "First drawing bar position number." So it wants the bar number you want to start drawing from, not an entire buffer. So if you called SetIndexDrawBegin(0, 23), that tells Empty4 to skip the oldest (left-most) 22 bars and start drawing buffer 0 on bar 23. (Note that this "count from the left" definition is the OPPOSITE of the normal Empty4 convention, where bar 0 is the NEWEST bar on the right of the chart.) I'm not sure why this indicator needs that. Maybe there's some initialization period where the indicator calculation returns wonky values, and it wants you to not start plotting until the values stabilize. I suspect you could just delete that line and it would probably work fine. |
|
| Author: | gaheitman [ Sun Sep 23, 2012 9:26 am ] |
| Post subject: | Re: Need some help to sort out an error |
Like many of the examples in the documentation, it isn't really helpful. I suspect the real code that they took the example from has this at the top (along with other externs): Code: Select all |
|
| Author: | NeoTrader [ Sun Sep 23, 2012 9:42 am ] |
| Post subject: | Re: Need some help to sort out an error |
hi gary, you're right...you could also use the math functions...but they still produce doubles...and maybe mql converts them to int (I'm not that sure what mql does at some times). In my solution ( as convoluted as it seems) I'm sure I have an int at the end. By the way...I also think that George is on the right track. As I said also in the first post, both values must be integer. I didn't look to close in the code and it was late...so I didn't realize that he uses the array instead of a value out of the array. It also makes much more sense to use a period value for this parameter. happy weekend, NeoTrader - |
|
| Author: | s01 [ Sun Sep 23, 2012 6:47 pm ] |
| Post subject: | Re: Need some help to sort out an error |
Well consesus was right, Code: Select all Will watch for the divide by zero error mentioned earlier, when we start to get some data flowing. Thanks again Guy's, Steve / s01 The next one won't be so easy. I have a few more things to try before I post it up. s01 |
|
| Author: | garyfritz [ Mon Sep 24, 2012 3:18 am ] |
| Post subject: | Re: Need some help to sort out an error |
Good, glad that worked out. The whole DoubleToInt() function should be unnecessary. Any competent and properly-implemented language should automatically convert the double to an int in any double-to-int assignment, including implicit conversions e.g. for passing a double for an int parameter to a function. If it doesn't do the conversion, it should flag a type mismatch error. If MQL doesn't do either of those, it's a horrific bug in the language implementation. And we know there aren't any bugs in Empty4... |
|
| All times are UTC | Page 1 of 2 |
|
Powered by phpBB® Forum Software © phpBB Limited |
|