Indicator compiles but will not print value

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

Indicator compiles but will not print value

Postby valabhi » 12 Jul 2007

attached indicator suppose to print value of angles for EMA at write side of last price bar. It draws ema line but fails to print angle ( with horizontal line in degrees) values. this indicator works fine in TS. i do not have TS so can not attach screenshot. can some one help


current bar
// PreviousEMA = Average(EMA[1],Lookback); //Another possible choice here
// PreviousEMA = EMA[Lookback]; //No smoothing - just use the EMA of n bars ago


If EmaAngleFactor <> 0 then //This is only here to prevent a Divide by 0 error is case EmaAngleFactor hapThis indicator normalizes the EMA angle for all types of data compression and displays
the EMA Angle using DougM_TX's nifty DMCWriteText function. }


Inputs: Price(Close),
EmaLength(34),
UpColor(Cyan), // You can also use RGB(128,128,128) for colors
DownColor(Red), // Get the RGB values from Format Indicator, Color "Other"
Lookback(2), // How far back you want to go to calculate the angle
VerticalDisplay(70), // Adjust where you want the angle to display
HorizOffset(2); // The number of bars to right of last bar on chart

Variables: EMA(0),
PreviousEMA(0),
EmaSlope(0),
EmaAngle(0),
EmaAngleFactor(1),
SessionDuration(0),
TicNum(10),
IntervalSize(3),
IntervalSizeRaw(0),
NBarsVolTick(5),
PlotColor(green);


// *****************************************************************************************************
//This calculates the "EmaAngleFactor", an adjustment to normalize the angle across various time frames
// I got this piece of code from another indicator dealing with EMA angle, but I don't know who the original author is
IntervalSize = BarInterval;
TicNum = pricescale/minmove;

if DataCompression = 2 then
begin {day}
SessionDuration = AbsValue(TimeToMinutes(Sess1EndTime)-TimeToMinutes(Sess1StartTime));
IntervalSizeRaw = SessionDuration*60;
EmaAngleFactor = SquareRoot(IntervalSizeRaw/180);
end else if DataCompression = 3 then
begin {week}
SessionDuration = AbsValue(TimeToMinutes(Sess1EndTime)-TimeToMinutes(Sess1StartTime));
IntervalSizeRaw = SessionDuration*60*5;
EmaAngleFactor = SquareRoot(IntervalSizeRaw/180);
end else if DataCompression = 4 then
begin {month}
SessionDuration = AbsValue(TimeToMinutes(Sess1EndTime)-TimeToMinutes(Sess1StartTime));
IntervalSizeRaw = SessionDuration*60*22;
EmaAngleFactor = SquareRoot(IntervalSizeRaw/180);
end else if DataCompression = 0 then
begin {volume and tick}
if TimeToMinutes(T)-TimeToMinutes(T of NBarsVolTick bars ago) > 1 then
SessionDuration = TimeToMinutes(T)-TimeToMinutes(T of NBarsVolTick bars ago)
else SessionDuration = 1;
IntervalSizeRaw = 60*SessionDuration/NBarsVolTick;
EmaAngleFactor = SquareRoot(IntervalSizeRaw/180);
end else if DataCompression = 1 then
begin {minutes}
IntervalSizeRaw = IntervalSize*60;
EmaAngleFactor = SquareRoot(IntervalSizeRaw/180);
end;

// *******************************************************************************************************
// - Calculating the EMA, Slope and Angle -
// The Angle is calculated by taking the difference between the current EMA value
// and a previous EMA value, in this case the median EMA. We take the slope and use
// ArcTangent to find the Angle in degrees of that slope.

EMA = XAverage(Price,EmaLength);

// Using the median EMA smoothes out the calculation a bit, but other things could be used here
PreviousEMA = Median(EMA[1], Lookback); //Use EMA[1], so the lookback starts from the previous bar, not pens to equal 0
EmaSlope = ((EMA - PreviousEMA)*TicNum) / EmaAngleFactor
else EmaSlope = 1;

EmaAngle = ArcTangent(EmaSlope);


// ********************************************************************************************************
// Plot Statements

If EmaAngle >= 0 then PlotColor = UpColor
else if EmaAngle < 0 then PlotColor = DownColor ;

Plot1(Ema,"Ema", PlotColor );
//Plot2(EmaAngle);
//Plot3(0);

// Displaying the text - note that is only displays in subgraph 1
condition1 = DMCWriteText(-999999, 0,"EMA Angle ", _VDL(VerticalDisplay), PlotColor, 0, HorizOffset);
condition1 = DMCWriteText(-999999, 0, numtostr(EmaAngle, 0) + "°", _VDL(VerticalDisplay-4), PlotColor, 0, HorizOffset);


//***********************************************************************

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

Postby SP » 12 Jul 2007

The plot condition
condition1 = DMCWriteText(-999999, 0,"EMA Angle ", _VDL(VerticalDisplay), PlotColor, 0, HorizOffset);

contains the function _VCL.
This function does not work in MC yet since in contains
Value1 = GetAppInfo( aiHighestDispValue ) ;
which is not supported.

You have to use something like
Textnew (date,time.c, numtostr(EmaAngle, 0) ); instead.


Return to “MultiCharts”