need Help for Alert in Stochastic

Posted By TradersIsland Monday, April 04, 2011
Add to Favorites0
Author Message
TradersIsland
 Posted Monday, April 04, 2011
Supreme Being

Supreme Being - (979 reputation)Supreme Being - (979 reputation)Supreme Being - (979 reputation)Supreme Being - (979 reputation)Supreme Being - (979 reputation)Supreme Being - (979 reputation)Supreme Being - (979 reputation)Supreme Being - (979 reputation)Supreme Being - (979 reputation)

Group: Forum Members
Last Active: Monday, May 23, 2011
Posts: 3, Visits: 63
979
Hi Traders,

i need Help, to modify an Stochastic Slow Indiacator that it send a Message if the Graph D or K Line or both cross from 20% or 80% to neutral zone...

....thanx for Help....Smile


i just post the Stochastice code...


const
IndicatorName = 'Stochastic';
Layout = Separated;

var
GraphK, GraphD: TLineGraph;
TSMA, SMAD: TSMAStatistics;
IsSlow: Boolean;
Period, AvPeriod, bot, topb: Integer;
bcolor:tcolor;

procedure CreateSettings;
begin
AddSetting('period', 'Period', '5');
AddSetting('avperiod', 'AveragePeriod', '3');
AddSetting('type', 'Type (Fast/Slow)', 'Slow');
AddSetting('color', '%K Color', 'clLime');
AddSetting('color2', '%D Color', 'clFuchsia');
AddSetting('bcolor', 'Border Color', 'clCream');
AddSetting('bot', 'Bottom border (%)', '20');
AddSetting('topb', 'Top border (%)', '80');
end;

procedure ApplySettings;
begin
Period := StrToInt(GetSetting('period'));
AvPeriod := StrToInt(GetSetting('avperiod'));

if GetSetting('type') = 'Slow' then IsSlow := True
else IsSlow := False;

GraphK.Color := StrToColor(GetSetting('color'));
GraphD.Color := StrToColor(GetSetting('color2'));
bcolor:= StrToColor(GetSetting('bcolor'));
bot:= StrToint(GetSetting('bot'));
topb:= StrToint(GetSetting('topb'));
SetTitle(IndicatorName +' '+ GetSetting('type') + ' (' + GetSetting('period') + ', ' + GetSetting('avperiod')+ ')' );

end;

procedure Init;
begin
GraphK := TLineGraph.Create;
GraphD := TLineGraph.Create;

TSMA := TSMAStatistics.Create;
SMAD := TSMAStatistics.Create;

SetYScale(0, 100);
end;

procedure Add(const ValueIndex: Integer);
var
LastTime: TDateTime;
n, i: Integer;
High, Low, HighI, LowI, KValue: Double;
IsKValue: Boolean;
begin
n := Trunc(Period) - 1;
if ValueIndex >= n then
begin
High := SourceGraph.HighValue(ValueIndex);
Low := SourceGraph.LowValue(ValueIndex);

for i := ValueIndex - n to ValueIndex - 1 do
begin
HighI := SourceGraph.HighValue(i);
LowI := SourceGraph.LowValue(i);
if HighI > High then High := HighI;
if LowI < Low then Low := LowI;
end;

if High <> Low then
KValue := 100.0 * (SourceGraph.CloseValue(ValueIndex) - Low) / (High - Low)
else
KValue := 0;

if IsSlow then
begin
TSMA.AddValue(KValue);
IsKValue := TSMA.HasValues;
if IsKValue then KValue := TSMA.LastValue;
end
else
IsKValue := True;

if IsKValue then
begin
GraphK.AddXY(SourceGraph.XValue(ValueIndex), KValue);
SMAD.AddValue(KValue);
if SMAD.HasValues then
GraphD.AddXY(SourceGraph.XValue(ValueIndex), SMAD.LastValue);
end;
end;
end;



procedure Recalculate;
begin
TSMA.Period := AvPeriod;
SMAD.Period := TSMA.Period;
FullRecalculation;
end;





procedure Draw;
var
Height, Y: Integer;
begin
Height := Bottom - Top;
Canvas.Pen.Color := bcolor;
Y := Bottom - Round(bot/100 * Height);
Canvas.Line(Left, Y, Right, Y);
Y := Bottom - Round(topb/100 * Height);
Canvas.Line(Left, Y, Right, Y);
end;


Tuesday, April 05, 2011 by TradersIsland
Admin
 Posted Thursday, January 05, 2012
Administrator

Administrator - (130,561 reputation)

Group: Administrators
Last Active: Friday, June 02, 2017
Posts: 548, Visits: 3,295
Dear TradersIsland,

It is much easier and more covenient to use Strategy with Stochastic notification than Indicator.
The example of such strategy is in attachment.


Best regards

-ACTFX© Forum Administrator
 stoch_info.acts (27 views, 1.06 KB)

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top