Need little help with PowerLanguage strategy creation

Questions about MultiCharts and user contributed studies.
raj
Posts: 8
Joined: 24 Feb 2013
Has thanked: 1 time

Need little help with PowerLanguage strategy creation

Postby raj » 24 Feb 2013

I'm currently using eSignal, but in process of making a transition to MC because its optimization features are irresistible. One of my first step involves creating this strategy in MC, which I've been using in eSignal from quite a while.

The entry criteria is something like this:

If today's closing price > SMA(21)
&
If weekly MACD is already in a crossover

In eSignal, writing the code was pretty simple like this:

Code: Select all

xSMA = sma(21);
var nSma = xSMA.getValue(0);

weeklyMacd = macd(8, 16, 11,inv("W"));
weeklyMacdSignal = macdSignal(8, 16, 11,inv("W"));

if(weeklyMacdSignal.getValue(0) < weeklyMacd.getValue(0))
{
if(Strategy.isLong() == false && close(0) >= nSma) {
Strategy.doLong("Long", Strategy.MARKET , Strategy.NEXTBAR, 100);
}
}
Note that regardless of chart was opened in daily interval, the MACD signal was being calculated for the week with the help of inv()

Now I can't figure out how to calculate weekly MACD in MC just like these lines are doing:

Code: Select all

weeklyMacd = macd(8, 16, 11,inv("W"));
weeklyMacdSignal = macdSignal(8, 16, 11,inv("W"));
Any help will be greatly appreciated.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Need little help with PowerLanguage strategy creation

Postby TJ » 24 Feb 2013

1. you will need to add 2 data series to a chart --- a daily series and a weekly series.

see post #4
[FAQ] Multiple time frame, Multi-Data Analysis
viewtopic.php?f=16&t=6929


2. apply indicators to the respective data series

see post #5
[FAQ] Data2
viewtopic.php?f=16&t=6929

raj
Posts: 8
Joined: 24 Feb 2013
Has thanked: 1 time

Re: Need little help with PowerLanguage strategy creation

Postby raj » 25 Feb 2013

Applying indicator sounds fine, but how an entry signal will work like this while performing backtesting?

raj
Posts: 8
Joined: 24 Feb 2013
Has thanked: 1 time

Re: Need little help with PowerLanguage strategy creation

Postby raj » 25 Feb 2013

I just finished reading the text, it was very helpful. However, I have one question, how will 'Data2' variable will work while working on portfolio backtester?

Because I assume portfolio backtester doesn't open charts to backtest. It does all its calculations in background, right?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Need little help with PowerLanguage strategy creation

Postby Andrew MultiCharts » 25 Feb 2013

Hello Raj,

Data2, data3 and so on... are the additional data series. The series are loaded both in Portfolio Backtester and in MultiCharts. In MC they are visualized, while in PB they are not. In MultiCharts you can have many of them, while in Portfolio Backtester only 5 data series (including th first one, that is base for strategy calculation.

raj
Posts: 8
Joined: 24 Feb 2013
Has thanked: 1 time

Re: Need little help with PowerLanguage strategy creation

Postby raj » 26 Feb 2013

Thanks, that solves the main problem. I have a separate issue if you can help:

I'm calculating MACD on a 'data3' series, which is displayed in monthly interval. Here's the code:

Code: Select all

var1 = MACD( Close, 8, 16) data3 ;
var2 = XAverage( var1, 11 ) ;
Now the values at a specific date calculated by above code are completely different from what is displayed on the chart.

Can you help?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Need little help with PowerLanguage strategy creation

Postby Andrew MultiCharts » 26 Feb 2013

If everything is set up the same way (symbol, data series length, number of bars, resolution, quote field, settings of strategy, signals), then the results should be the same.

raj
Posts: 8
Joined: 24 Feb 2013
Has thanked: 1 time

Re: Need little help with PowerLanguage strategy creation

Postby raj » 27 Feb 2013

Is this code right to calculate MACD on data3 series?

Code: Select all

var1 = MACD( Close of data3, 8, 16) data3 ;
var2 = XAverage( var1, 11 ) data3 ;

raj
Posts: 8
Joined: 24 Feb 2013
Has thanked: 1 time

Re: Need little help with PowerLanguage strategy creation

Postby raj » 27 Feb 2013

Also, is there a functional reference for Power Language somewhere? I can't find it.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Need little help with PowerLanguage strategy creation

Postby Andrew MultiCharts » 27 Feb 2013

This should work:

Code: Select all

var1 = MACD( Close, 8, 16) data3 ;
var2 = XAverage( var1, 11 ) data3 ;
Also, is there a functional reference for Power Language somewhere? I can't find it.
If you want to find out how a function works in MC, you need to open its script and analyze it.

raj
Posts: 8
Joined: 24 Feb 2013
Has thanked: 1 time

Re: Need little help with PowerLanguage strategy creation

Postby raj » 28 Feb 2013

The code works but it is producing different values than the chart. Been trying to figure out from last 2 days but no luck - have looked everywhere.

For eg:

Values from chart:
9/28/2012
MACD: 35
MACDAvg: -8

Values in code (debug output):
9/28/2012
MACD: 26
MACDAvg: -10

Although difference is somewhat similar, but if I move forward to further dates, even difference has a huge variation.

raj
Posts: 8
Joined: 24 Feb 2013
Has thanked: 1 time

Re: Need little help with PowerLanguage strategy creation

Postby raj » 28 Feb 2013

FYI, MACD is coming almost correct - its the MACDAvg which is varied greatly.

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Need little help with PowerLanguage strategy creation

Postby Andrew MultiCharts » 28 Feb 2013

When you apply your script to data 1 to calculate values from data 3, the frequency of calculations and their final amount will depend on the amount of bars (or intrabar points of calculation) of data 1. These values may be different from what you get if you apply your script directly to data 3.


Return to “MultiCharts”