[Portfolio Trader] Relative strength in Power Language  [SOLVED]

Questions about MultiCharts and user contributed studies.
Henrik1
Posts: 4
Joined: 20 Jun 2017
Has thanked: 1 time

[Portfolio Trader] Relative strength in Power Language

Postby Henrik1 » 22 Jun 2017

Hi

I am trying to create a signal (strategy) that is based on relative strength. I will use it in Portfolio Trader. I want the signal to compare the 100-day price change in several stocks (data 1) with the 100-day price change in an index (data 2). I want the signal to buy the five most relatively strong stocks if they meet some additional criteria.

I have read the following page (https://www.multicharts.com/trading-sof ... y_Examples) many times but I don’t find it helpful enough.

I have these questions:

1. What does the word “Traceoutput(true)” mean? This word is included in the “Rotation Strategy”.
2. What does the word “pmm_set_my_named_num” mean? This word is also included in the “Rotation Strategy”.

I have tried to code my signal and this is what I came up with (I have excluded the additional criteria):

Code: Select all

inputs: Formula ((Close of Data1 / Close[100] of Data1) - (Close of Data2 / Close[100] of Data2) / (Close of Data2 / Close[100] of Data2)) , TraceOutput(true);

variables: BarNumber (0), BarNumber2 (0), RelativeStrength (0);

BarNumber = BarNumber of data(1);

BarNumber2 = BarNumber of data(2) ;

RelativeStrength = Formula ;

if BarNumber > BarNumber[1] and BarNumber2 > BarNnumber2[1] then begin
pmm_set_my_named_num("Relative Strentgth", RelativeStrength);
end;

if (TraceOutput=true) then begin
buy this bar on close;
end;
Best Regards

User avatar
Angelina MultiСharts
Posts: 260
Joined: 28 Dec 2016
Has thanked: 28 times
Been thanked: 66 times

Re: Relative strength in Power Language

Postby Angelina MultiСharts » 23 Jun 2017

Hello Henrik1,

1. In Rank strategy TraceOutput regulates the Output prints. For example:

Code: Select all

if TraceOutput then
print("CurrentBar = ", currentbar:0:0, ". Allow SHORT for symbol ", pmms_strategy_symbol(strIdx), ", Contracts = ", ContractsForEntry[strIdx]);
2. pmm_set_my_named_num : https://www.multicharts.com/trading-sof ... _named_num

Henrik1
Posts: 4
Joined: 20 Jun 2017
Has thanked: 1 time

Re: Relative strength in Power Language

Postby Henrik1 » 25 Jun 2017

Hello Henrik1,

1. In Rank strategy TraceOutput regulates the Output prints. For example:

Code: Select all

if TraceOutput then
print("CurrentBar = ", currentbar:0:0, ". Allow SHORT for symbol ", pmms_strategy_symbol(strIdx), ", Contracts = ", ContractsForEntry[strIdx]);
2. pmm_set_my_named_num : https://www.multicharts.com/trading-sof ... _named_num
Thank you for your answer!

1. What is an "Output print"? Is it what is shown in the "Output bar" in the "Power Language Editor"? I have never understood the "Output bar", what is its function?

2. Does "pmm_set_my_named_num" only assign a value to a variable (in my case the variable "Relative Strength")?

3. What is the function of this part in my code above:

Code: Select all

"if (TraceOutput=true) then begin
buy this bar on close;
end; "

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Relative strength in Power Language

Postby JoshM » 28 Jun 2017

1. What is an "Output print"? Is it what is shown in the "Output bar" in the "Power Language Editor"? I have never understood the "Output bar", what is its function?
The Print() keyword outputs information to the 'Output' tab in the PowerLanguage Editor. The purpose of that 'Output' tab is being to see values printed by the code, like to keep track of what the script does or to troubleshoot issue.
2. Does "pmm_set_my_named_num" only assign a value to a variable (in my case the variable "Relative Strength")?
That's my understanding of it also.
3. What is the function of this part in my code above:

Code: Select all

"if (TraceOutput=true) then begin
buy this bar on close;
end; "
This code snippet submits an enter long (buy) market order whenever the `TraceOutput` variable is `true`. To see the situations in which that variable would be `true` (and when it would be `false`), you'll have to explore the code that comes before this if statement.

Henrik1
Posts: 4
Joined: 20 Jun 2017
Has thanked: 1 time

Re: Relative strength in Power Language

Postby Henrik1 » 03 Jul 2017

1. What is an "Output print"? Is it what is shown in the "Output bar" in the "Power Language Editor"? I have never understood the "Output bar", what is its function?
The Print() keyword outputs information to the 'Output' tab in the PowerLanguage Editor. The purpose of that 'Output' tab is being to see values printed by the code, like to keep track of what the script does or to troubleshoot issue.
2. Does "pmm_set_my_named_num" only assign a value to a variable (in my case the variable "Relative Strength")?
That's my understanding of it also.
3. What is the function of this part in my code above:

Code: Select all

"if (TraceOutput=true) then begin
buy this bar on close;
end; "
This code snippet submits an enter long (buy) market order whenever the `TraceOutput` variable is `true`. To see the situations in which that variable would be `true` (and when it would be `false`), you'll have to explore the code that comes before this if statement.
Thanks for your answer. I understand everything you wrote except the "TraceOutput variable, I don't understand what this is. I assume "TraceOutput" monitors which value that results from the calculation of my "Formula", am I correct? The value from the calculation of my formula can be negative, zero or positive, when is it "true" and when is it "false"?

Best Regards
Henrik

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Relative strength in Power Language

Postby JoshM » 08 Jul 2017

I understand everything you wrote except the "TraceOutput variable, I don't understand what this is.
The `TraceOutput` variable is from the script input that's from your first post in this thread.

The code of the signal you posted in the first post is:

Code: Select all

inputs: Formula ((Close of Data1 / Close[100] of Data1) - (Close of Data2 / Close[100] of Data2) / (Close of Data2 / Close[100] of Data2)) , TraceOutput(true);

variables: BarNumber (0), BarNumber2 (0), RelativeStrength (0);

BarNumber = BarNumber of data(1);

BarNumber2 = BarNumber of data(2) ;

RelativeStrength = Formula ;

if BarNumber > BarNumber[1] and BarNumber2 > BarNnumber2[1] then begin
pmm_set_my_named_num("Relative Strentgth", RelativeStrength);
end;

if (TraceOutput=true) then begin
buy this bar on close;
end;
Here, in the first line, the `TraceOutput` input variable is defined and given a default value of `true`. You can change it to another value by editing the input options of the signal. (The input variable cannot be changed in the code itself; only by hand with the input options.)
I assume "TraceOutput" monitors which value that results from the calculation of my "Formula", am I correct?
`TraceOutput` doesn't do any monitoring; it's only used with the following if statement from your signal's code:

Code: Select all

if (TraceOutput=true) then begin
buy this bar on close;
end;
So here it only submits a market order on the close of this bar.

You can use the following code snippet from Angelina in your signal to help troubleshoot your signal:

Code: Select all

if TraceOutput then
print("CurrentBar = ", currentbar:0:0, ". Allow SHORT for symbol ", pmms_strategy_symbol(strIdx), ", Contracts = ", ContractsForEntry[strIdx]);
This code prints troubleshooting information to the 'Output' tab of the PowerLanguage Editor.

Because this printing happens in the same situation in which your enter long order is submitted (namely, when `TraceOutput` is `true`), you can match the troubleshooting information with the trades that happen on the chart for more insight into why the signal is behaving like it does.

The value from the calculation of my formula can be negative, zero or positive, when is it "true" and when is it "false"?
No, the formula in your signal and the relative strength value are both independent from what happens with `TraceOutput`. That is, whether that input variable is true or false doesn't matter for the calculated relative strength value.

Hope this helps.

Henrik1
Posts: 4
Joined: 20 Jun 2017
Has thanked: 1 time

Re: Relative strength in Power Language  [SOLVED]

Postby Henrik1 » 10 Jul 2017

Thanks a lot. I think I understand now. Admin can close the thread.

Jonny473
Posts: 68
Joined: 04 Apr 2016
Has thanked: 5 times
Been thanked: 1 time

Re: Relative strength in Power Language

Postby Jonny473 » 18 Aug 2021

Can Henrik post the full code here? As he mentioned he wants to trade the best 5 stocks only here....


Return to “MultiCharts”