Loop problem in MTF indicator

 

Hi All,

I seem to have a loop problem in Start(), possibly with return(0) statement(s) placement.

(Hopefully the iBarShift function works correctly !)

I want to display, in the same window, 4 TFs (say M1, M5, M15 and M30) of CSS display with 8 major currencies.

What I seem to get is only the first display in M1 for the chart and the table... after waiting for some minutes, a drawn out chart becomes visible stretched over all TF spaces but which is flat, i.e., not being updated.

Can anyone help here?

Thanks,

Athar.

Files:
 
 
WHRoeder:
Don't double post. Previously asked and answered. Only first instance of chart appears, then disappears with change of TF - MQL4 forum


This is NOT a double post. If you recall (as you incorrectly do here), the problem, as I stated above, lies with the additional code I wrote MYSELF: the loop, and perhaps iBarShift statement. Of course there could be other logical inconsistencies, which is the point of my post.

And NO, you certainly did not answer then, besides lecturing about where to look. Never provided any code, despite saying you are.

What gives you the gall to come back and stop me, when you did nothing for me in the first place?

Who are you, anyway, besides a 1973 relic? What gives you the right to harass anyone, unless you own this site, which you don't ?

If you cannot help, keep your peace. Don't discourage other helpful folks, and keep your lonely real life to yourselves !

 

I took a look at your indicator, and really, if you were asking for help when not understanding how some function of mql4 works or how to code a certain logic is one thing, asking for somone to debug a several hundred line program with multiple custom functions for you for free is something else entirely.

You said hopefully the iBarShift function works correctly, does that mean you have not even tested it ? How much other untested code do you have in that program ? it could take someone hours, even days to go through all that code and test it and debug it.

It appears to be a program written by someone else with several other peoples functions incorporated into it and then an attempt to modify it by you, did it work correctly before you modified it ? If it did why dont you start by isolating your own code from it, then introduce small changes one at a time then see if it still works each time. Create test scripts to test your own code to be sure what you did actually does what you intended. If you did write some code that doesn't appear to work the way you expected, and you have tested it to the best of your ability but still can't find the problem with it, post your own code here and tell us what you were trying to do, and you will probably get some help with it. Alternatively I would suggest if you want that entire thing debugged, post it in the jobs section and pay someone to do it. People seem willing to do things suprisingly cheap in the jobs section.

 
SDC:

I took a look at your indicator, and really, if you were asking for help when not understanding how some function of mql4 works or how to code a certain logic is one thing, asking for somone to debug a several hundred line program with multiple custom functions for you for free is something else entirely.

.............................


SDC,

Thanks for your detailed reply. I have tested the code dozens of times as you suggested.

The problem is isolated to the Start()- because all other modules/codes I left unchanged.

1. See picture, and the Start() code portion below. My changes are highlighted in RED.

Again, the changes I made in the Start() code is adding a for...j loop for the 4TFs and changing, before Start() in declarations above it, the single input extern variable for TF input, now commented out, to a global string variable for 4 TFs, PeriodsToTrade- set for now to {M1, M5, M15, M30}.

Also, parametrized the SetIndexShift (for horizontal shift per TF of CSS chart) and horizontalOffset for the CurrencyTable (text) to work with the j loop.


2. The problem is that I get only the first TF, M1, display with CSS chart and the Table. With time passing, this chart covers entire 4 TF window space, instead of displaying the other 3 TF CSS/Tables.

3. So, IMHO, it is much less complicated than scanning hundreds of line of code- the problem is the Start() code loop. The original single TF code works fine. See here, with single TF version updated to v8, with minor bugs.

http://www.stevehopwoodforex.com/phpBB3/viewtopic.php?f=45&t=629

For some experienced guy like you, this cannot be a big enough task for me to go to the Job Board ! Re: the iBarShift, if you take a look, it also ought to be obvious if it is erroneous within the loop.

4. If you have the time, kindly do take a look, and give me your quick feedback. It's tough for me as a newbie, but I cannot imagine it is rocket science for a moderate MQL4 programmer. I have no problem paying $25-30 for this fix, but from the Job Board the form filling is pretty onerous !

Regards,

Athar.

MTF CSS indi display only in first TF, distorts over time

//------------ Main routine. Loops for 4 TFs. RED highlights are my own additions to single loop TF code that works.



//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int j;

int limit;


for ( j=0; j<4; j++ ) //4 loops for 4 TFs.


{

int counted_bars = IndicatorCounted();

//---- check for possible errors

if (counted_bars < 0) return(-1);

//---- the last counted bar will be recounted

if (counted_bars > 0) counted_bars -=10 ; // change to counted_bars -- ?



limit = Bars - counted_bars;



if ( maxBars > 0 )

{

limit = MathMin (maxBars, limit);

}



for (int k = 0; k < CURRENCYCOUNT; k++ ) //changed to variable k from i to avoid confusion.

{

SetIndexStyle( k, DRAW_LINE, STYLE_SOLID, 2, currencyColors[k] );

SetIndexShift( k, -30 +j*15); // shifts above chart by bar units

}



RefreshRates(); // See def, refreshes SetIndexStyle plot for every bar, maxbars=20

horizontalOffset= 560 -j*180; // For ShowCurrencyTable, the TF text labels column, 560,380,200,20rightmost pixels.

timeFrame = PeriodsToTrade[j]; //Relate prev single input TF to MTF input string.

userTimeFrame = PERIOD_D1;

if ( autoTimeFrame )

{

userTimeFrame = Period();

}

else

{

                if ( timeFrame == "M1" ) userTimeFrame = PERIOD_M1;

                else if ( timeFrame == "M5" ) userTimeFrame = PERIOD_M5;

                else if ( timeFrame == "M15" ) userTimeFrame = PERIOD_M15;

                else if ( timeFrame == "M30" ) userTimeFrame = PERIOD_M30;

                else if ( timeFrame == "H1" ) userTimeFrame = PERIOD_H1;

                else if ( timeFrame == "H4" ) userTimeFrame = PERIOD_H4;

                else if ( timeFrame == "D1" ) userTimeFrame = PERIOD_D1;

                else if ( timeFrame == "W1" ) userTimeFrame = PERIOD_W1;

                else if ( timeFrame == "MN" ) userTimeFrame = PERIOD_MN1;

        }

for ( int y =limit-1; y>=0;y-- ) // y is chart bar counted; index 0 to Bars-1. MODIFIED i variable to y: i now refers to iBarShift

{

int index;

double diff = 0.0;

ArrayInitialize(currencyValues, 0.0); //?

int i = iBarShift( NULL, userTimeFrame, Time[y],True)+1; // +1 is delay to not ask for future price.

// i is now the (current)bar shift.

// NOTE: Define i locally ! (e.g., differentiate from k loop above.)

// Need iBarShift because in MTF, bar shift =y can't be used with tf != Period(),

//current (MT4 chart)period. Bars form differently in each TF.

// Calc Slope into currencyValues[]

calcCSS( userTimeFrame, i );



if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "USD" ) != -1 ) ) || ( !showOnlySymbolOnChart && USD ) )

{

arrUSD[i] = currencyValues[0];

if ( diff == 0 ) diff += currencyValues[0]; else diff -= currencyValues[0];

}

if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "EUR" ) != -1 ) ) || ( !showOnlySymbolOnChart && EUR ) )

{

arrEUR[i] = currencyValues[1];

if ( diff == 0 ) diff += currencyValues[1]; else diff -= currencyValues[1];

}

if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "GBP" ) != -1 ) ) || ( !showOnlySymbolOnChart && GBP ) )

{

arrGBP[i] = currencyValues[2];

if ( diff == 0 ) diff += currencyValues[2]; else diff -= currencyValues[2];

}

if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "CHF" ) != -1 ) ) || ( !showOnlySymbolOnChart && CHF ) )

{

arrCHF[i] = currencyValues[3];

if ( diff == 0 ) diff += currencyValues[3]; else diff -= currencyValues[3];

}

if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "JPY" ) != -1 ) ) || ( !showOnlySymbolOnChart && JPY ) )

{

arrJPY[i] = currencyValues[4];

if ( diff == 0 ) diff += currencyValues[4]; else diff -= currencyValues[4];

}

if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "AUD" ) != -1 ) ) || ( !showOnlySymbolOnChart && AUD ) )

{

arrAUD[i] = currencyValues[5];

if ( diff == 0 ) diff += currencyValues[5]; else diff -= currencyValues[5];

}

if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "CAD" ) != -1 ) ) || ( !showOnlySymbolOnChart && CAD ) )

{

arrCAD[i] = currencyValues[6];

if ( diff == 0 ) diff += currencyValues[6]; else diff -= currencyValues[6];

}

if ( ( showOnlySymbolOnChart && ( StringFind ( Symbol(), "NZD" ) != -1 ) ) || ( !showOnlySymbolOnChart && NZD ) )

{

arrNZD[i] = currencyValues[7];

if ( diff == 0 ) diff += currencyValues[7]; else diff -= currencyValues[7];

}

if ( i == 1 )

{

ArrayCopy(currencyValuesPrior, currencyValues);

}

if ( i == 0 )

{

// Show ordered table

ShowCurrencyTable( userTimeFrame );

}

// Only two currencies, show background

if ( showOnlySymbolOnChart )

{

// Create background object

int windex = WindowFind ( shortName );

string objectName = almostUniqueIndex + "_diff_" + Time[y]; //loop var

if ( ObjectFind ( objectName ) == -1 )

{

if ( ObjectCreate ( objectName, OBJ_VLINE, windex, Time[y], 0 ) ) // loop var

{

ObjectSet ( objectName, OBJPROP_BACK, true );

ObjectSet ( objectName, OBJPROP_WIDTH, 8 );

}

}

// Determine background color

if ( MathAbs( diff ) > differenceThreshold )

{

// Check diff sign

double cssLong = currencyValues[getCurrencyIndex(StringSubstr(Symbol(), 0, 3))];

double cssShort = currencyValues[getCurrencyIndex(StringSubstr(Symbol(), 3, 3))];

if ( cssLong > cssShort )

ObjectSet ( objectName, OBJPROP_COLOR, colorDifferenceUp );

else

ObjectSet ( objectName, OBJPROP_COLOR, colorDifferenceDn );

}

else

{

// Below threshold

ObjectSet ( objectName, OBJPROP_COLOR, colorDifferenceLo );

}

}

}

return(0); // right location for it?

}

}

// end of main routine.
 
atharmian:


SDC,

Thanks for your detailed reply. I have tested the code dozens of times as you suggested.

The problem is isolated to the Start()- because all other modules/codes I left unchanged.

<CODE REMOVED>

Please read some other posts before posting . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.

 
RaptorUK:

Please read some other posts before posting . . .

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.


Simon,

Done as above. Sorry about that !

Athar.

 
atharmian:


This is NOT a double post. If you recall (as you incorrectly do here), the problem, as I stated above, lies with the additional code I wrote MYSELF: the loop, and perhaps iBarShift statement. Of course there could be other logical inconsistencies, which is the point of my post.

And NO, you certainly did not answer then, besides lecturing about where to look. Never provided any code, despite saying you are.

You need to go back and look at your other thread . . .

WHRoeder 2013.08.19 15:01

atharmian: I have modified this to display charts in 4 TFs at once

  for ( i = limit; i >= 0; i-- ){                            // i is the current chart bar
      :                                                      // Current chart's Period()
      calcCSS( userTimeFrame, i );
:
void calcCSS( int tf, int shift ){
   :
   for ( i = 0; i < symbolCount; i++){
      double slope = getSlope(symbolNames[i], tf, shift);   // Shift is for the tf.
:
Can't use shift=i if tf != Period. Go look at some MTF indicators.

You were being quoted . . . "atharmian: I have modified this to display charts in 4 TFs at once" WHRoeder never said he modified any code.

atharmian:

William,

From your first comment, "I have modified this to display charts in 4 TFs at once," to me meant that you did update code. You did not.

 
RaptorUK:

You need to go back and look at your other thread . . .

You were being quoted . . . "atharmian: I have modified this to display charts in 4 TFs at once" WHRoeder never said he modified any code.


Simon,

Is there a point to this nitpicking? Especially when my point with WHRoeder here simply was to ask him to not boss me around, if he could not help me (and he certainly did not from the previous similar thread.)

I understand you may want to defend your friend, but don't you think you could have used this time and effort to provide me with a solution to my problem (hopefully not difficult for you at all)? Could you still?

Regards,

Athar.

 
atharmian:


Simon,

Is there a point to this nitpicking? Especially when my point with WHRoeder here simply was to ask him to not boss me around, if he could not help me (and he certainly did not from the previous similar thread.)

I understand you may want to defend your friend, but don't you think you could have used this time and effort to provide me with a solution to my problem (hopefully not difficult for you at all)? Could you still?.

You made an accusation based on an incorrect assumption . . . I thought you might want to correct your accusation. I guess not . . .
 
RaptorUK:
You made an accusation based on an incorrect assumption . . . I thought you might want to correct your accusation. I guess not . . .

Ha ha ha... you guys just don't give up in your Sky-is-Falling mode.

Does such passive aggression really pay in real life, besides some moribund sense of satisfaction?

Alright, I made a mistake in a hurry, I apologize.

Now can you be kind enough to solve my problem?

Or will I have to say this time, "I guess not." I hope not.

:)

Athar.

Reason: