Division by Zero error (PPO Indicator) - futures io
futures io



Division by Zero error (PPO Indicator)


Discussion in EasyLanguage Programming

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




Welcome to futures io: the largest futures trading community on the planet, with well over 150,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Division by Zero error (PPO Indicator)

(login for full post details)
  #1 (permalink)
 Dallas Trader 
Dallas
 
Experience: Advanced
Platform: TradeStation, TOS
Trading: Futures, Stocks, Options
 
Posts: 6 since Dec 2020
Thanks: 1 given, 1 received

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 futures io?
help with take profit several targets
TradeStation
Big Mo Indicator for NT8
NinjaTrader
NT8 Order Management Strategy
The Elite Circle
Market on Close data within IB
Platforms and Indicators
How do I create Strategy with the Second Entry indicator
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Is anyone actually making money?
88 thanks
An embarrassing, honest confession
25 thanks
ApexTraderFunding.com experience and review
8 thanks
Sierra vs. Ninja : why I chose .....
8 thanks
Want your NinjaTrader indicator created, free?
7 thanks
 
(login for full post details)
  #2 (permalink)
 ABCTG   is a Vendor
 
 
Posts: 2,361 since Apr 2013
Thanks: 426 given, 1,579 received

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


futures io Trading Community Platforms and Indicators EasyLanguage Programming > Division by Zero error (PPO Indicator)


Last Updated on December 14, 2020


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
     



Copyright © 2023 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada), info@futures.io
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.
no new posts