Toute question des nouveaux arrivants sur MQL4 et MQL5, aide et discussion sur les algorithmes et les codes. - page 5
Vous manquez des opportunités de trading :
- Applications de trading gratuites
- Plus de 8 000 signaux à copier
- Actualités économiques pour explorer les marchés financiers
Inscription
Se connecter
Vous acceptez la politique du site Web et les conditions d'utilisation
Si vous n'avez pas de compte, veuillez vous inscrire
Mais comment le faire étape par étape ? ..... objets graphiques (quels sont-ils et comment les mettre), mettre des étiquettes de données sur le graphique (où entrer et avec quelles données) ...... désolé pour les questions idiotes.
Logiciel.
Vous devez écrire un indicateur d'information avec les données que vous voulez.
Ensuite, si le RSI a franchi le niveau il y a 20 minutes, nous vérifions le prix, c'est-à-dire que pour être short, le prix doit être inférieur à celui d'il y a 20 minutes. Merci beaucoup. Si ça marche, je te dois une promesse))
Puisque nous le créons au plus près de MQL5, nous n'utiliserons pas les fonctions MQL4 pour obtenir le décalage de barre par temps et le prix de clôture (iBarShift() et iClose() respectivement).
Nous avons nos propres fonctions pour cela : GetBarShift() et GetPriceClose(). De plus, nous devrons obtenir l'heure de la barre en utilisant la fonction GetTime() au lieu de iTime(), puisque nous rejetons les fonctions standard de MQL4.
Voici un test de conseiller expert :
//| exTestValueRSI.mq4 |
//| Copyright 2016, Artem A. Trishkin, Skype artmedia70 |
//| https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Artem A. Trishkin, Skype artmedia70"
#property link "https://login.mql5.com/ru/users/artmedia70"
#property version "1.00"
#property strict
//--- input parameters
input ENUM_TIMEFRAMES TimeframeRSI = PERIOD_M15; // Таймфрейм RSI
input int PeriodRSI = 14; // Период расчёта RSI
input ENUM_APPLIED_PRICE PriceRSI = PRICE_CLOSE; // Цена расчёта RSI
input int MinutesBefore =20; // Количество минут назад
//--- global variables
int minutesBefore; // Количество минут назад
int periodRSI; // Период расчёта RSI
//---
double prevRSIvalue0; // Значение RSI для заданного тф xxx минут назад
double prevRSIvalue1; // Значение RSI для заданного тф xxx минут назад-x минут
//---
double prevClose_0; // Значение Close для заданного тф xxx минут назад
double prevClose_1; // Значение Close для заданного тф xxx минут назад-x минут
//---
datetime timeBefore; // Время ххх минут назад
datetime timePrevBefore; // Время ххх минут назад-x минут
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
minutesBefore=(MinutesBefore<1?1:MinutesBefore); // Количество минут назад
periodRSI=(PeriodRSI<1?1:PeriodRSI);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
int shift_0;
int shift_1;
//---
MqlDateTime server_time;
TimeToStruct(TimeCurrent(),server_time);
string tf=EnumToString(TimeframeRSI);
//--- если значение минут серверного времени кратно заданному значению, в частности 20-ти минутам или равно 0
if(server_time.min%minutesBefore==0 || server_time.min==0) {
//--- время 1x и 2x минут назад
timeBefore=TimeCurrent()-minutesBefore*PeriodSeconds(PERIOD_M1);
timePrevBefore=TimeCurrent()-2*minutesBefore*PeriodSeconds(PERIOD_M1);
//--- смещение в барах времени 1х и 2х для заданного таймфрейма RSI (тф М15)
shift_0=GetBarShift(Symbol(),TimeframeRSI,timeBefore);
shift_1=GetBarShift(Symbol(),TimeframeRSI,timePrevBefore);
//--- значения RSI на барах 1х и 2х минут назад для заданного таймфрейма RSI (тф М15)
prevRSIvalue0=GetLastDataRSI(Symbol(),TimeframeRSI,shift_0);
prevRSIvalue1=GetLastDataRSI(Symbol(),TimeframeRSI,shift_1);
//--- значения цен закрытия баров 1х и 2х минут назад
prevClose_0=GetPriceClose(Symbol(),TimeframeRSI,shift_0);
prevClose_1=GetPriceClose(Symbol(),TimeframeRSI,shift_1);
}
Comment("\nТекущее время: ",TimeCurrent(),
"\nВремя ",minutesBefore," минут назад: ",TimeCurrent()-minutesBefore*PeriodSeconds(PERIOD_M1),
"\nБар ",tf,"_0=",shift_0,", бар ",tf,"_1=",shift_1,
"\nМинуты текущего времени: ",server_time.min,
"\nЗначение RSI ",minutesBefore," минут назад на ",tf," : ",DoubleToString(prevRSIvalue0,4),
"\nЗначение RSI ",minutesBefore*2," минут назад на ",tf," : ",DoubleToString(prevRSIvalue1,4),
//---
"\nЗначение Close ",minutesBefore," минут назад > ",tf," : ",DoubleToString(prevClose_0,Digits()),
"\nЗначение Close ",minutesBefore*2," минут назад > ",tf," : ",DoubleToString(prevClose_1,Digits())
);
}
//+------------------------------------------------------------------+
double GetLastDataRSI(string symbol_name, ENUM_TIMEFRAMES timeframe, int shift, int period_rsi=14, ENUM_APPLIED_PRICE price_rsi=PRICE_CLOSE) {
return(iRSI(symbol_name,timeframe,period_rsi,price_rsi,shift));
}
//+------------------------------------------------------------------+
double GetPriceClose(string symbol_name,ENUM_TIMEFRAMES timeframe, int shift){
double array[1];
if(CopyClose(symbol_name,timeframe,shift,1,array)==1) return(array[0]);
return(-1);
}
//+------------------------------------------------------------------+
int GetBarShift(string symbol_name,ENUM_TIMEFRAMES timeframe,datetime time) {
if(time<0) return(-1);
//---
datetime array[], time0;
if(CopyTime(symbol_name,timeframe,0,1,array)<0) return(-1);
time0=array[0];
if(CopyTime(symbol_name,timeframe,time0,time,array)<0) return(-1);
datetime temptime=GetTime(symbol_name,timeframe,ArraySize(array)-1);
if(array[0]==temptime && temptime<=time) return(ArraySize(array)-1);
else return(ArraySize(array));
}
//+------------------------------------------------------------------+
datetime GetTime(string symbol_name,ENUM_TIMEFRAMES timeframe,int bar) {
if(bar<0) return(-1);
datetime array[];
if(CopyTime(symbol_name,timeframe,bar,1,array)>0) return(array[0]);
return(-1);
}
//+------------------------------------------------------------------+
Maintenant, nous devons créer une fonction séparée pour recevoir les données RSI pour le temps requis et comparer les prix et les valeurs RSI.
Puisque nous le créons au plus près de MQL5, nous n'utiliserons pas les fonctions MQL4 pour obtenir le décalage de barre par temps et le prix de clôture (iBarShift() et iClose() respectivement).
Nous avons nos propres fonctions pour cela : GetBarShift() et GetPriceClose(). De plus, nous devrons obtenir l'heure de la barre en utilisant la fonction GetTime() au lieu de iTime(), puisque nous rejetons les fonctions standard de MQL4.
Voici un test de conseiller expert :
//| exTestValueRSI.mq4 |
//| Copyright 2016, Artem A. Trishkin, Skype artmedia70 |
//| https://login.mql5.com/ru/users/artmedia70 |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, Artem A. Trishkin, Skype artmedia70"
#property link "https://login.mql5.com/ru/users/artmedia70"
#property version "1.00"
#property strict
//--- input parameters
input ENUM_TIMEFRAMES TimeframeRSI = PERIOD_M15; // Таймфрейм RSI
input int PeriodRSI = 14; // Период расчёта RSI
input ENUM_APPLIED_PRICE PriceRSI = PRICE_CLOSE; // Цена расчёта RSI
input int MinutesBefore =20; // Количество минут назад
//--- global variables
int minutesBefore; // Количество минут назад
int periodRSI; // Период расчёта RSI
//---
double prevRSIvalue0; // Значение RSI для заданного тф xxx минут назад
double prevRSIvalue1; // Значение RSI для заданного тф xxx минут назад-x минут
//---
double prevClose_0; // Значение Close для заданного тф xxx минут назад
double prevClose_1; // Значение Close для заданного тф xxx минут назад-x минут
//---
datetime timeBefore; // Время ххх минут назад
datetime timePrevBefore; // Время ххх минут назад-x минут
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
minutesBefore=(MinutesBefore<1?1:MinutesBefore); // Количество минут назад
periodRSI=(PeriodRSI<1?1:PeriodRSI);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
int shift_0;
int shift_1;
//---
MqlDateTime server_time;
TimeToStruct(TimeCurrent(),server_time);
string tf=EnumToString(TimeframeRSI);
//--- если значение минут серверного времени кратно заданному значению, в частности 20-ти минутам или равно 0
if(server_time.min%minutesBefore==0 || server_time.min==0) {
//--- время 1x и 2x минут назад
timeBefore=TimeCurrent()-minutesBefore*PeriodSeconds(PERIOD_M1);
timePrevBefore=TimeCurrent()-2*minutesBefore*PeriodSeconds(PERIOD_M1);
//--- смещение в барах времени 1х и 2х для заданного таймфрейма RSI (тф М15)
shift_0=GetBarShift(Symbol(),TimeframeRSI,timeBefore);
shift_1=GetBarShift(Symbol(),TimeframeRSI,timePrevBefore);
//--- значения RSI на барах 1х и 2х минут назад для заданного таймфрейма RSI (тф М15)
prevRSIvalue0=GetLastDataRSI(Symbol(),TimeframeRSI,shift_0);
prevRSIvalue1=GetLastDataRSI(Symbol(),TimeframeRSI,shift_1);
//--- значения цен закрытия баров 1х и 2х минут назад
prevClose_0=GetPriceClose(Symbol(),TimeframeRSI,shift_0);
prevClose_1=GetPriceClose(Symbol(),TimeframeRSI,shift_1);
}
Comment("\nТекущее время: ",TimeCurrent(),
"\nВремя ",minutesBefore," минут назад: ",TimeCurrent()-minutesBefore*PeriodSeconds(PERIOD_M1),
"\nБар ",tf,"_0=",shift_0,", бар ",tf,"_1=",shift_1,
"\nМинуты текущего времени: ",server_time.min,
"\nЗначение RSI ",minutesBefore," минут назад на ",tf," : ",DoubleToString(prevRSIvalue0,4),
"\nЗначение RSI ",minutesBefore*2," минут назад на ",tf," : ",DoubleToString(prevRSIvalue1,4),
//---
"\nЗначение Close ",minutesBefore," минут назад > ",tf," : ",DoubleToString(prevClose_0,Digits()),
"\nЗначение Close ",minutesBefore*2," минут назад > ",tf," : ",DoubleToString(prevClose_1,Digits())
);
}
//+------------------------------------------------------------------+
double GetLastDataRSI(string symbol_name, ENUM_TIMEFRAMES timeframe, int shift, int period_rsi=14, ENUM_APPLIED_PRICE price_rsi=PRICE_CLOSE) {
return(iRSI(symbol_name,timeframe,period_rsi,price_rsi,shift));
}
//+------------------------------------------------------------------+
double GetPriceClose(string symbol_name,ENUM_TIMEFRAMES timeframe, int shift){
double array[1];
if(CopyClose(symbol_name,timeframe,shift,1,array)==1) return(array[0]);
return(-1);
}
//+------------------------------------------------------------------+
int GetBarShift(string symbol_name,ENUM_TIMEFRAMES timeframe,datetime time) {
if(time<0) return(-1);
//---
datetime array[], time0;
if(CopyTime(symbol_name,timeframe,0,1,array)<0) return(-1);
time0=array[0];
if(CopyTime(symbol_name,timeframe,time0,time,array)<0) return(-1);
datetime temptime=GetTime(symbol_name,timeframe,ArraySize(array)-1);
if(array[0]==temptime && temptime<=time) return(ArraySize(array)-1);
else return(ArraySize(array));
}
//+------------------------------------------------------------------+
datetime GetTime(string symbol_name,ENUM_TIMEFRAMES timeframe,int bar) {
if(bar<0) return(-1);
datetime array[];
if(CopyTime(symbol_name,timeframe,bar,1,array)>0) return(array[0]);
return(-1);
}
//+------------------------------------------------------------------+
Nous devons maintenant créer une fonction distincte pour obtenir les données RSI à partir du moment souhaité et comparer les prix et les valeurs RSI.
{
ticket=OrderSend(Symbol(),OP_SELL, 0.1, Ask, Slippage,0, 0, NULL, Magic, 0, Blue);
return(0);
}
{
int ticket;
if (OrdersTotal() == 0)
{
ticket=OrderSend(Symbol(),OP_SELL, 1, Bid, 0, 0, 0, NULL, 1234, 0, Red);
}
return(0);
}
Je l'ai mis à la fin du code pour vérifier :
{
int ticket;
if (OrdersTotal() == 0)
{
ticket=OrderSend(Symbol(),OP_SELL, 1, Bid, 0, 0, 0, NULL, 1234, 0, Red);
}
return(0);
}
Qui vous empêche d'afficher le code d'erreur?
Qui vous empêche d'afficher le code d'erreur?
Chers utilisateurs du forum, Voici la question :
Est-il possible dans un bloc de tique
int start() {}
Créez un événement qui, lorsqu'il est exécuté, affiche une fenêtre pop-up dans laquelle vous pouvez définir manuellement la valeur d'une variable.
C'est similaire à ce qui se passe lorsque vous définissez une variable via Extern, mais automatiquement pendant l'exécution du programme, plutôt qu'une fois au démarrage.
Je vous serais reconnaissant si vous pouviez au moins me dire dans quel sens creuser.
Merci !
Chers utilisateurs du forum, Voici la question :
Est-il possible dans un bloc de tique
int start() {}
Créez un événement qui, lorsqu'il est exécuté, affiche une fenêtre pop-up dans laquelle vous pouvez définir manuellement la valeur d'une variable.
C'est similaire à ce qui se passe lorsque vous définissez une variable via Extern, mais automatiquement pendant l'exécution du programme, plutôt qu'une fois au démarrage.
Je vous serais reconnaissant si vous pouviez au moins me dire dans quel sens creuser.
Merci !
Chers membres du forum, Voici la question :
Est-il possible dans un bloc de tique
int start() {}
Créez un événement qui, lorsqu'il est exécuté, affiche une fenêtre pop-up dans laquelle vous pouvez définir manuellement la valeur d'une variable.
Cela est similaire à ce qui se passe lorsque vous définissez une variable avec Extern, mais automatiquement pendant l'exécution du programme plutôt qu'une fois au démarrage.
Je vous serais reconnaissant si vous me disiez au moins dans quelle direction creuser.
Merci !
Creuser vers les objets graphiques. Le champ de saisie en particulier est OBJ_EDIT.
Voici une fonction pour le créer sur un graphique :
void SetEditField(const long chart_id=0, // ID графика
const string name="Edit", // имя объекта
const int sub_window=0, // номер подокна
const int x=0, // координата по оси X
const int y=0, // координата по оси Y
const int width=50, // ширина поля ввода
const int height=18, // высота поля ввода
const string text="Text", // текст
const string font="Calibri", // шрифт
const int font_size=8, // размер шрифта
const ENUM_ALIGN_MODE align=ALIGN_CENTER, // способ выравнивания
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // угол графика для привязки
const long z_order=0, // приоритет на нажатие мышью
const color clr=clrBlack, // цвет текста
const color back_clr=clrWhite, // цвет фона
const color border_clr=clrNONE, // цвет границы
const bool back=false, // на заднем плане
const bool read_only=false, // возможность редактировать
const bool selection=false, // выделить для перемещений
const bool hidden=true) // скрыт в списке объектов
{
if(ObjectFind(chart_id,name)<0) ObjectCreate(chart_id,name,OBJ_EDIT,sub_window,0,0);
ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,y);
ObjectSetInteger(chart_id,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_id,name,OBJPROP_YSIZE,height);
ObjectSetString(chart_id,name,OBJPROP_TEXT,text);
ObjectSetString(chart_id,name,OBJPROP_FONT,font);
ObjectSetInteger(chart_id,name,OBJPROP_FONTSIZE,font_size);
ObjectSetInteger(chart_id,name,OBJPROP_ALIGN,align);
ObjectSetInteger(chart_id,name,OBJPROP_READONLY,read_only);
ObjectSetInteger(chart_id,name,OBJPROP_CORNER,corner);
ObjectSetInteger(chart_id,name,OBJPROP_COLOR,clr);
ObjectSetInteger(chart_id,name,OBJPROP_BGCOLOR,back_clr);
ObjectSetInteger(chart_id,name,OBJPROP_BORDER_COLOR,border_clr);
ObjectSetInteger(chart_id,name,OBJPROP_BACK,back);
ObjectSetInteger(chart_id,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_id,name,OBJPROP_SELECTED,selection);
ObjectSetInteger(chart_id,name,OBJPROP_HIDDEN,hidden);
ObjectSetInteger(chart_id,name,OBJPROP_ZORDER,z_order);
}
//+------------------------------------------------------------------+