Need help creating a ds_Symbol style ChartWindow indicator

Examples step by step how to make your own automated strategy or user indicator
Message
Author
Lonesome
Posts: 28
Joined: Fri Oct 21, 2016 9:04 am

Need help creating a ds_Symbol style ChartWindow indicator

#1 Postby Lonesome » Mon Apr 10, 2017 6:36 pm

I used the fractal indicator as an example to learn how ds_Symbol style ChartWindow indicators are created.
I modified the fractal script to create a very simple indicator. See attached figure.
The condition are:
1. If (Open(0)>Open(1) and Open(1)>Open(2)) then put a ds_Symbol at index
2. If (Open(0)<Open(1) and Open(1)<Open(2)) then put a ds_Symbol at index

However, the indicator is not working and I cannot figure out why.
Please somebody fix my script below.

Code: Select all

//---------------------------------------------------------------------------
// Test Indicator
//---------------------------------------------------------------------------
library TestIndicator;

uses
  graphics, IndicatorInterfaceUnit, SysUtils;

var
  // Buffers
  TrendUpBuff, TrendDownBuff: TIndexBuffer;
 
//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
  // define properties
  IndicatorShortName('Test Indicator');
  SetOutputWindow(ow_ChartWindow);

  // create buffers
  TrendUpBuff := CreateIndexBuffer;
  TrendDownBuff := CreateIndexBuffer;
  SetIndexBuffer(0, TrendUpBuff);
  SetIndexStyle(0, ds_Symbol, psSolid, 1, clGreen);
  SetIndexSymbol(0, 217, 0, 10);
  SetIndexLabel(0, 'Trend Up');
  SetIndexBuffer(1, TrendDownBuff);
  SetIndexStyle(1, ds_Symbol, psSolid, 1, clRed);
  SetIndexSymbol(1, 218, 0, -10);
  SetIndexLabel(1, 'Trend Down');
end;
//---------------------------------------------------------------------------
// Deinitialize indicator
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin

end;

//---------------------------------------------------------------------------
// Mark Candlestick Patterns
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;

begin

    //*************Trend up**************
    if not (Close(index)>Close(index+1)) and (Close(index+1)>Close(index+2)) then
      begin
        TrendUpBuff[index] := 0;
      end
    else
      TrendUpBuff[index] := Close(index);

    //*************Trend down*************
    if not (Close(index)<Close(index+1)) and (Close(index+1)<Close(index+2)) then
      begin
        TrendDownBuff[index] := 0;
      end
     else
      TrendUpBuff[index] := Close(index);

end;

exports

Init, Done, Calculate;
begin
end.
Attachments
image001.jpg
image001.jpg (56.13 KiB) Viewed 2145 times

User avatar
neHcioHep
Posts: 18
Joined: Sat Nov 21, 2009 5:49 pm

Re: Need help creating a ds_Symbol style ChartWindow indicator

#2 Postby neHcioHep » Tue Apr 11, 2017 3:41 am

Hello,

Try to add line

Code: Select all

IndicatorBuffers(2);


before these lines

Code: Select all

// create buffers
  TrendUpBuff := CreateIndexBuffer;
  TrendDownBuff := CreateIndexBuffer;

Lonesome
Posts: 28
Joined: Fri Oct 21, 2016 9:04 am

Re: Need help creating a ds_Symbol style ChartWindow indicator

#3 Postby Lonesome » Tue Apr 11, 2017 9:18 am

yes, indeed, after adding the "IndicatorBuffers(2)" line I got the symbols. Inserting it after creating the buffers also works.
In addition the if statements in the Calculate procedure were wrong.
Below is the fully functional script.
It is a nonsense indicator, but the script is minimal making it easy to understand how to script a ds_Symbol style ChartWindow indicator.

Code: Select all

//---------------------------------------------------------------------------
// Test Indicator
//---------------------------------------------------------------------------
library TestIndicator;

uses
  graphics, IndicatorInterfaceUnit, SysUtils;

var
  // Buffers
  TrendUpBuff, TrendDownBuff: TIndexBuffer;
 
//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
  // define properties
  IndicatorShortName('Test Indicator');
  SetOutputWindow(ow_ChartWindow);

  // create buffers
  TrendUpBuff := CreateIndexBuffer;
  TrendDownBuff := CreateIndexBuffer;
  IndicatorBuffers(2);
  SetIndexBuffer(0, TrendUpBuff);
  SetIndexStyle(0, ds_Symbol, psSolid, 1, clGreen);
  SetIndexSymbol(0, 217, 0, 10);
  SetIndexLabel(0, 'Trend Up');
  SetIndexBuffer(1, TrendDownBuff);
  SetIndexStyle(1, ds_Symbol, psSolid, 1, clRed);
  SetIndexSymbol(1, 218, 0, -10);
  SetIndexLabel(1, 'Trend Down');
end;
//---------------------------------------------------------------------------
// Deinitialize indicator
//---------------------------------------------------------------------------
procedure Done; stdcall;
begin

end;

//---------------------------------------------------------------------------
// Mark Candlestick Patterns
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;

begin

    //*************Trend up**************
    if (Close(index)>Close(index+1)) and (Close(index+1)>Close(index+2)) and (Close(index+2)>Close(index+3))and (Close(index+3)>Close(index+4))then
      begin
        TrendUpBuff[index] := High(index);
      end;

    //*************Trend down*************
    if (Close(index)<Close(index+1)) and (Close(index+1)<Close(index+2)) and (Close(index+2)<Close(index+3))and (Close(index+3)<Close(index+4)) then
      begin
        TrendDownBuff[index] := Low(index);
      end

end;

exports

Init, Done, Calculate;
begin
end.

Lonesome
Posts: 28
Joined: Fri Oct 21, 2016 9:04 am

Re: Need help creating a ds_Symbol style ChartWindow indicator

#4 Postby Lonesome » Tue Apr 11, 2017 9:30 am

neHcioHep, thanks for your help.

Lonesome
Posts: 28
Joined: Fri Oct 21, 2016 9:04 am

Re: Need help creating a ds_Symbol style ChartWindow indicator

#5 Postby Lonesome » Wed Apr 12, 2017 8:18 am

BTW, below is a table with symbols that can be used with the ds_symbol indicator.
Attachments
Wingdings%20codes%20for%20ForexTester.PNG
Wingdings%20codes%20for%20ForexTester.PNG (89.18 KiB) Viewed 2124 times


Return to “Programming lessons”

Who is online

Users browsing this forum: No registered users and 2 guests