help converting simple indicator into signal

Questions about MultiCharts and user contributed studies.
max vogt
Posts: 3
Joined: 19 Nov 2008

help converting simple indicator into signal

Postby max vogt » 20 Nov 2008

I have a simple crossover indicator (the Price Percentage Oscillator) which I'd like to convert into a signal with on chart arrows, but don't know how to do it. Would someone here be willing to look at it and help out. Thanks so much for any help!

Here's the indicator (the version I have of it anyway)


variables:
PPO(0),
Trigger(0);

PPO = (XAverage( close, 9 ) - XAverage( close, 45 ))/XAverage( close, 9 )*100;

Trigger = XAverage((XAverage( close, 9 ) - XAverage( close, 45 ))/XAverage( close, 9 )*100, 9);

plot1( PPO , "Percent Price Oscillator");
plot2( Trigger, "Trigger");

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

Postby TJ » 20 Nov 2008

if Trigger then buy ( "PPO" ) next bar at market ;

User avatar
Januson
Posts: 119
Joined: 18 Apr 2007
Location: Denmark

Postby Januson » 20 Nov 2008

variables:
PPO(0),
Trigger(0);

PPO = (XAverage( close, 9 ) - XAverage( close, 45 ))/XAverage( close, 9 )*100;

Trigger = XAverage((XAverage( close, 9 ) - XAverage( close, 45 ))/XAverage( close, 9 )*100, 9);

if Trigger crosses above PPO then
Buy ( "PPO" ) next bar at market ;

if Trigger crosses under PPO then
Sell ( "PPO" ) next bar at market ;

max vogt
Posts: 3
Joined: 19 Nov 2008

Postby max vogt » 20 Nov 2008

if Trigger then buy ( "PPO" ) next bar at market ;
Thank you..

However if I simply add this to the end of the string like this:


variables:
PPO(0),
Trigger(0);

PPO = (XAverage( close, 9 ) - XAverage( close, 45 ))/XAverage( close, 9 )*100;

Trigger = XAverage((XAverage( close, 9 ) - XAverage( close, 45 ))/XAverage( close, 9 )*100, 9);

plot1( PPO , "Percent Price Oscillator");
plot2( Trigger, "Trigger");
if Trigger then buy ( "PPO" ) next bar at market ;


and then compile, I get this error message:

------ Build started: ------
Study: "ppobuysell" (Signal)
Please wait ....
------ Compiled with error(s): ------
Logical expression expected
errLine 12, errColumn 3, errLineEnd 12, errColumnEnd 3


Thanks if you can show me the issue.

Max

User avatar
Januson
Posts: 119
Joined: 18 Apr 2007
Location: Denmark

Postby Januson » 20 Nov 2008

Thats because you can't use a numerical as true/ false expression!
Try the crosses method instead.

eegroup
Posts: 78
Joined: 04 Aug 2008
Has thanked: 11 times
Been thanked: 9 times

Postby eegroup » 20 Nov 2008

Hi, Max:

"Trigger" is defined as a numeric variable, not a condition. In a logical statement (IF .... THEN ...), you need to compare something with something else in order to have the Buy take place as coded.

In Januson's example that he provided, it was assumed that you wanted to buy (go long) when the Trigger value crosses above (over) the PPO value. Likewise, you would sell (go short) when the Trigger value crosses under (below) the PPO value:

if Trigger crosses above PPO then
Buy ( "PPO" ) next bar at market ;

if Trigger crosses under PPO then
Sell ( "PPO" ) next bar at market ;

You need to condition the buy and the sell based upon how the Trigger value compares to and in a relationship to something else (like the PPO value).

Also, the two market order commands (Buy and Sell) should be labeled differently (not both the same named as "PPO").

Further, you cannot use Plot Statements in a Signal that issues market orders. In other words, you cannot mix Plot and Buy and Sell commands.

The best solution is to make up a Indicator to plot the two values (Trigger & PPO). Then make up a Signal (Strategy) to execute/plot the market orders (Buys & Sells).

Also, it appeared that the logic for determining a Buy and Sell were reversed. It looks like you should go long when the Trigger crosses under the PPO, and go short when the Trigger crosses over the PPO. If this is not correct, simply reverse the "under" and the "over" parts of the conditional statements that execute thebuys and the sells.

We also added some input parameters, so you could change the long and short lengths in your formulas without having to recompile the indicator and the study. This would also allow you to optimize the length setting for various instruments and time/bar frequencies, if you wanted to. We also placed the price stream (Close) into a "Price" input parameter, in case you want to try different price streams [ for example, Open, High, Low, or (High + Low + Close)/3].

Here's your basic INDICATOR coding:

// Max Vogt Indicator

inputs:
Price(Close),
ShortLen(9),
LongLen(45);

variables:
PPO(0),
Trigger(0);

PPO = (XAverage( Price, ShortLen ) - XAverage( Price, LongLen ))/XAverage( Price, ShortLen )*100;

Trigger = XAverage((XAverage( Price, ShortLen ) - XAverage( Price, LongLen ))/XAverage( Price, ShortLen )*100, 9);

plot1( PPO , "% Price Osc");
plot2( Trigger, "Trigger");

Here's your basic STUDY (Strategy) coding:

// Max Vogt Signal

// Max Vogt Signal

inputs:
Price(Close),
ShortLen(9),
LongLen(45);

variables:
PPO(0),
Trigger(0);

PPO = (XAverage( Price, ShortLen ) - XAverage( Price, LongLen ))/XAverage( Price, ShortLen )*100;

Trigger = XAverage((XAverage( Price, ShortLen ) - XAverage( Price, LongLen ))/XAverage( Price, ShortLen )*100, 9);

if Trigger crosses under PPO then
Buy ( "Buy" ) next bar at market ;

if Trigger crosses over PPO then
Sell ( "Sell" ) next bar at market ;

Both of these compile without errors.

With both the Indicator and the Signal placed on a chart, they look like the attached screenshot.

Hope this helps.

May all of your trades be profitable.

Take care,

Ryan
eegroup
Attachments
picture1.png
(65.72 KiB) Downloaded 1119 times

User avatar
Januson
Posts: 119
Joined: 18 Apr 2007
Location: Denmark

Postby Januson » 20 Nov 2008

Ryan I wasn't aware that this was going to be a pissing contest!!

Take care :shock:

max vogt
Posts: 3
Joined: 19 Nov 2008

Postby max vogt » 20 Nov 2008

Thanks so much for your help, both of you, this worked great. It feels like a Thanksgiving present, since the math and coding of it all is utterly beyond me. I appreciate people like you who understand programming and are willing to share your knowledge and expertise with such generosity.

May all your trades reach your desired targets :-)

Max

eegroup
Posts: 78
Joined: 04 Aug 2008
Has thanked: 11 times
Been thanked: 9 times

Postby eegroup » 20 Nov 2008

Hi, Janus:

No, no pissing contest. Just trying to help Max out.

You got him on the right road; I just was attempting to help him get to his destination.

I appreciate all of your hard work posting on the Forum. Thanks for your contributions. They are all very informative.

Have a Carlsberg HOF for me!

Take care,

Ryan


Return to “MultiCharts”