Kindly convert this code for Multichart (code working in ActFX):
const
IndicatorName = 'Inside Bars';
Layout = Embedded;
var
InsB_up, InsB_dn : TPointGraph;
Dist, NumberOfBars, MinLength, count_ins_bars: Integer;
start_pos, length_pos: array of integer;
allow:boolean;
procedure CreateSettings;
begin
AddSetting('NumberOfBars', 'Number Of Bars', '150');
AddSetting('MinLength', 'Min Length (more or equal 2)', '5');
AddSetting('Dist', 'Distance between beginnig of inside bars', '5');
AddSetting('upcolor', 'Magic up Color', 'clLime');
AddSetting('dwcolor', 'Magic down Color', 'clFuchsia');
end;
procedure ApplySettings;
begin
MinLength := StrToInt(GetSetting('MinLength'));
if MinLength<2 then MinLength:=2;
NumberOfBars := StrToInt(GetSetting('NumberOfBars'));
Dist := StrToInt(GetSetting('Dist'));
InsB_up.Color := StrToColor(GetSetting('upcolor'));
InsB_dn.Color := StrToColor(GetSetting('dwcolor'));
SetTitle(IndicatorName + ' (' + GetSetting('NumberOfBars')+', '+ GetSetting('MinLength') + ')');
count_ins_bars:=0;
SetLength(start_pos, SourceGraph.count);
SetLength(length_pos, SourceGraph.count);
allow:=true;
if (SourceGraph.count<NumberOfBars) then
begin
showmessage('Not enough candles to create this indicator with NumberOfBars='+inttostr(NumberOfBars)+'. Please add more candles');
allow:=false;
end;
end;
procedure Init;
begin
InsB_up := TPointGraph.Create();
InsB_dn := TPointGraph.Create();
end;
procedure Recalculate;
begin
FullRecalculation;
SetLength(start_pos, SourceGraph.count);
SetLength(length_pos, SourceGraph.count);
count_ins_bars:=0;
allow:=true;
if (SourceGraph.count<NumberOfBars) then
begin
showmessage('Not enough candles to create this indicator with NumberOfBars='+inttostr(NumberOfBars)+'. Please add more candles');
allow:=false;
end;
end;
procedure Add(const ValueIndex: Integer);
var
i, j, count_candle: Integer;
start_candle_h, start_candle_l:double;
begin
if allow and (ValueIndex>= (SourceGraph.count-NumberOfBars-1)) then
begin
start_candle_h:=SourceGraph.HighValue(ValueIndex-(MinLength-1));
start_candle_l:=SourceGraph.LowValue(ValueIndex-(MinLength-1));
count_candle:=0;
for i:=1 to MinLength-1 do
begin
if (start_candle_h>SourceGraph.HighValue(ValueIndex-(MinLength-1)+i)) and (start_candle_l<SourceGraph.LowValue(ValueIndex-(MinLength-1)+i)) then
begin
inc(count_candle);
end;
end;
if count_candle=MinLength-1 then
begin
i:=1;
while (start_candle_h>SourceGraph.HighValue(ValueIndex+i)) and (start_candle_l<SourceGraph.LowValue(ValueIndex+i)) do
begin
inc(i);
inc(count_candle);
end;
inc(count_ins_bars);
start_pos[count_ins_bars]:=ValueIndex-(MinLength-1);
length_pos[count_ins_bars]:=count_candle;
end;
end;
if allow and (ValueIndex = SourceGraph.count-1) then
begin
for i:=1 to count_ins_bars do
begin
if (i>0) and ((start_pos-start_pos[i-1])>=Dist) then
begin
for j:=0 to 2*(length_pos) do
begin
InsB_up.AddXY(SourceGraph.XValue(start_pos)+j/2, SourceGraph.HighValue(start_pos));
InsB_dn.AddXY(SourceGraph.XValue(start_pos)+j/2, SourceGraph.LowValue(start_pos));
end;
end;
end;
end;
end;
Inside bar breakout - Need to fix
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Inside bar breakout - Need to fix
Hello ravidevt,
Please contact us directly if you are interested in our custom programming services.
Please contact us directly if you are interested in our custom programming services.