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;