Anyone got an idea how to work around this

Post Reply
dietcoke
Trader
Posts: 162
Joined: Tue Nov 15, 2011 9:59 pm

Anyone got an idea how to work around this

Post by dietcoke »

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) );
}
You do not have the required permissions to view the files attached to this post.
Image
User avatar
SteveHopwood
Owner
Posts: 9904
Joined: Tue Nov 15, 2011 8:43 am
Location: Misterton - an insignificant village in England. Very pleasant to live in.

Re: Anyone got an idea how to work around this

Post by SteveHopwood »

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
Read the effing manual, ok?

Afterprime is the official SHF broker. Read about them at https://www.stevehopwoodforex.com/phpBB3/viewtopic.php?p=175790#p175790.

I still suffer from OCCD. Good thing, really.

Anyone here feeling generous? My paypal account is always in the market for a tiny donation. pianodoodler@hotmail.com is the account.

To see The Weekly Roundup of stuff you guys might have missed Click here

My special thanks to Thomas (tomele) for all the incredible work he does here.
eigenvector
Trader
Posts: 20
Joined: Sat Jul 14, 2012 3:14 pm

Re: Anyone got an idea how to work around this

Post by eigenvector »

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) );
}
User avatar
lazypips
Trader
Posts: 16
Joined: Sun Jul 08, 2012 4:01 pm

Re: Anyone got an idea how to work around this

Post by lazypips »

Looks like GetMa is confused by the 7 days a week / the 5 trading days a week
Post Reply

Return to “Coders Hangout”