stevehopwoodforex.com
https://www.stevehopwoodforex.com/phpBB3/
Print view

Anyone got an idea how to work around this
https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?t=1775
Page 1 of 1
Author:  dietcoke [ Wed Apr 03, 2013 11:09 pm ]
Post subject:  Anyone got an idea how to work around this

I am using a shifted Moving average on the weekly timeframe (2 wk LWMA as used in more than one of the NB versions)

I am finding that my code is reading the wrong value for the average on some days of the week compared with the indicator displayed in the window.

This seems to have something to do with the fact that the shift appears to run from Wednesday to wednesday rather than monday to monday.

This code appears to be correct on Monday and tuesday

Code: Select all

SlowLWMA = GetMa(symbol,LongPeriod,2,1,MODE_LWMA,PRICE_OPEN  ,1);
And this works from wednesday to friday

Code: Select all

SlowLWMA = GetMa(symbol,LongPeriod,2,1,MODE_LWMA,PRICE_OPEN  ,0);

Code: Select all

double GetMa(string symbol,int tf, int period, int mashift, int method, int ap, int shift) {
	return(iMA(symbol, tf, period, mashift, method, ap, shift) );
}
Author:  SteveHopwood [ Wed Apr 03, 2013 11:21 pm ]
Post subject:  Re: Anyone got an idea how to work around this

I suddenly feel a lot better.

Umpteen times I have torn my hair out wondering why the ma values displayed in my DisplayUserFeedback() are not the same as those shown on the chart. I thought I was doing something wrong.

The fact that we are in the same boat does not help with a solution. It is just good to know that I (you) am not actually alone.

Isn't Crapql4 such fun? :evil:

Anyone here have a workaround solution like Gary's solution to the doubles thingy and CloseEnough()? The sort of solution that is included with every half-decent coding language ever written by a dense 14 year old but forgotten by those cowboys who wrote this crap?

:D
Author:  eigenvector [ Fri Apr 05, 2013 3:21 am ]
Post subject:  Re: Anyone got an idea how to work around this

I didn't see the iBarShift function being used. This is a must if you are referencing other timeframes or other symbols because the bar indexing does not match up. Basically this function returns the correct index for the timeframe you are attempting to reference. Try something like this:

Code: Select all

int start()
  {
   int    counted_bars=IndicatorCounted();
   if (Bars < 1) return(0);
   int i = Bars-counted_bars -1;
   string symbol = Symbol();
   int LongPeriod = PERIOD_W1;
   while (i >=0) {
      MABuffer[i] = GetMa(symbol,LongPeriod,2,1,MODE_LWMA,PRICE_OPEN  ,i);
      i--;
   }
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+


double GetMa(string symbol,int tf, int period, int mashift, int method, int ap, int shift) {
   int ishift = iBarShift(symbol, tf, Time[shift], false);   
   return(iMA(symbol, tf, period, mashift, method, ap, ishift) );
}
Author:  lazypips [ Thu Apr 11, 2013 12:30 pm ]
Post subject:  Re: Anyone got an idea how to work around this

Looks like GetMa is confused by the 7 days a week / the 5 trading days a week
All times are UTC Page 1 of 1