Shift on MA

Posted By: Fred7

Shift on MA - 09/12/19 21:24

I have an SMA that I shift 1 forward and it plots fine, but when I try the trade it doesn't like it.
Code
vars smaHS = series(SMA,20); \\is my series I use


when I plot:
Code
plot("SMA High",smaHS[1],0,BLUE); 
it shows it on the price curve and shifted 1 bar forward,

but when I try it as a condition:
Code
 if(Close>smaHS[1]) 
I get an POINTER:DOUBLE:LONG error.

Do I need to specify it as a double somewhere?

Thanx
Posted By: AndrewAMD

Re: Shift on MA - 09/13/19 00:53

I’m assuming Close is a series?

If so, you must dereference a particular element of it, like so:
Code
if(Close[0]>smaHS[1])

In other words, you cannot compare a vars to a var. You must compare a var to a var.
Posted By: Fred7

Re: Shift on MA - 09/13/19 15:06

Thanx AndrewAMD, makes sense yes.

Just want to ask, the numbers in [ ] specify how many bars back you want to look but with the MA I'm plotting
Code
plot("SMA High",smaHS[2],0,BLUE);
it does the shifting 2bars forward which is what I want, but when I do
Code
if(Close[1] > smaHS[2] && Close[2]<smaHS[2])
it does not look like it is taking the entries at the right place, or is the code correct for what I want to do?
Posted By: AndrewAMD

Re: Shift on MA - 09/13/19 15:20

Can you describe your intended entry conditions?
Posted By: Fred7

Re: Shift on MA - 09/14/19 07:37

On the chart there is a SMA that is shifted 2bars forward. When Close[1] is above the SMA and Close[2] should still be below SMA, then a condition is met
Posted By: AndrewAMD

Re: Shift on MA - 09/15/19 12:30

You just regurgitated your code instead of rewriting your entry conditions in a logical paragraph form, which I would have preferred. I say this because your description is possibly wrong, and I have no way to confirm this.

Anyways, if you set Verbose = 7 | DIAG, and set(LOGFILE), add various printf statements, and then read the logs in your log folder, you will be able to troubleshoot your script.

If you're still having trouble, post your **entire** script and not little snippets.
© 2024 lite-C Forums