Time Box Background on White Chart

Bug reports and errors in the program
Message
Author
stephen77
Posts: 10
Joined: Wed Dec 19, 2012 1:55 pm

Time Box Background on White Chart

#1 Postby stephen77 » Wed Dec 19, 2012 2:07 pm

I use the standard Black and White color scheme for my charts.

When selecting the color for the Time Box indicator, the result is wrong. The color on the chart seems to be a 'negative' of the selected color.

Attached image shows an example.
The color selected was light grey
But the color on chart is dark grey

I'd like to have a very light grey but cannot achieve this. I've tried every color available but cannot get any light ones at all.

Is there a way round this please.
Attachments
Untitled-1.jpg
Untitled-1.jpg (122.12 KiB) Viewed 14119 times

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

#2 Postby FT Support » Thu Dec 20, 2012 7:58 am

Sorry but there is no way to set exact color for this indicator because it depends on the background of the chart and indicator properties "do not know" about the chart background
Check our other product here:
http://www.forexcopier.com

stephen77
Posts: 10
Joined: Wed Dec 19, 2012 1:55 pm

#3 Postby stephen77 » Thu Dec 20, 2012 8:26 am

FT Support wrote:Sorry but there is no way to set exact color for this indicator because it depends on the background of the chart and indicator properties "do not know" about the chart background


That's a shame. Thank you for taking the time to answer my query. Much appreciated

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#4 Postby KelvinHand » Mon Dec 24, 2012 9:22 am

stephen77 wrote:
FT Support wrote:Sorry but there is no way to set exact color for this indicator because it depends on the background of the chart and indicator properties "do not know" about the chart background


That's a shame. Thank you for taking the time to answer my query. Much appreciated



Try the attached for your White Background. Hope it work for you.

Only alter the cmSrcInvert to cmSrcCopy.

Code: Select all

//---------------------------------------------------------------------------
// Timebox 2
//---------------------------------------------------------------------------
library TimeBox2;

uses
  windows,
  graphics,
  SysUtils,
  DateUtils,
  IndicatorInterfaceUnit,
  strUtils,
  Math;

var
  // External variables
  FromHour: integer = 8;
  ToHour: integer = 18;
  Color1: TColor = clBlue;
  displayText: boolean = true;

//---------------------------------------------------------------------------
// Initialize indicator
//---------------------------------------------------------------------------
procedure Init; stdcall;
begin
  // define properties
  IndicatorShortName('Time Box 2');
  SetOutputWindow(ow_ChartWindow);

  // register options
  AddSeparator('Common');

  RegOption('From hour', ot_Integer, FromHour);
  SetOptionRange('From hour', 0, 23);

  RegOption('To hour', ot_Integer, ToHour);
  SetOptionRange('To hour', 0, 23);

  RegOption('Fill color', ot_Color, Color1);

  RegOption('Display price range', ot_Boolean, displayText);

  // create buffers
  IndicatorBuffers(0);
end;

function GetObjName(startDate: TDateTime): ansiString;
begin
 result := format('TimeBoxText_%d_%d_%d_%d_%d_%d', [FromHour, ToHour, YearOf(startDate), MonthOf(startDate), DayOf(startDate), HourOf(startDate)]);
end;

function GetLabelText(highestPrice: double; lowestPrice: double): string;
begin
  result := 'range = ' + inttostr(round((highestPrice - lowestPrice) / Point)) + ' pips';
end;

procedure DisplayBoxText(startDate: TDateTime; highestPrice: double; lowestPrice: double);
begin
  if (ObjectExists(GetObjName(startDate))) then
  begin
    ObjectDelete(GetObjName(startDate));
  end;
  if (displayText) then begin
      ObjectCreate(GetObjName(startDate), obj_Text, 0, startDate, lowestPrice);
      ObjectSetText(GetObjName(startDate), GetLabelText(highestPrice, lowestPrice), 10, 'Arial', clGray);
      ObjectSet(GetObjName(startDate), OBJPROP_VALIGNMENT, tlTop);
      ObjectSet(GetObjName(startDate), OBJPROP_HALIGNMENT, taLeftJustify);
  end;
end;

//---------------------------------------------------------------------------
// Calculate requested bar
//---------------------------------------------------------------------------
procedure Calculate(index: integer); stdcall;
begin

end;

procedure DrawBox(startBarIndex: integer; endBarIndex: integer; bmp: TBitmap; ChartInfo: TChartInfo; canvas: TCanvas; R1: TRect);
var
 R: TRect;
 highestPrice, lowestPrice: double;
 startDate: TDateTime;
 startBoxIndex, endBoxIndex: integer;
begin
  if ((endBarIndex > ChartInfo.FirstIndex) or (startBarIndex < ChartInfo.LastIndex)) then
  begin
    exit;
  end;
       
  startBoxIndex := Min(startBarIndex, ChartInfo.FirstIndex);
  endBoxIndex := Max(endBarIndex, ChartInfo.LastIndex);

  highestPrice := High(iHighest(Symbol, Timeframe, MODE_HIGH, abs(startBarIndex - endBarIndex), endBarIndex));
  lowestPrice := Low(iLowest(Symbol, Timeframe, MODE_LOW, abs(startBarIndex - endBarIndex), endBarIndex));
  startDate := iTime(Symbol, Timeframe, startBoxIndex);
//  endDate := iTime(Symbol, Timeframe, endBoxIndex);
  R.Left := ChartToScrX(startBoxIndex) + (ChartInfo.BarWidth div 2);
  R.Right := ChartToScrX(endBoxIndex)- (ChartInfo.BarWidth div 2);
  R.Top := ChartToScrY(highestPrice);
  R.Bottom := ChartToScrY(lowestPrice);

  DisplayBoxText(startDate, highestPrice, lowestPrice);

  canvas.CopyRect(R, bmp.Canvas, R1);
end;

procedure DeleteAllObjStartingFrom(prefix: string);
var i: integer;
    objsToDelete: array of ansiString;
begin
   for I := 0 to ObjectsTotal - 1 do
   begin
     if Pos(prefix, ObjectName(i)) > 0 then
     begin
       SetLength(objsToDelete, Length(objsToDelete) + 1);
       objsToDelete[Length(objsToDelete) - 1] := ObjectName(i);
     end;
   end;

   for I := 0 to (Length(objsToDelete) - 1) do
   begin
     ObjectDelete(objsToDelete[i]);
   end;
end;

procedure DeleteAllAssocObjs();
begin
  DeleteAllObjStartingFrom(format('TimeBoxText_%d_%d', [FromHour, ToHour]));
end;

procedure DeleteAllTimeBoxObjs();
begin
  DeleteAllObjStartingFrom('TimeBoxText');
end;

//---------------------------------------------------------------------------
// paint
//---------------------------------------------------------------------------
procedure OnPaint(handle: integer); stdcall;
var
  canvas: TCanvas;
  ChartInfo: TChartInfo;
  i: integer;
  R1: TRect;
  bmp: TBitmap;
  startIndex, endIndex: integer;

  currentStartIndex: integer;
begin
  DeleteAllAssocObjs();

  if not(GetChartInfo(ChartInfo)) then
    exit;

  if ChartInfo.FirstIndex <= ChartInfo.LastIndex then
    exit;

  if Timeframe >= PERIOD_D1 then exit;

  bmp := TBitmap.Create;
  bmp.Width := 10;
  bmp.Height := 10;
  with bmp.Canvas do
    begin
      brush.Style := bsSolid;
      brush.Color := Color1;
      pen.Style := psClear;
      SetRect(R1, 0, 0, 10, 10);
      FillRect(R1);
    end;

  // create canvas
  canvas := TCanvas.Create;
  try
    canvas.Handle := handle;

    with canvas do
      begin
       //--KH: Change below ---
        canvas.CopyMode := cmSrcCopy; //cmSrcInvert;

        //
        currentStartIndex := 0;
        startIndex := Min(ChartInfo.FirstIndex + (PERIOD_D1 div Timeframe), Bars);
        endIndex := Max(ChartInfo.LastIndex - (PERIOD_D1 div Timeframe), 0);

        for i:=startIndex downto endIndex do
        begin
          if (HourOf(Time(i)) >= FromHour) and (HourOf(Time(i)) < ToHour) then
            begin
              if (currentStartIndex = 0) then
              begin
                currentStartIndex := i;
              end;
            end else
            begin
              if currentStartIndex<>0 then begin
                 DrawBox(currentStartIndex, i, bmp, ChartInfo, canvas, R1);
                 currentStartIndex := 0;
              end;
            end;
        end;

        if currentStartIndex<>0 then begin
           DrawBox(currentStartIndex, i, bmp, ChartInfo, canvas, R1);
           currentStartIndex := 0;
        end;

      end;

  finally
    canvas.Free;
    bmp.Free;
  end;
end;

procedure OnParametersChange; stdcall;
begin
  DeleteAllTimeBoxObjs();
end;

procedure Done; stdcall;
begin
  DeleteAllAssocObjs();
end;


exports

Init, Calculate, OnPaint, Done, OnParametersChange;

begin

end.


Attachments
Timebox2-BW.jpg
Timebox2-BW.jpg (118.89 KiB) Viewed 13758 times
Timebox2-WB.jpg
Timebox2-WB.jpg (224.49 KiB) Viewed 13758 times
TimeBox2.dll
(121.5 KiB) Downloaded 708 times

stephen77
Posts: 10
Joined: Wed Dec 19, 2012 1:55 pm

#5 Postby stephen77 » Thu Dec 27, 2012 9:14 am

KelvinHand wrote:

Try the attached for your White Background. Hope it work for you.

Only alter the cmSrcInvert to cmSrcCopy.


That works perfectly.
Thanks a lot KelvinHand, your help is much appreciated.
I haven't tried modifying ForexTester before and simply uploaded your file to the indicators folder and now have access to TimeBox 2 which allows pale colors on a white chart - Brilliant

KelvinHand
Posts: 103
Joined: Sun Jan 02, 2011 6:05 pm

#6 Postby KelvinHand » Thu Dec 27, 2012 9:57 am

stephen77 wrote:
KelvinHand wrote:

Try the attached for your White Background. Hope it work for you.

Only alter the cmSrcInvert to cmSrcCopy.


That works perfectly.
Thanks a lot KelvinHand, your help is much appreciated.
I haven't tried modifying ForexTester before and simply uploaded your file to the indicators folder and now have access to TimeBox 2 which allows pale colors on a white chart - Brilliant


Good to hear that solve your problem.
Remember, everyone had he blind spot. me too. Just that FT support design the timebox with special consideration and did not cater for that. I just lucky that trail by error with some good graphic programming book.

nothing to shame about.


Return to “Bug reports”

Who is online

Users browsing this forum: No registered users and 19 guests