ProRealTime
Pour discuter sur l’interface de ProRealTime Software, nos configurations graphiques...
Répondre • Page 1 sur 1

Adapter un indicateur déjà codé

par KeKhou » 07 sept. 2018 18:02

Bonjour, j'ai trouvé en opensource un indicateur qui m'inetéresse, GravityCenter de Moustafa Belkhayate, mais qui est codé pour NinjaTrader, j'aimerai l'adapter pour qu'il marche sur ProRealTime mais je ne sais pas vraiment comment m'y prendre, s'il y a des programmeurs qui peuvent m'aider, je vous en serait reconnaissant.
Spoiler:
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion

// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Belkhayate Gravity")]
public class BelkhayateGravity : Indicator
{
#region Variables
// Wizard generated variables
private int period = 100; // Default setting for Period
private int order = 3; // Default setting for Order
private int addonRange1 = 13;
private int addonRange2 = 23;
private int addonRange3 = 37;
private int addonRange4 = 53;
private int addonMinute1 = 3;
private int addonMinute2 = 7;
private Color clrUp = Color.Lime;
private Color clrDown = Color.Red;
private DataSeries biasStrength;

int day = -1;
double [] pa;
int [] dir;
string alertCross = "alert1.wav";
string alertFat = "alert1.wav";
#endregion

/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{


Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "GC1"));
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Dot, "Thick1"));
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Dot, "Thick2"));
Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Dot, "Thick3"));
biasStrength = new DataSeries(this);
Plots[1].Pen.Width = 2;
Plots[2].Pen.Width = 3;
Plots[3].Pen.Width = 4;

if(Instrument != null)
{
if(BarsPeriod.Id == PeriodType.Minute)
{
if(BarsPeriod.Value < 5)
{
Add(PeriodType.Minute, 5);
Add(PeriodType.Minute, 15);
Add(PeriodType.Minute, 20);
Add(PeriodType.Minute, 30);
Add(PeriodType.Minute, 60);
Add(PeriodType.Minute, 240);
Add(PeriodType.Day, 1);
day = 7;
alertCross = "Daily line cross 1 to 3 min.wav";
alertFat = "Fat line greater than 3 1m.wav";
}
else if(BarsPeriod.Value == 5)
{
Add(PeriodType.Minute, 15);
Add(PeriodType.Minute, 20);
Add(PeriodType.Minute, 30);
Add(PeriodType.Minute, 60);
Add(PeriodType.Minute, 120);
Add(PeriodType.Minute, 240);
Add(PeriodType.Day, 1);
day = 7;
alertCross = "Daily line cross 5 to 30 min.wav";
alertFat = "Fat line greater than 3 5m.wav";
}
else if(BarsPeriod.Value > 5 && BarsPeriod.Value <= 15)
{
Add(PeriodType.Minute, 20);
Add(PeriodType.Minute, 30);
Add(PeriodType.Minute, 60);
Add(PeriodType.Minute, 120);
Add(PeriodType.Minute, 240);
Add(PeriodType.Minute, 720);
Add(PeriodType.Day, 1);
day = 7;
alertCross = "Daily line cross 5 to 30 min.wav";
alertFat = "Fat line greater than 3 15m.wav";
}
else if(BarsPeriod.Value > 15 && BarsPeriod.Value <= 30)
{
Add(PeriodType.Minute, 60);
Add(PeriodType.Minute, 120);
Add(PeriodType.Minute, 240);
Add(PeriodType.Minute, 720);
Add(PeriodType.Day, 1);
Add(PeriodType.Week, 1);
day = 5;
alertCross = "Daily line cross 5 to 30 min.wav";
alertFat = "Fat line greater than 3 30m.wav";
}
else if(BarsPeriod.Value > 30 && BarsPeriod.Value <= 60)
{
Add(PeriodType.Minute, 120);
Add(PeriodType.Minute, 240);
Add(PeriodType.Minute, 720);
Add(PeriodType.Day, 1);
Add(PeriodType.Week, 1);
Add(PeriodType.Month, 1);
day = 4;
alertCross = "Daily line cross higher.wav";
alertFat = "Fat line greater than 3 60m.wav";
}
}
else if(BarsPeriod.Id == PeriodType.Range)
{
Add(PeriodType.Range, addonRange1);
Add(PeriodType.Range, addonRange2);
Add(PeriodType.Range, addonRange3);
Add(PeriodType.Range, addonRange4);
Add(PeriodType.Minute, addonMinute1);
Add(PeriodType.Minute, addonMinute2);
//Add(PeriodType.Day, 1);
day = 7;
alertCross = "Daily line cross 1 to 3 min.wav";
alertFat = "Fat line greater than 3 1m.wav";
/*
if(BarsPeriod.Value <= 3)
{
Add(PeriodType.Range, 5);
Add(PeriodType.Range, 8);
Add(PeriodType.Range, 13);
Add(PeriodType.Range, 21);
Add(PeriodType.Minute, 60);
Add(PeriodType.Minute, 240);
Add(PeriodType.Day, 1);
day = 7;
alertCross = "Daily line cross 1 to 3 min.wav";
alertFat = "Fat line greater than 3 1m.wav";
}
else if(BarsPeriod.Value <= 5)
{
Add(PeriodType.Range, 8);
Add(PeriodType.Range, 13);
Add(PeriodType.Range, 21);
Add(PeriodType.Range, 34);
Add(PeriodType.Day, 1);
day = 5;
alertCross = "Daily line cross 1 to 3 min.wav";
alertFat = "Fat line greater than 3 1m.wav";
}
else if(BarsPeriod.Value <= 10)
{
Add(PeriodType.Range, 13);
Add(PeriodType.Range, 21);
Add(PeriodType.Range, 34);
Add(PeriodType.Range, 55);
Add(PeriodType.Day, 1);
Add(PeriodType.Week, 1);
day = 5;
alertCross = "Daily line cross 1 to 3 min.wav";
alertFat = "Fat line greater than 3 1m.wav";
}
else if(BarsPeriod.Value <= 15)
{
Add(PeriodType.Range, 21);
Add(PeriodType.Range, 34);
Add(PeriodType.Range, 55);
Add(PeriodType.Day, 1);
Add(PeriodType.Week, 1);
day = 4;
alertCross = "Daily line cross 1 to 3 min.wav";
alertFat = "Fat line greater than 3 1m.wav";
}
*/
}
}

pa = new double[8];
dir = new int[8];
for(int i = 0; i < 8; i++)
{
pa = 0;
dir = 0;
}
Overlay = true;
}

/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(CurrentBar < 10 + period) return;

double p1 = BCG(0.618, Order, Period).GravityLine[0];
double p2 = BCG(0.618, Order, Period).GravityLine[1];

if(BarsInProgress == 0)
{
biasStrength.Set(0);
GC1.Set(p1);
if(GC1[0] > GC1[1])
{
PlotColors[BarsInProgress][0] = UpColor;
biasStrength.Set(1);
}
else if(GC1[0] < GC1[1])
{
PlotColors[BarsInProgress][0] = DownColor;
biasStrength.Set(-1);
}
}

pa[BarsInProgress] = p1;
if(p1 > p2)
dir[BarsInProgress] = 1;
else if(p1 < p2)
dir[BarsInProgress] = -1;

int above = 0;
int below = 0;
for(int i = 1; i < 8; i++)
{
if(pa > 0)
{
if(pa[0] > pa)
above++;
else if(pa[0] < pa)
below++;
}
}
if(GC1[0] > GC1[1] && above > 0)
{
if(below == 0)
{
Thick3.Set(GC1[0]);
PlotColors[3][0] = UpColor;
biasStrength.Set(4);
}
if(above > below)
{
Thick2.Set(GC1[0]);
PlotColors[2][0] = UpColor;
biasStrength.Set(3);
}
else
{
Thick1.Set(GC1[0]);
PlotColors[1][0] = UpColor;
biasStrength.Set(2);
}
}
else if(GC1[0] < GC1[1] && below > 0)
{
if(above == 0)
{
Thick3.Set(GC1[0]);
PlotColors[3][0] = DownColor;
biasStrength.Set(-4);
}
if(below > above)
{
Thick2.Set(GC1[0]);
PlotColors[2][0] = DownColor;
biasStrength.Set(-3);
}
else
{
Thick1.Set(GC1[0]);
PlotColors[1][0] = DownColor;
biasStrength.Set(-2);
}
}
}

#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries GC1
{
get { return Values[0]; }
}

[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Thick1
{
get { return Values[1]; }
}

[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Thick2
{
get { return Values[2]; }
}

[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Thick3
{
get { return Values[3]; }
}

[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries BiasStrength
{
get { return biasStrength; }
}

[Description("")]
[GridCategory("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int Order
{
get { return order; }
set { order = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int AddonRange1
{
get { return addonRange1; }
set { addonRange1 = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int AddonRange2
{
get { return addonRange2; }
set { addonRange2 = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int AddonRange3
{
get { return addonRange3; }
set { addonRange3 = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int AddonRange4
{
get { return addonRange4; }
set { addonRange4 = Math.Max(1, value); }
}


[Description("")]
[GridCategory("Parameters")]
public int AddonMinute1
{
get { return addonMinute1; }
set { addonMinute1 = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public int AddonMinute2
{
get { return addonMinute2; }
set { addonMinute2 = Math.Max(1, value); }
}

[Description("")]
[GridCategory("Parameters")]
public Color UpColor
{
get { return clrUp; }
set { clrUp = value; }
}

[Description("")]
[GridCategory("Parameters")]
public Color DownColor
{
get { return clrDown; }
set { clrDown = value; }
}

[Browsable(false)]
public string UpColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString(clrUp); }
set { clrUp = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
}

[Browsable(false)]
public string DownColorSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString(clrDown); }
set { clrDown = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
}

#endregion
}
}

#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private BelkhayateGravity[] cacheBelkhayateGravity = null;

private static BelkhayateGravity checkBelkhayateGravity = new BelkhayateGravity();

/// <summary>
/// Belkhayate Gravity
/// </summary>
/// <returns></returns>
public BelkhayateGravity BelkhayateGravity(int addonMinute1, int addonMinute2, int addonRange1, int addonRange2, int addonRange3, int addonRange4, Color downColor, int order, int period, Color upColor)
{
return BelkhayateGravity(Input, addonMinute1, addonMinute2, addonRange1, addonRange2, addonRange3, addonRange4, downColor, order, period, upColor);
}

/// <summary>
/// Belkhayate Gravity
/// </summary>
/// <returns></returns>
public BelkhayateGravity BelkhayateGravity(Data.IDataSeries input, int addonMinute1, int addonMinute2, int addonRange1, int addonRange2, int addonRange3, int addonRange4, Color downColor, int order, int period, Color upColor)
{
if (cacheBelkhayateGravity != null)
for (int idx = 0; idx < cacheBelkhayateGravity.Length; idx++)
if (cacheBelkhayateGravity[idx].AddonMinute1 == addonMinute1 && cacheBelkhayateGravity[idx].AddonMinute2 == addonMinute2 && cacheBelkhayateGravity[idx].AddonRange1 == addonRange1 && cacheBelkhayateGravity[idx].AddonRange2 == addonRange2 && cacheBelkhayateGravity[idx].AddonRange3 == addonRange3 && cacheBelkhayateGravity[idx].AddonRange4 == addonRange4 && cacheBelkhayateGravity[idx].DownColor == downColor && cacheBelkhayateGravity[idx].Order == order && cacheBelkhayateGravity[idx].Period == period && cacheBelkhayateGravity[idx].UpColor == upColor && cacheBelkhayateGravity[idx].EqualsInput(input))
return cacheBelkhayateGravity[idx];

lock (checkBelkhayateGravity)
{
checkBelkhayateGravity.AddonMinute1 = addonMinute1;
addonMinute1 = checkBelkhayateGravity.AddonMinute1;
checkBelkhayateGravity.AddonMinute2 = addonMinute2;
addonMinute2 = checkBelkhayateGravity.AddonMinute2;
checkBelkhayateGravity.AddonRange1 = addonRange1;
addonRange1 = checkBelkhayateGravity.AddonRange1;
checkBelkhayateGravity.AddonRange2 = addonRange2;
addonRange2 = checkBelkhayateGravity.AddonRange2;
checkBelkhayateGravity.AddonRange3 = addonRange3;
addonRange3 = checkBelkhayateGravity.AddonRange3;
checkBelkhayateGravity.AddonRange4 = addonRange4;
addonRange4 = checkBelkhayateGravity.AddonRange4;
checkBelkhayateGravity.DownColor = downColor;
downColor = checkBelkhayateGravity.DownColor;
checkBelkhayateGravity.Order = order;
order = checkBelkhayateGravity.Order;
checkBelkhayateGravity.Period = period;
period = checkBelkhayateGravity.Period;
checkBelkhayateGravity.UpColor = upColor;
upColor = checkBelkhayateGravity.UpColor;

if (cacheBelkhayateGravity != null)
for (int idx = 0; idx < cacheBelkhayateGravity.Length; idx++)
if (cacheBelkhayateGravity[idx].AddonMinute1 == addonMinute1 && cacheBelkhayateGravity[idx].AddonMinute2 == addonMinute2 && cacheBelkhayateGravity[idx].AddonRange1 == addonRange1 && cacheBelkhayateGravity[idx].AddonRange2 == addonRange2 && cacheBelkhayateGravity[idx].AddonRange3 == addonRange3 && cacheBelkhayateGravity[idx].AddonRange4 == addonRange4 && cacheBelkhayateGravity[idx].DownColor == downColor && cacheBelkhayateGravity[idx].Order == order && cacheBelkhayateGravity[idx].Period == period && cacheBelkhayateGravity[idx].UpColor == upColor && cacheBelkhayateGravity[idx].EqualsInput(input))
return cacheBelkhayateGravity[idx];

BelkhayateGravity indicator = new BelkhayateGravity();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.Force mumBarsLookBack256 = Force mumBarsLookBack256;
indicator. mumBarsLookBack = mumBarsLookBack;
#endif
indicator.Input = input;
indicator.AddonMinute1 = addonMinute1;
indicator.AddonMinute2 = addonMinute2;
indicator.AddonRange1 = addonRange1;
indicator.AddonRange2 = addonRange2;
indicator.AddonRange3 = addonRange3;
indicator.AddonRange4 = addonRange4;
indicator.DownColor = downColor;
indicator.Order = order;
indicator.Period = period;
indicator.UpColor = upColor;
Indicators.Add(indicator);
indicator.SetUp();

BelkhayateGravity[] tmp = new BelkhayateGravity[cacheBelkhayateGravity == null ? 1 : cacheBelkhayateGravity.Length + 1];
if (cacheBelkhayateGravity != null)
cacheBelkhayateGravity.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheBelkhayateGravity = tmp;
return indicator;
}
}
}
}

// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Belkhayate Gravity
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.BelkhayateGravity BelkhayateGravity(int addonMinute1, int addonMinute2, int addonRange1, int addonRange2, int addonRange3, int addonRange4, Color downColor, int order, int period, Color upColor)
{
return _indicator.BelkhayateGravity(Input, addonMinute1, addonMinute2, addonRange1, addonRange2, addonRange3, addonRange4, downColor, order, period, upColor);
}

/// <summary>
/// Belkhayate Gravity
/// </summary>
/// <returns></returns>
public Indicator.BelkhayateGravity BelkhayateGravity(Data.IDataSeries input, int addonMinute1, int addonMinute2, int addonRange1, int addonRange2, int addonRange3, int addonRange4, Color downColor, int order, int period, Color upColor)
{
return _indicator.BelkhayateGravity(input, addonMinute1, addonMinute2, addonRange1, addonRange2, addonRange3, addonRange4, downColor, order, period, upColor);
}
}
}

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Belkhayate Gravity
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.BelkhayateGravity BelkhayateGravity(int addonMinute1, int addonMinute2, int addonRange1, int addonRange2, int addonRange3, int addonRange4, Color downColor, int order, int period, Color upColor)
{
return _indicator.BelkhayateGravity(Input, addonMinute1, addonMinute2, addonRange1, addonRange2, addonRange3, addonRange4, downColor, order, period, upColor);
}

/// <summary>
/// Belkhayate Gravity
/// </summary>
/// <returns></returns>
public Indicator.BelkhayateGravity BelkhayateGravity(Data.IDataSeries input, int addonMinute1, int addonMinute2, int addonRange1, int addonRange2, int addonRange3, int addonRange4, Color downColor, int order, int period, Color upColor)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");

return _indicator.BelkhayateGravity(input, addonMinute1, addonMinute2, addonRange1, addonRange2, addonRange3, addonRange4, downColor, order, period, upColor);
}
}
}
#endregion

Re: Adapter un indicateur déjà codé

par plataxis » 07 sept. 2018 20:29

Moi non mais il me semble que prt proposait des robots pour faire ce genre de chose, voire l'aide de programmeurs. Saurais tu au moins le commenter ? Parce que brut de code pour quelqu'un qui n'est pas au fait du code NT c'est pas limpide.

Re: Adapter un indicateur déjà codé

par KeKhou » 11 sept. 2018 17:07

Oui je comprend, il y a déjà quelques commentaires du créateur mais non je ne saurai pas le commenter plus que cela

Re: Adapter un indicateur déjà codé

par Burzum » 11 sept. 2018 17:17

si ça peut aider les programmeurs

https://www.prorealcode.com/topic/centre-de-gravite/

Re: Adapter un indicateur déjà codé

par Chouini l'ourson » 11 sept. 2018 20:35

Attention, c'est un indicateur qui repeint :evil:

Re: Adapter un indicateur déjà codé

par KeKhou » 13 sept. 2018 18:51

Oui je sais mais je pense qu'il peut être simpa j'ai très envie de le tester.

Merci Burz!

Re: Adapter un indicateur déjà codé

par Katana » 13 sept. 2018 20:32

ça veut dire quoi "un indicateur qui repeint" ?

Re: Adapter un indicateur déjà codé

par Chouini l'ourson » 13 sept. 2018 20:46

L'indicateur va te donner une valeur à l'instant T, mais ensuite, cette valeur va continuer à s'adapter au prix.
En gros, cet indicateur va te donner 100% de réussite si tu le backtest alors que si tu l'observe en temps réel, il ne te donnera aucun signal signal.

Re: Adapter un indicateur déjà codé

par Chouini l'ourson » 13 sept. 2018 20:49

C'est comme si le rsi cassait à la hausse la ligne des 80, puis quelques bougies plus tard le cours chute. Dans le cas d'un indicateur qui repeint, ton rsi va se rétracter sous la ligne des 80 pour ne pas générer un faux signal, alors que toi tu l'as bien vu franchir cette ligne quelques bougies auparavant.

Re: Adapter un indicateur déjà codé

par Katana » 16 sept. 2018 10:55

D'accord, merci Chouini

Sujets similaires
Adapter votre money management à vos objectifs
par Tonny47 » 26 août 2017 10:34 (3 Réponses)
Changer le nombre de ticks pour adapter la vitesse ?
par LouRichard » 29 mars 2018 17:56 (2 Réponses)
L’Esma va adapter le régime des pas de cotation
par Benoist Rousseau » 17 juil. 2018 05:40 (3 Réponses)
Adapter les GANs au trading ?
par Guipit » 03 mai 2019 12:27 (3 Réponses)
Adapter son levier en fonction de son Trading
Fichier(s) joint(s) par Benoist Rousseau » 07 oct. 2019 13:25 (1 Réponses)
Code indicateur
par benylio » 18 nov. 2014 18:50 (5 Réponses)
comment convertir un indicateur 1h en indicateur 1min
par Raiko » 09 août 2014 10:35 (11 Réponses)
ECe forum, Déjà 1 mois d'existence...
par HellionReign » 09 oct. 2011 12:24 (17 Réponses)
Deja debout?
par GDX23 » 23 nov. 2012 06:29 (18 Réponses)