How to change color? (CreateIndicator / GetIndicator)

How to create strategies and indicators
Message
Author
Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

How to change color? (CreateIndicator / GetIndicator)

#1 Postby Gen » Wed Sep 29, 2010 2:19 am

Hi,

Is there any way that I can change the indicator line color in the strategy I create, especially when I use CreateIndicator / GetIndicator?

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#2 Postby FT Support » Wed Sep 29, 2010 4:55 am

Hello,

Please use "SetIndicatorBuffStyle" procedure from Strategies API, see more information in Help -> Strategies API
Check our other product here:
http://www.forexcopier.com

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#3 Postby Gen » Thu Sep 30, 2010 2:23 am

Hi,

Can you please provide me some examples how you create the SetIndicatorBuffStyle procedure?

I tried to create it as below. The error came back saying, "HolyGrail.dpr(70,59) Error: Wrong number of parameters specified for call to "SetIndicatorBuffStyle"

Can you look into it?


{-----Reset strategy--------------------------------------------------------}
procedure ResetStrategy; stdcall;
begin
OrderHandle := -1;
handle1 := CreateIndicator(Currency, TimeFrame, 'MovingAverage', format('%d;0;0;%s;Close', [period1, StrMAType(ma_EMA)]));
handle2 := CreateIndicator(Currency, TimeFrame, 'MovingAverage', format('%d;0;0;%s;Close', [period2, StrMAType(ma_EMA)]));
handle3 := CreateIndicator(Currency, TimeFrame, 'PRSAR', '0.02;0.02;0.20');
end;

{-----Set Indicator Color--------------------------------------------------------}
procedure SetIndicatorBuffStyle; stdcall;
begin
SetIndicatorBuffStyle(handle1, 0, 'psSolid', 1, 'clblue');
end;

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#4 Postby FT Support » Thu Sep 30, 2010 7:23 am

Please see an example below:

Code: Select all

SetIndicatorBuffStyle(handle1, 0, psSolid, 1, clBlue);


note that you need to add Graphics unit to uses.
Check our other product here:
http://www.forexcopier.com

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#5 Postby Gen » Fri Oct 01, 2010 4:06 am

Thanks.
With "Graphics", the problem resolved.

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#6 Postby Gen » Wed Oct 20, 2010 4:23 am

I ran into another problem on color.
I cannot see the line colors I set in the different time frame.
From the Indicator list, it looks fine. But I can not see it in the chart.

Can you please tell me what causes this problem from my script below?

I have not use TimeFrame1 yet, FYI.

____________________________________________________________

//-------------------------------------------------------------------------
// Strategy based on EMA
//-------------------------------------------------------------------------
library EMAStrategy;

uses
Graphics, Interfaces, TechnicalFunctions, SysUtils, Classes, StrategyInterfaceUnit;

var
// External parameters
Currency: PChar = nil;
TimeFrame1: integer;
TimeFrame2: integer;
TimeFrame3: integer;
LotSize: double;
period1: integer;
period2: integer;
period3: integer;
handle1: integer;
handle2: integer;
handle3: integer;
handle4: integer;
handle5: integer;
handle6: integer;

// custom variables
OrderHandle: integer;
OrderStyle: TTradePositionType;
OpenTime: TDateTime;


{-----Init strategy---------------------------------------------------------}
procedure InitStrategy; stdcall;
begin
StrategyShortName('SimpleEMA');
StrategyDescription('Strategy based on EMA');

// Register external parameters
RegOption('Currency', ot_Currency, Currency);
ReplaceStr(Currency, 'EURUSD');

RegOption('Timeframe1', ot_Timeframe, TimeFrame1);
TimeFrame1 := 5;

RegOption('Timeframe2', ot_Timeframe, TimeFrame2);
TimeFrame2 := 30;

RegOption('Timeframe3', ot_Timeframe, TimeFrame3);
TimeFrame3 := 240;

RegOption('LotSize', ot_Double, LotSize);
SetOptionDigits('LotSize', 1);
lotSize := 0.1;

RegOption('EMA1 period', ot_Integer, period1);
SetOptionRange('EMA1 period', 2, MaxInt);
period1 := 13;

RegOption('EMA2 period', ot_Integer, period2);
SetOptionRange('EMA2 period', 2, MaxInt);
period2 := 86;

RegOption('EMA3 period', ot_Integer, period3);
SetOptionRange('EMA3 period', 2, MaxInt);
period3 := 233;
end;

{-----Done strategy---------------------------------------------------------}
procedure DoneStrategy; stdcall;
begin
FreeMem(Currency);
end;

{-----Reset strategy--------------------------------------------------------}
procedure ResetStrategy; stdcall;
begin
OrderHandle := -1;
// 4H
handle1 := CreateIndicator(Currency, TimeFrame3, 'MovingAverage', format('%d;0;0;%s;Close', [period1, StrMAType(ma_EMA)]));
SetIndicatorBuffStyle(handle1, 0, psSolid, 1, clAqua);
handle2 := CreateIndicator(Currency, TimeFrame3, 'MovingAverage', format('%d;0;0;%s;Close', [period2, StrMAType(ma_EMA)]));
SetIndicatorBuffStyle(handle2, 0, psSolid, 1, clLime);
handle3 := CreateIndicator(Currency, TimeFrame3, 'MovingAverage', format('%d;0;0;%s;Close', [period3, StrMAType(ma_EMA)]));
SetIndicatorBuffStyle(handle3, 0, psSolid, 1, clYellow);
// 30M
handle4 := CreateIndicator(Currency, TimeFrame2, 'MovingAverage', format('%d;0;0;%s;Close', [period1, StrMAType(ma_EMA)]));
SetIndicatorBuffStyle(handle4, 0, psSolid, 1, clAqua);
handle5 := CreateIndicator(Currency, TimeFrame2, 'MovingAverage', format('%d;0;0;%s;Close', [period2, StrMAType(ma_EMA)]));
SetIndicatorBuffStyle(handle5, 0, psSolid, 1, clLime);
handle6 := CreateIndicator(Currency, TimeFrame2, 'MovingAverage', format('%d;0;0;%s;Close', [period3, StrMAType(ma_EMA)]));
SetIndicatorBuffStyle(handle6, 0, psSolid, 1, clYellow);


end;


{-----Process single tick---------------------------------------------------}
procedure GetSingleTick; stdcall;
var
ema3_1, ema3_2, ema3_3, ema2_1, ema2_2, ema2_3: double;
begin
// check our currency
if Symbol <> string(Currency) then exit;

// set currency and timeframe
SetCurrencyAndTimeframe(Symbol, TimeFrame3);
SetCurrencyAndTimeframe(Symbol, TimeFrame2);

// check number of bars and SMA period
if (Bars < period1) or (Bars < period2) or (Bars < period3)then exit;

// get TimeFrame3 Moving Average value
ema3_1 := GetIndicatorValue(handle1, 1, 0);
ema3_2 := GetIndicatorValue(handle2, 1, 0);
ema3_3 := GetIndicatorValue(handle3, 1, 0);

// get TimeFrame2 Moving Average value
ema2_1 := GetIndicatorValue(handle4, 1, 0);
ema2_2 := GetIndicatorValue(handle5, 1, 0);
ema2_3 := GetIndicatorValue(handle6, 1, 0);


// if BUY order exists and fast EMA crosses slow EMA from top
// then close order
if (OrderHandle <> -1) and (OrderStyle = tp_Buy) and
(OpenTime <> Time(0)) and
(ema2_1 < ema2_3) then
begin
CloseOrder(OrderHandle);
OrderHandle := -1;
end;

// if SELL order exists and fast EMA crosses slow EMA from bottom
// then close order
if (OrderHandle <> -1) and (OrderStyle = tp_Sell) and
(OpenTime <> Time(0)) and
(ema2_1 > ema2_3) then
begin
CloseOrder(OrderHandle);
OrderHandle := -1;
end;

// if there is no order and fast EMA crosses slow EMA from top
// then open SELL order
if (OrderHandle = -1) and
(ema3_1 < ema3_2) and
(ema3_2 < ema3_3) and
(ema2_1 < ema2_2) and
(ema2_2 < ema2_3)
then
begin
SendInstantOrder(Symbol, op_Sell, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Sell;
OpenTime := Time(0);
end;

// if there is no order and fast EMA crosses slow EMA from bottom
// then open BUY order
if (OrderHandle = -1) and
(ema3_1 > ema3_2) and
(ema3_2 > ema3_3) and
(ema2_1 > ema2_2) and
(ema2_2 > ema2_3)
then
begin
SendInstantOrder(Symbol, op_Buy, LotSize, 0, 0, '', 0, OrderHandle);
OrderStyle := tp_Buy;
OpenTime := Time(0);
end;
end;

exports

InitStrategy,
DoneStrategy,
ResetStrategy,
GetSingleTick,
ReplaceStr,
IntrfProcsRec;

end.
Attachments
image.GIF
image.GIF (23.19 KiB) Viewed 15161 times

User avatar
Terranin
Site Admin
Posts: 833
Joined: Sat Oct 21, 2006 4:39 pm

#7 Postby Terranin » Wed Oct 20, 2010 9:50 am

Do you show 2 different charts together or it it the same chart after you switched timeframe? If there are 2 different chart windows then probably your indicators were added to one of them. If you change timeframe on 4H chart to 30M you will see your indicator there. Also check Journal, all problems will be commented there.
Hasta la vista
Mike

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#8 Postby Gen » Wed Oct 20, 2010 1:50 pm

I am trying to use 3 different time frames to trade. So I want to have 3 different charts on the screen, 4h, 30M and 5M. When I enable to strategy, I would like to see all the lines and everything on each of the chart for debugging my strategy. Is there any way possible? I, just in case, attached the journal message.
Attachments
journal.GIF
journal.GIF (4.65 KiB) Viewed 15151 times

Gen
Posts: 14
Joined: Tue Sep 21, 2010 2:19 pm

#9 Postby Gen » Thu Oct 21, 2010 2:01 am

It's been resolved. I do not see the problem anymore. Thanks for your support.


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 12 guests