Bonjour à tous.Puis-je savoir ce dont j'ai besoin pour que le code dessine la boîte et imprime le texte une seule fois après la fermeture du modèle de bougie détecté ?
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//---code start
int counted_bars=IndicatorCounted();
//---check for possible errors
if (counted_bars<0) return(-1);
//---last counted bar will be recounted
if (counted_bars>0) counted_bars--;
int limit=Bars-counted_bars;
for(int i = limit-1; i >= 0; i--)
{
if (i >= MathMin(Maxbars-1, rates_total-1-50)) continue;
double high1 = High[i];
double low1 = Low[i];
double open1 = Open[i];
double close1 = Close[i];
double high2 = High[i+1];
double low2 = Low[i+1];
Bar1[i] = EMPTY;
Bar2[i] = EMPTY;
Bar3[i] = EMPTY;
Bar4[i] = EMPTY;
int sigtf=0;
if(_Period==1440 || _Period==43200){sigtf=6;}
else{sigtf=5;}
int sigbox=0;
//double priceopen = iOpen(NULL,0,1);
//double priceclose = iClose(NULL,0,1);
if (high1>high2 && low1<low2 && close1>open1)
{
Bar1[i] = High[i];
Bar2[i] = Low[i];
Bar3[i] = Open[i];
Bar4[i] = Close[i];
sigbox = 1;
Print("test 1");
}
if(sigbox==1)
{
sigbox=0;
DrawBox("Area",i,Time[i],Bar1[i],Time[i]+((_Period*sigtf)*60),Bar2[i],clrGainsboro);
}
else
{
sigbox=0;
}
}
ChartRedraw(0);
//---code end
return(rates_total);
}
void DrawBox(string bxname, int i, datetime time1, double price1, datetime time2, double price2, color bxcolor)
{
string objname = objref+bxname+(string)i;
ObjectDelete(objname);
ObjectCreate(0,objname,OBJ_RECTANGLE,0,time1,price1,time2,price2);
ObjectSet(objname, OBJPROP_COLOR, bxcolor);
ObjectSet(objname, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(objname, OBJPROP_WIDTH, 0);
ObjectSet(objname, OBJPROP_FILL, true);
ObjectSet(objname, OBJPROP_BACK, false);
ObjectSet(objname, OBJPROP_SELECTABLE, false);
ObjectSet(objname, OBJPROP_HIDDEN, true);
}
#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("Enter the description of your new custom indicator here")]
publicclass NPSqueeze : Indicator
{
#region Variables
// Wizard generated variablesprivateint length = 20; // Default setting for Lengthprivatedouble bBDev = 2; // Default setting for BBDevprivatedouble kCDev = 1.5; // Default setting for KCDev// User defined variables (add any user defined variables below)#endregion
/// <summary>/// This method is used to configure the indicator and is called once before any bar data is loaded./// </summary>protectedoverridevoid Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Bar, "Squeeze"));
Overlay = false;
}
/// <summary>/// Called on each bar update event (incoming tick)/// </summary>protectedoverridevoid OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each// plot below by replacing 'Close[0]' with your own formula.double value = Bollinger(bBDev,length).Upper[0]-KeltnerChannel(kCDev,length).Upper[0] ;
Squeeze.Set(value);
}
#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 removepublic DataSeries Squeeze
{
get { return Values[0]; }
}
[Description("BB and KC average length")]
[GridCategory("Parameters")]
publicint Length
{
get { return length; }
set { length = Math.Max(1, value); }
}
[Description("BB deviations")]
[GridCategory("Parameters")]
publicdouble BBDev
{
get { return bBDev; }
set { bBDev = Math.Max(0, value); }
}
[Description("KC deviation in ATR's")]
[GridCategory("Parameters")]
publicdouble KCDev
{
get { return kCDev; }
set { kCDev = Math.Max(0, 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 NPSqueeze[] cacheNPSqueeze = null;
privatestatic NPSqueeze checkNPSqueeze = new NPSqueeze();
/// <summary>/// Enter the description of your new custom indicator here/// </summary>/// <returns></returns>public NPSqueeze NPSqueeze(double bBDev, double kCDev, int length)
{
return NPSqueeze(Input, bBDev, kCDev, length);
}
/// <summary>/// Enter the description of your new custom indicator here/// </summary>/// <returns></returns>public NPSqueeze NPSqueeze(Data.IDataSeries input, double bBDev, double kCDev, int length)
{
if (cacheNPSqueeze != null)
for (int idx = 0; idx < cacheNPSqueeze.Length; idx++)
if (Math.Abs(cacheNPSqueeze[idx].BBDev - bBDev) <= double.Epsilon && Math.Abs(cacheNPSqueeze[idx].KCDev - kCDev) <= double.Epsilon && cacheNPSqueeze[idx].Length == length && cacheNPSqueeze[idx].EqualsInput(input))
return cacheNPSqueeze[idx];
lock (checkNPSqueeze)
{
checkNPSqueeze.BBDev = bBDev;
bBDev = checkNPSqueeze.BBDev;
checkNPSqueeze.KCDev = kCDev;
kCDev = checkNPSqueeze.KCDev;
checkNPSqueeze.Length = length;
length = checkNPSqueeze.Length;
if (cacheNPSqueeze != null)
for (int idx = 0; idx < cacheNPSqueeze.Length; idx++)
if (Math.Abs(cacheNPSqueeze[idx].BBDev - bBDev) <= double.Epsilon && Math.Abs(cacheNPSqueeze[idx].KCDev - kCDev) <= double.Epsilon && cacheNPSqueeze[idx].Length == length && cacheNPSqueeze[idx].EqualsInput(input))
return cacheNPSqueeze[idx];
NPSqueeze indicator = new NPSqueeze();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.BBDev = bBDev;
indicator.KCDev = kCDev;
indicator.Length = length;
Indicators.Add(indicator);
indicator.SetUp();
NPSqueeze[] tmp = new NPSqueeze[cacheNPSqueeze == null ? 1 : cacheNPSqueeze.Length + 1];
if (cacheNPSqueeze != null)
cacheNPSqueeze.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheNPSqueeze = 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>/// Enter the description of your new custom indicator here/// </summary>/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.NPSqueeze NPSqueeze(double bBDev, double kCDev, int length)
{
return _indicator.NPSqueeze(Input, bBDev, kCDev, length);
}
/// <summary>/// Enter the description of your new custom indicator here/// </summary>/// <returns></returns>public Indicator.NPSqueeze NPSqueeze(Data.IDataSeries input, double bBDev, double kCDev, int length)
{
return _indicator.NPSqueeze(input, bBDev, kCDev, length);
}
}
}
// This namespace holds all strategies and is required. Do not change it.namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>/// Enter the description of your new custom indicator here/// </summary>/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.NPSqueeze NPSqueeze(double bBDev, double kCDev, int length)
{
return _indicator.NPSqueeze(Input, bBDev, kCDev, length);
}
/// <summary>/// Enter the description of your new custom indicator here/// </summary>/// <returns></returns>public Indicator.NPSqueeze NPSqueeze(Data.IDataSeries input, double bBDev, double kCDev, int length)
{
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.NPSqueeze(input, bBDev, kCDev, length);
}
}
}
J'ai besoin d'aide pour convertir un indicateur Ninja en MQL4, MT4.
J'ai développé un code MATLAB pour la prédiction du prix des paires forex pour le jour suivant. Maintenant, j'ai besoin d'un expert en mql4 qui peut lire un fichier .csv : contenant la date, l'heure, le symbole et le signal (buy=1, sell=-1 et 0=rien) avec SL, TP et LOTS constants.
Bonjour à tous ! J'ai une question et j'ai besoin d'aide s'il vous plaît. J'ai créé un EA basé sur plusieurs indicateurs d'entrée/sortie/TP/SL etc. Mon problème est qu'il ouvre trop de transactions. Ce que je veux dire c'est que : J'ai un indicateur de croisement de 2 lignes comme une des conditions pour ouvrir une transaction. Si l'indicateur se croise vers le haut + une autre condition, cela ouvre une transaction d'achat, si l'indicateur se croise vers le bas + une autre condition, cela ouvre une transaction de vente. Supposons donc que l'indicateur croise à la hausse, que toutes les autres conditions sont remplies et que la transaction est ouverte. Après quelques bougies, le TP est atteint et la transaction est fermée. Mais l'indicateur n'a pas encore basculé dans l'autre sens, et alors une autre transaction est ouverte. C'est ce que je veux arrêter dans certaines conditions. Par exemple, si l'indicateur s'est retourné il y a 7 bougies, n'ouvrez aucun trade. Ce que je veux dire, c'est que par exemple, une tendance se forme, tous mes indicateurs sont d'accord pour ouvrir un trade, le trade est ouvert, et le TP est atteint après 4-5 bougies. Et un autre ordre est ouvert mais peut-être que la tendance est presque terminée, et j'entre près du fond. Je veux changer cela. Créer une condition de telle sorte que si mon indicateur a basculé il y a [7] bougies, il ne faut pas ouvrir de transaction.
Bonjour, j'ai besoin d'ajouter un tampon à l'un de mes indicateurs et de le remplir avec une SMA (comme quelqu'un m'a suggéré de le faire pour un problème que je devais résoudre). Le problème, c'est que je ne sais pas trop comment faire. Quelqu'un pourrait-il m'aider ?
Si vous n'avez pas de compte, veuillez vous inscrire
Autorisez l'utilisation de cookies pour vous connecter au site Web MQL5.com.
Veuillez activer les paramètres nécessaires dans votre navigateur, sinon vous ne pourrez pas vous connecter.
Vous êtes connecté. L'authentification à deux facteurs a été désactivée. Configurez-la à nouveau et scannez un nouveau code QR, ou continuez avec l'authentification à deux facteurs désactivée.
Bonjour à tous.Puis-je savoir ce dont j'ai besoin pour que le code dessine la boîte et imprime le texte une seule fois après la fermeture du modèle de bougie détecté ?
//+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //---code start int counted_bars=IndicatorCounted(); //---check for possible errors if (counted_bars<0) return(-1); //---last counted bar will be recounted if (counted_bars>0) counted_bars--; int limit=Bars-counted_bars; for(int i = limit-1; i >= 0; i--) { if (i >= MathMin(Maxbars-1, rates_total-1-50)) continue; double high1 = High[i]; double low1 = Low[i]; double open1 = Open[i]; double close1 = Close[i]; double high2 = High[i+1]; double low2 = Low[i+1]; Bar1[i] = EMPTY; Bar2[i] = EMPTY; Bar3[i] = EMPTY; Bar4[i] = EMPTY; int sigtf=0; if(_Period==1440 || _Period==43200){sigtf=6;} else{sigtf=5;} int sigbox=0; //double priceopen = iOpen(NULL,0,1); //double priceclose = iClose(NULL,0,1); if (high1>high2 && low1<low2 && close1>open1) { Bar1[i] = High[i]; Bar2[i] = Low[i]; Bar3[i] = Open[i]; Bar4[i] = Close[i]; sigbox = 1; Print("test 1"); } if(sigbox==1) { sigbox=0; DrawBox("Area",i,Time[i],Bar1[i],Time[i]+((_Period*sigtf)*60),Bar2[i],clrGainsboro); } else { sigbox=0; } } ChartRedraw(0); //---code end return(rates_total); } void DrawBox(string bxname, int i, datetime time1, double price1, datetime time2, double price2, color bxcolor) { string objname = objref+bxname+(string)i; ObjectDelete(objname); ObjectCreate(0,objname,OBJ_RECTANGLE,0,time1,price1,time2,price2); ObjectSet(objname, OBJPROP_COLOR, bxcolor); ObjectSet(objname, OBJPROP_STYLE, STYLE_SOLID); ObjectSet(objname, OBJPROP_WIDTH, 0); ObjectSet(objname, OBJPROP_FILL, true); ObjectSet(objname, OBJPROP_BACK, false); ObjectSet(objname, OBJPROP_SELECTABLE, false); ObjectSet(objname, OBJPROP_HIDDEN, true); }comment faire une ligne horizontale mq4 avec votre propre valeur. svp
J'ai besoin d'aide pour convertir un indicateur Ninja en MQL4, MT4.
Rgds.
ok
Bonjour à tous les codeurs,
J'ai développé un code MATLAB pour la prédiction du prix des paires forex pour le jour suivant. Maintenant, j'ai besoin d'un expert en mql4 qui peut lire un fichier .csv : contenant la date, l'heure, le symbole et le signal (buy=1, sell=-1 et 0=rien) avec SL, TP et LOTS constants.
J'apprécierais que vous me le fournissiez.
Merci Maryam.
Ne doublez pas les messages! Tu avais déjà un autre fil ouvert.
Règles générales et bonnes pratiques du forum. -Général - Forum de programmation MQL5 (2017)