GetIndicatorValue for ADX indicator does not work

Bug reports and errors in the program
Message
Author
gglamonakis
Posts: 23
Joined: Sun Jun 19, 2011 10:19 am

GetIndicatorValue for ADX indicator does not work

#1 Postby gglamonakis » Fri Aug 15, 2014 3:12 pm

No matter what buffer (0,1,2,3,4,5) I request or what index (0,1,2,3) I always get back a FloatToStr(adxVal) of 2.32910531519136E-306

The indicator shows up correctly on the chart as the strategy is being tested.
Note that the parameters passed into the create adx call " IntToStr(adxPeriod) + ',' + adxApplyToPrice[adxApplyTo]" resolves to "14,Close"

Also to note is that the buffers for the ADX indicated in the API documentation are incorrect, the SetIndicatorBuffStyle calls are correctly coloring/hiding the ADX and DI+/-, found this out by trial and error and hence why I also went through buffers 0-5 on GetIndicatorValue for trial and error.

Also I am using GetIndicatorValue for another indicator (PriceChannels to be specific) - most of the code creating these has been omitted for brevity (and to hide my strategy a bit) but as is noted in the GetSingleTick method - the GetIndicatorValue for these is working exactly as it should.

I really need the ADX line value for my strategy, can someone please look into this a bit?

Thanks!!
Greg


My code is as follows (not the complete , edited to reduce size/hide code):

Code: Select all

const
  adxApplyToPrice: array[1..7] of string = ('Open','Low','High','Close','(High + Low)/2','(High + Low + Close)/3','(High + Low + Close + Open)/4');

procedure InitStrategy; stdcall;
var
  count: integer;
begin

RegOption('ADX Period', ot_Integer, adxPeriod);
  SetOptionRange('ADX Period', 2, MaxInt);
  adxPeriod := 14;

  RegOption('Apply To', ot_EnumType, adxApplyTo);
  For count := 1 to Length(adxApplyToPrice) do
    AddOptionValue('Apply To', adxApplyToPrice[count]);

  adxApplyTo := 3;
end;

procedure ResetStrategy; stdcall;
begin

 adxHandle := CreateIndicator(Currency, TimeFrame, 'ADX', IntToStr(adxPeriod) + ',' + adxApplyToPrice[adxApplyTo]);
  SetIndicatorBuffStyle(adxHandle, 0, psSolid, 1, clBlue);
  SetIndicatorBuffStyle(adxHandle, 1, psClear, 0, clNone);
  SetIndicatorBuffStyle(adxHandle, 2, psClear, 0, clNone);

end;

procedure GetSingleTick; stdcall;
var
  now: TDateTime;
  hh,mm,ss,ms: Word;
  adxVal, highChannelHigh, lowChannelHigh: double;
  highChannelLow, lowChannelLow: double;
begin

  now := TimeCurrent;
  DecodeTime(now,hh,mm,ss,ms);

  if (hh = 17) and (mm = 0) then
    adxVal := GetIndicatorValue(adxHandle, 0, 3);
    highChannelHigh := GetIndicatorValue(highChannelHandle, 0, 0);
    highChannelLow := GetIndicatorValue(highChannelHandle, 0, 1);
    lowChannelHigh := GetIndicatorValue(lowChannelHandle, 0, 0);
    lowChannelLow := GetIndicatorValue(lowChannelHandle, 0, 1);

    Print('AdxVal: ' + FloatToStr(adxVal) + ', High Channel High: ' + FloatToStr(highChannelHigh) + ', High Channel Low: ' + FloatToStr(highChannelLow) +
            ', Low Channel High: ' + FloatToStr(lowChannelHigh) + ', Low Channel Low: ' + FloatToStr(lowChannelLow));



end;

gglamonakis
Posts: 23
Joined: Sun Jun 19, 2011 10:19 am

Re: GetIndicatorValue for ADX indicator does not work

#2 Postby gglamonakis » Fri Aug 15, 2014 4:24 pm

I believe I found the cause of this issue.

The ADX indicator value seems to be calculated at the end of the bar, accessing it mid bar give weird values. I exacerbated the issue with my misunderstanding of delphi coding conventions.

I was treating it like python where indentation has value, in delphi if you have multiple statements after an if then you need to have a begin / end around this group of statements.

Please consider the issue resolved


Return to “Bug reports”

Who is online

Users browsing this forum: No registered users and 20 guests