Perform calculation when my position changes  [SOLVED]

Questions about MultiCharts and user contributed studies.
monick
Posts: 19
Joined: 20 Nov 2015

Perform calculation when my position changes

Postby monick » 29 Dec 2017

This should be very simple. I just want to perform a calculation only when my position changes. I don't understand why the following wouldn't work.

Code: Select all

input: lambda(0.1);
input: zeropoint(100);
var: Centerpoint(zeropoint);

if currentcontracts <> currentcontracts[1] then begin;
centerpoint =  centerpoint * (1-lambda) + lambda * close;
end;


This doesn't seem to be doing anything in the backtest. It's just operating as if the lambda doesn't exist.
Further, rather than the close price in the above centerpoint formula, more accurately, I want to use the last price I traded at. Is there a keyword that will always generate the very last price that I traded at.

Thanks
Last edited by monick on 29 Dec 2017, edited 1 time in total.

User avatar
TJ
Posts: 6977
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 984 times
Been thanked: 1996 times

Re: Perform calculation when my position changes  [SOLVED]

Postby TJ » 29 Dec 2017

See post#1 and post#2
viewtopic.php?t=11713

monick
Posts: 19
Joined: 20 Nov 2015

Re: Perform calculation when my position changes

Postby monick » 29 Dec 2017

Thanks, edited...

User avatar
ABC
Posts: 581
Joined: 16 Dec 2006
Has thanked: 117 times
Been thanked: 327 times
Contact:

Re: Perform calculation when my position changes

Postby ABC » 30 Dec 2017

monick,

check this link and Henry's reply: viewtopic.php?f=1&t=51048&p=127428#p127415
You can find out if CurrentContracts and CurrentContracts[1] are giving you the value that you expect when positions are opened, changed or reversed by using the print reserved word for example.

Regards,

ABC

monick
Posts: 19
Joined: 20 Nov 2015

Re: Perform calculation when my position changes

Postby monick » 30 Dec 2017

ABC,

Thanks so much. That's all it needed.

Monick


Return to “MultiCharts”