简体   繁体   中英

Problem in converting Pinescript code to Metastock

In pine script, we can create a changing period simple moving average by:

( cum(close) - cum(close)[barssince(condition)] ) / barssince(condition)

However, on Metastock, the Ref function similar to [ ] in pine script, only accepts static period and not changing period like barssince.

How can I create a changing period moving average or changing period sum?

To avoid a lot of problems with the archaic MSFL, I recommend going to the MetaStock forum site, searching for the forum.dll and using the moving average function which accepts variable periods, eg

ExtFml("forum.VarMov",CLOSE,BarsSince(condition),S);

Otherwise, problems: MS struggles keeping the cum() accurate with anything other than integer values, and divide by zero errors (on the bar of the condition reset) are painful (unintuitive) to catch, and you'll end up with something like:

cumData:=cum(CLOSE);
reset:={condition goes here}
varAvg:=(cumData - ValueWhen(1,reset,cumData)) / Max(BarsSince(reset),1));
{plot}
varAvg;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM