NexusFi: Find Your Edge


Home Menu

 





Division by Zero error (PPO Indicator)


Discussion in EasyLanguage Programming

Updated
    1. trending_up 4,024 views
    2. thumb_up 0 thanks given
    3. group 2 followers
    1. forum 1 posts
    2. attach_file 0 attachments




 
Search this Thread

Division by Zero error (PPO Indicator)

  #1 (permalink)
 Dallas Trader 
Dallas
 
Experience: Advanced
Platform: TradeStation, TOS
Trading: Futures, Stocks, Options
Posts: 6 since Dec 2020
Thanks Given: 1
Thanks Received: 1

Saved MACD indicator for modification into PPO Indicator.
Equations for MACD and PPO listed below

MACD Line = 12EMA - 26EMA
Signal Line = 9EMA of MACD Line
Histogram = MACD Line - Signal Line

PPO Line = 100*((12EMA-26EMA)/26EMA)
Signal Line = 9EMA of PPO Line
Histogram = PPO Line - Signal Line

_____________________________________________________________

Here is the modified EasyLanguage MACD Code I created:

{ Moving average convergence-divergence indicator Modified for PPO }

inputs:
int FastLength( 12 ), { the shorter of the two exponential moving average
lengths used to calculate the MACD value, in bars }
int SlowLength( 26 ), { the longer of the two exponential moving average
lengths used to calculate the MACD value, in bars }
int MACDLength( 9 ), { the number of bars over which to exponentially average
the MACD value }
int MACDDiff_Up_Color( Darkgreen ), { color to be used to plot positive values of
MACDDiff }
int MACDDiff_Down_Color( Red ), { color to be used to plot negative values of
MACDDiff }
int BackgroundColorAlertCell( DarkGray ) ; { if alert criteria are met, this is
the color used for the cell background in RadarScreen; if it is not desired
for the cell background color to change when the alert criteria are met, set
this input to the default cell background color }

variables:
intrabarpersist bool PlotCrossBarsAgo( false ),
double MyMACD( 0 ),
double MACDAvg( 0 ),
double MACDDiff( 0 ),
double SlowlengthEMA (0),
double PPO1 (0), {PPO is TradeStation reserved word, used PPO1 instead for PPO}
double HistogramColor( 0 ),
int CrossBarsAgo( 0 ) ;

once
PlotCrossBarsAgo = GetAppInfo( aiApplicationType ) <> cChart ;

MyMACD = MACD( Close, FastLength, SlowLength ) ;
SlowlengthEMA = XAverage (Close,Slowlength);
MACDAvg = XAverage( MyMACD, MACDLength ) ;
PPO1 = 100*(MyMACD/MACDAvg);
MACDDiff = PPO1 - MACDAvg ;
HistogramColor = iff( MACDDiff > 0, MACDDiff_Up_Color, MACDDiff_Down_Color ) ;

if ( MACDDiff > 0 and MACDDiff[1] <= 0 ) or ( MACDDiff < 0 and MACDDiff[1] >= 0 )
then
CrossBarsAgo = 0
else
CrossBarsAgo += 1 ;

Plot1( PPO1, "PPO" ) ;
Plot2( MACDAvg, "PPO Signal" ) ;
Plot3( MACDDiff, "PPO Hist", HistogramColor ) ;
if PlotCrossBarsAgo = false then
Plot4( 0, "ZeroLine" )
else
Plot5( CrossBarsAgo, "CrossBarsAgo", HistogramColor ) ;

{ alert criteria }
if MACDDiff crosses over 0 then
begin
SetPlotBGColor( 5, BackgroundColorAlertCell ) ;
Alert( "MACD diff. crossing over 0." ) ;
end
else if MACDDiff crosses under 0 then
begin
SetPlotBGColor( 5, BackgroundColorAlertCell ) ;
Alert( "MACD diff. crossing under 0." ) ;
end ;


{ ** Copyright (c) 2001 - 2011 TradeStation Technologies, Inc. All rights reserved. **
** TradeStation reserves the right to modify or overwrite this analysis technique
with each release. ** }

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Better Renko Gaps
The Elite Circle
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
31 thanks
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

Dallas Trader,

you can prevent division by zero errors by checking if the denominator is different than 0 before performing the division.

 
Code
if denominator <> 0 then 
   divisionResult = numerator / denominator 
else
   divisionResult = 0 ; //specify a fallback value in case denominator = 0; this could be 0 or anything you like to use instead
Regards,

ABCTG


Dallas Trader View Post
Saved MACD indicator for modification into PPO Indicator.
Equations for MACD and PPO listed below

MACD Line = 12EMA - 26EMA
Signal Line = 9EMA of MACD Line
Histogram = MACD Line - Signal Line

PPO Line = (12EMA-26EMA)/26EMA
Signal Line = 9EMA of PPO Line
Histogram = PPO Line - Signal Line

_____________________________________________________________

Here is the modified EasyLanguage MACD Code I created:

{ Moving average convergence-divergence indicator Modified for PPO }

inputs:
int FastLength( 12 ), { the shorter of the two exponential moving average
lengths used to calculate the MACD value, in bars }
int SlowLength( 26 ), { the longer of the two exponential moving average
lengths used to calculate the MACD value, in bars }
int MACDLength( 9 ), { the number of bars over which to exponentially average
the MACD value }
int MACDDiff_Up_Color( Darkgreen ), { color to be used to plot positive values of
MACDDiff }
int MACDDiff_Down_Color( Red ), { color to be used to plot negative values of
MACDDiff }
int BackgroundColorAlertCell( DarkGray ) ; { if alert criteria are met, this is
the color used for the cell background in RadarScreen; if it is not desired
for the cell background color to change when the alert criteria are met, set
this input to the default cell background color }

variables:
intrabarpersist bool PlotCrossBarsAgo( false ),
double MyMACD( 0 ),
double MACDAvg( 0 ),
double MACDDiff( 0 ),
double SlowlengthEMA (0),
double PPO1 (0), {PPO is TradeStation reserved word, used PPO1 instead for PPO}
double HistogramColor( 0 ),
int CrossBarsAgo( 0 ) ;

once
PlotCrossBarsAgo = GetAppInfo( aiApplicationType ) <> cChart ;

MyMACD = MACD( Close, FastLength, SlowLength ) ;
SlowlengthEMA = XAverage (Close,Slowlength);
MACDAvg = XAverage( MyMACD, MACDLength ) ;
PPO1 = MyMACD/MACDAvg;
MACDDiff = PPO1 - MACDAvg ;
HistogramColor = iff( MACDDiff > 0, MACDDiff_Up_Color, MACDDiff_Down_Color ) ;

if ( MACDDiff > 0 and MACDDiff[1] <= 0 ) or ( MACDDiff < 0 and MACDDiff[1] >= 0 )
then
CrossBarsAgo = 0
else
CrossBarsAgo += 1 ;

Plot1( PPO1, "PPO" ) ;
Plot2( MACDAvg, "PPO Signal" ) ;
Plot3( MACDDiff, "PPO Hist", HistogramColor ) ;
if PlotCrossBarsAgo = false then
Plot4( 0, "ZeroLine" )
else
Plot5( CrossBarsAgo, "CrossBarsAgo", HistogramColor ) ;

{ alert criteria }
if MACDDiff crosses over 0 then
begin
SetPlotBGColor( 5, BackgroundColorAlertCell ) ;
Alert( "MACD diff. crossing over 0." ) ;
end
else if MACDDiff crosses under 0 then
begin
SetPlotBGColor( 5, BackgroundColorAlertCell ) ;
Alert( "MACD diff. crossing under 0." ) ;
end ;


{ ** Copyright (c) 2001 - 2011 TradeStation Technologies, Inc. All rights reserved. **
** TradeStation reserves the right to modify or overwrite this analysis technique
with each release. ** }


Follow me on Twitter Reply With Quote




Last Updated on December 14, 2020


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts