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");
help converting simple indicator into signal
- TJ
- Posts: 7739
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1032 times
- Been thanked: 2221 times
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 ;
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 ;
Thank you..if Trigger then buy ( "PPO" ) next bar at market ;
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
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
"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
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
May all your trades reach your desired targets
Max
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
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