indicator not replaying correctly

How to create strategies and indicators
Message
Author
amirN1
Posts: 7
Joined: Tue Feb 24, 2015 4:56 am

indicator not replaying correctly

#1 Postby amirN1 » Sun Mar 01, 2015 5:04 am

Hi,

I have coded this simple indicator. This displays fine in the history mode however, in the testing mode the indicator is displayed correctly for the loaded days but for the replayed bars it just keeps repeating the last value (as if the index variable is not updated). What is wrong?

Thanks

//---------------------------------------------------------------------------
// Test
//---------------------------------------------------------------------------

#include <windows.h>
#include "IndicatorInterfaceUnit.h"
#include "TechnicalFunctions.h"
#include <stdio.h>
#include <string>
#include <iostream>
#include <fstream>

// External variables
int iOption;


// Buffers
TIndexBuffer iAmirNTest;

//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
EXPORT void __stdcall Init()
{
// define properties
IndicatorShortName("Test");
SetOutputWindow(ow_SeparateWindow );

// register options
AddSeparator("Common");


RegOption("No Option", ot_Integer, &iOption);
SetOptionRange("No Range", 1, MaxInt);
iOption = 0;

// create buffers
iAmirNTest = CreateIndexBuffer();


IndicatorBuffers(1);
SetIndexBuffer(0, iAmirNTest);

SetIndexStyle(0, ds_Line, psSolid, 2, clRed);
SetIndexLabel(0, "Test");

}

//---------------------------------------------------------------------------
EXPORT void __stdcall OnParamsChange()
{
}

//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
EXPORT void __stdcall Calculate(int index)
{
if (index%10)
iAmirNTest[index] = 100;
else
iAmirNTest[index] = 50;
}

amirN1
Posts: 7
Joined: Tue Feb 24, 2015 4:56 am

Re: indicator not replaying correctly

#2 Postby amirN1 » Mon Mar 02, 2015 3:38 pm

Any response?

I need to get this one working ASAP. As I am a new user I need to make sure if this software is for me.

Thanks

amirN1
Posts: 7
Joined: Tue Feb 24, 2015 4:56 am

Re: indicator not replaying correctly

#3 Postby amirN1 » Tue Mar 03, 2015 3:52 pm

I have done it in Delphi as well and I am getting the same problem:

library test1;

uses
SysUtils, classes, graphics, windows, IndicatorInterfaceUnit;

var
// Buffers
iAmirNTest: TIndexBuffer;

//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
// define properties
IndicatorShortName('Test');
SetOutputWindow(ow_SeparateWindow);

// create buffers
iAmirNTest := CreateIndexBuffer;
IndicatorBuffers(1);
SetIndexBuffer(0, iAmirNTest);
SetIndexStyle(0, ds_line, psSolid, 2, RGB($1E, $90, $FF));
SetIndexLabel(0, 'Test');
end;

//---------------------------------------------------------------------------
// Deinitialize indicator
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin

end;

//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
begin
if (index mod 10) = 0 then
iAmirNTest[index] := 100
else
iAmirNTest[index] := 50;
end;

exports

Init, Done, Calculate;

end.

FX Helper
Posts: 1479
Joined: Mon Apr 01, 2013 3:55 am

Re: indicator not replaying correctly

#4 Postby FX Helper » Wed Mar 04, 2015 6:31 am

Hello,

You have this issue because during testing current bar always has index 0.
So your "if (index mod 10) = 0" will always be true and you will always see value=100 in testing.

Do I understand correctly that you want to show value=100 for every tenth bar? In this case you need to use another verification for tenth bar.

amirN1
Posts: 7
Joined: Tue Feb 24, 2015 4:56 am

Re: indicator not replaying correctly

#5 Postby amirN1 » Wed Mar 04, 2015 3:16 pm

Hi,

I have sent you an email, in essence what I require is how to found out the bar number currently printing in the testing mode.

Regard

FX Helper
Posts: 1479
Joined: Mon Apr 01, 2013 3:55 am

Re: indicator not replaying correctly

#6 Postby FX Helper » Thu Mar 05, 2015 7:16 am

Hello,

Currently printing bar number has index 0. Previous bar has index 1, and so on.

amirN1
Posts: 7
Joined: Tue Feb 24, 2015 4:56 am

Re: indicator not replaying correctly

#7 Postby amirN1 » Thu Mar 05, 2015 2:54 pm

So how could I use this information to find out what is the current bar number printing from the beginning of data file.

In the history mode the current bar number is (Bars() -1 - index) what is it in the testing mode?

Regards

FX Helper
Posts: 1479
Joined: Mon Apr 01, 2013 3:55 am

Re: indicator not replaying correctly

#8 Postby FX Helper » Tue Mar 10, 2015 1:06 pm

Hello,

In Testing Mode current bar has index 0. When new bar appears, this bar will have index 1 and so on.


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 13 guests