what is wrong with this eld srript  [SOLVED]

Questions about MultiCharts and user contributed studies.
valabhi
Posts: 45
Joined: 25 Jun 2007

what is wrong with this eld srript

Postby valabhi » 13 Jan 2013

Can someone correct the script posted below to plot correctly for INTRADAY data. It compiles and plots
but does not give correct value. oscillator value should be above zero line when +DMI is above -DMI.
Function for DMI Oscillator;
inputs:
int DMILength( numericsimple ); { length for
DMI calculations }
variables:
double DMIPlusValue( 0 ),
double DMIMinusValue( 0 ),
DMIOsc( 0 ) ;
once { function designed for Daily, Weekly, or Monthly
bars}
DMIPlusValue = DMIPlus( DMILength ) ;
DMIMinusValue = DMIMinus( DMILength ) ;
DMIOsc = DMIPlusValue - DMIMinusValue ;
_DMI_Oscillator = DMIOsc ;
{ force series function, since otherwise this function
can verify as simple, but needs to be called at every
bar to return correct results }
if false then
Value1 = _DMI_Oscillator[1] ;

code script for DMI Osillator;

inputs:
int DMILength( 10 ), { DMI calculation length }
bool PlotOBandOSLines( true ),
double OverBought( 20 ),
double OverSold( -20 ),
bool ColorCellBGOnOBorOS( true ), { if true, cell background color will be if DMI Oscillator is in overbought or oversold territory }
int BackgroundColorOnOBorOS( DarkGray ) ; { if ColorCellBGOnOBorOS is true, this input specifies the color to which the cell background will be
change; if ColorCellBGOnOBorOS is false, then
this input has no effect }

variables:

intrabarpersist bool InAChart( false ),
double DMIOsc( 0 ) ; { holds DMI Oscillator value }

once { determine if the application is a chart }
InAChart = GetAppInfo( aiApplicationType ) = cChart ;
{ calculate the DMI oscillator value }

DMIOsc = _DMI_Oscillator( DMILength ) ;
{ plot the DMI oscillator value }
if DMIOsc > 0 then begin
Plot1( DMIOsc, "DMIOsc", Blue ) ;
if InAChart then
Plot2( DMIOsc, "DMIOscL", blue ) ; { line plot }
end;
if DMIOsc < 0 then begin
Plot1( DMIOsc, "DMIOsc", Red ) ;
if InAChart then
Plot2( DMIOsc, "DMIOscL", Red) ; { line plot }
end;

if PlotOBandOSLines then
begin
Plot3( OverBought, "OverBought" ) ;
Plot4( OverSold, "OverSold" ) ;
plot5(0, "Zero");
end ;
{ grid application specifics }
if ColorCellBGOnOBorOS then { if true, set the
background color if the DMI Oscillator is overbought
or oversold; note that SetPlotBGColor has no effect
in Charting }
begin
if DMIOsc > OverBought then
SetPlotBGColor( 3,
BackgroundColorOnOBorOS ) ;
if DMIOsc < OverSold then
SetPlotBGColor( 4,
BackgroundColorOnOBorOS ) ;
end ;

{ alerts }
if AlertEnabled then
begin
if DMIOsc > OverBought then
Alert( "DMI Oscillator overbought." ) ;
if DMIOsc < OverSold then
Alert( "DMI Oscillator oversold." ) ;
end ;
Attachments
picture1.png
(35.52 KiB) Downloaded 539 times

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

Re: what is wrong with this eld srript

Postby TJ » 13 Jan 2013

Please see How to Post Codes
viewtopic.php?f=16&t=11713



I have tagged the code for you below:

Function for DMI Oscillator;

Code: Select all

inputs:
int DMILength( numericsimple ); { length for DMI calculations }

variables:
double DMIPlusValue( 0 ),
double DMIMinusValue( 0 ),
DMIOsc( 0 ) ;

once { function designed for Daily, Weekly, or Monthly bars}
DMIPlusValue = DMIPlus( DMILength ) ;
DMIMinusValue = DMIMinus( DMILength ) ;
DMIOsc = DMIPlusValue - DMIMinusValue ;
_DMI_Oscillator = DMIOsc ;

{ force series function, since otherwise this function
can verify as simple, but needs to be called at every
bar to return correct results }
if false then
Value1 = _DMI_Oscillator[1] ;
code script for DMI Osillator;

Code: Select all

inputs:
int DMILength( 10 ), { DMI calculation length }
bool PlotOBandOSLines( true ),
double OverBought( 20 ),
double OverSold( -20 ),
bool ColorCellBGOnOBorOS( true ), { if true, cell background color will be
if DMI Oscillator is in overbought or oversold territory }
int BackgroundColorOnOBorOS( DarkGray ) ;
{ if ColorCellBGOnOBorOS is true, this input specifies the color to
which the cell background will be change;
if ColorCellBGOnOBorOS is false, then this input has no effect }

variables:
intrabarpersist bool InAChart( false ),
double DMIOsc( 0 ) ; { holds DMI Oscillator value }

once { determine if the application is a chart }
InAChart = GetAppInfo( aiApplicationType ) = cChart ;
{ calculate the DMI oscillator value }

DMIOsc = _DMI_Oscillator( DMILength ) ;
{ plot the DMI oscillator value }
if DMIOsc > 0 then
begin
Plot1( DMIOsc, "DMIOsc", Blue ) ;
if InAChart then
Plot2( DMIOsc, "DMIOscL", blue ) ; { line plot }
end;

if DMIOsc < 0 then
begin
Plot1( DMIOsc, "DMIOsc", Red ) ;
if InAChart then
Plot2( DMIOsc, "DMIOscL", Red) ; { line plot }
end;

if PlotOBandOSLines then
begin
Plot3( OverBought, "OverBought" ) ;
Plot4( OverSold, "OverSold" ) ;
plot5(0, "Zero");
end ;

{ grid application specifics }
if ColorCellBGOnOBorOS then { if true, set the
background color if the DMI Oscillator is overbought
or oversold; note that SetPlotBGColor has no effect
in Charting }
begin
if DMIOsc > OverBought then
SetPlotBGColor( 3, BackgroundColorOnOBorOS ) ;
if DMIOsc < OverSold then
SetPlotBGColor( 4, BackgroundColorOnOBorOS ) ;
end ;

{ alerts }
if AlertEnabled then
begin
if DMIOsc > OverBought then
Alert( "DMI Oscillator overbought." ) ;
if DMIOsc < OverSold then
Alert( "DMI Oscillator oversold." ) ;
end ;

SP
Posts: 465
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 286 times

Re: what is wrong with this eld srript  [SOLVED]

Postby SP » 14 Jan 2013

You need to remove the once at

Code: Select all

once { function designed for Daily, Weekly, or Monthly bars}
DMIPlusValue = DMIPlus( DMILength ) ;

valabhi
Posts: 45
Joined: 25 Jun 2007

Re: what is wrong with this eld srript

Postby valabhi » 14 Jan 2013

SP;
Thank you It works fine after removing "once"


Return to “MultiCharts”