Bonjour, ;)
Voilà j'ai compilé un petit EA, avec heure et minute programmable pour qu'il lance un sell stop et buy stop a une heure précise, mais seulement il prend en compte l'heure de mon PC et pas celle du graphique.
Alors ma question comment faire pour qu'il prenne en compte l'heure du graphique ?
Merci a ceux qui m'aiderons.
Voici le code
Voilà j'ai compilé un petit EA, avec heure et minute programmable pour qu'il lance un sell stop et buy stop a une heure précise, mais seulement il prend en compte l'heure de mon PC et pas celle du graphique.
Alors ma question comment faire pour qu'il prenne en compte l'heure du graphique ?
Merci a ceux qui m'aiderons.
Voici le code
Code
#include <stdlib.mqh>
#include <WinUser32.mqh>
// exported variables
extern string Fermeture_des_stops = "Tranche horaire";
extern int Minute30 = 36;
extern int HoursFrom25 = 15;
extern int HoursTo25 = 16;
extern string Ouverture_stops = "Tranche horaire";
extern int HoursFrom29 = 15;
extern int HoursTo29 = 16;
extern int Minute31 = 30;
extern int Minute2 = 30;
extern double BuyLots32 = 0.1;
extern int BuySlippage32 = 3;
extern int BuyStoploss32 = 10;
extern int BuyTakeprofit32 = 11;
extern int PriceOffset32 = 10;
extern double SellLots28 = 0.1;
extern int SellSlippage28 = 3;
extern int SellStoploss28 = 10;
extern int SellTakeprofit28 = 11;
extern int PriceOffset28 = 10;
// local variables
double PipValue=1; // this variable is here to support 5-digit brokers
bool Terminated = false;
string LF = "\n"; // use this in custom or utility blocks where you need line feeds
int NDigits = 4; // used mostly for NormalizeDouble in Flex type blocks
int ObjCount = 0; // count of all objects created on the chart, allows creation of objects with unique names
int current = 0;
int Hour30 = 1;
int Hour31 = 1;
int Hour2 = 1;
int init()
{
NDigits = Digits;
if (false) ObjectsDeleteAll(); // clear the chart
Comment(""); // clear the chart
}
// Expert start
int start()
{
if (Bars < 10)
{
Comment("Not enough bars");
return (0);
}
if (Terminated == true)
{
Comment("EA Terminated.");
return (0);
}
OnEveryTick7();
}
void OnEveryTick7()
{
if (true == false && false) PipValue = 10;
if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;
IfOrderExists10();
IfOrderExists13();
OnceAnHour30();
HoursFilter29();
}
void IfOrderExists10()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUY && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists)
{
DeletePendingOrder33();
}
}
void DeletePendingOrder33()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
bool ret = OrderDelete(OrderTicket(), Red);
if (ret == false)
{
Print("OrderDelete() error - ", ErrorDescription(GetLastError()));
}
}
}
}
void IfOrderExists13()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists)
{
DeletePendingOrder12();
}
}
void DeletePendingOrder12()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
bool ret = OrderDelete(OrderTicket(), Red);
if (ret == false)
{
Print("OrderDelete() error - ", ErrorDescription(GetLastError()));
}
}
}
}
void OnceAnHour30()
{
int datetime800 = TimeLocal();
int hour0 = TimeHour(datetime800);
int minute0 = TimeMinute(datetime800);
if (hour0 != Hour30 && minute0 == Minute30)
{
Hour30 = hour0;
HoursFilter25();
}
}
void HoursFilter25()
{
int datetime800 = TimeLocal();
int hour0 = TimeHour(datetime800);
if ((HoursFrom25 < HoursTo25 && hour0 >= HoursFrom25 && hour0 < HoursTo25) ||
(HoursFrom25 > HoursTo25 && (hour0 < HoursTo25 || hour0 >= HoursFrom25)))
{
IfOrderExists15();
IfOrderExists17();
}
}
void IfOrderExists15()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists)
{
DeletePendingOrder16();
}
}
void DeletePendingOrder16()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
bool ret = OrderDelete(OrderTicket(), Red);
if (ret == false)
{
Print("OrderDelete() error - ", ErrorDescription(GetLastError()));
}
}
}
}
void IfOrderExists17()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists)
{
DeletePendingOrder18();
}
}
void DeletePendingOrder18()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
bool ret = OrderDelete(OrderTicket(), Red);
if (ret == false)
{
Print("OrderDelete() error - ", ErrorDescription(GetLastError()));
}
}
}
}
void HoursFilter29()
{
int datetime800 = TimeLocal();
int hour0 = TimeHour(datetime800);
if ((HoursFrom29 < HoursTo29 && hour0 >= HoursFrom29 && hour0 < HoursTo29) ||
(HoursFrom29 > HoursTo29 && (hour0 < HoursTo29 || hour0 >= HoursFrom29)))
{
OnceAnHour31();
OnceAnHour2();
}
}
void OnceAnHour31()
{
int datetime800 = TimeLocal();
int hour0 = TimeHour(datetime800);
int minute0 = TimeMinute(datetime800);
if (hour0 != Hour31 && minute0 == Minute31)
{
Hour31 = hour0;
IfOrderDoesNotExist27();
}
}
void IfOrderDoesNotExist27()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_BUYSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists == false)
{
BuyPendingOrder32();
}
}
void BuyPendingOrder32()
{
int expire = TimeCurrent() + 60 * 60;
double price = NormalizeDouble(Ask, NDigits) + PriceOffset32*PipValue*Point;
double SL = price - BuyStoploss32*PipValue*Point;
if (BuyStoploss32 == 0) SL = 0;
double TP = price + BuyTakeprofit32*PipValue*Point;
if (BuyTakeprofit32 == 0) TP = 0;
if (60 == 0) expire = 0;
int ticket = OrderSend(Symbol(), OP_BUYSTOP, BuyLots32, price, BuySlippage32, SL, TP, "My Expert", 1, expire, Blue);
if (ticket == -1)
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void OnceAnHour2()
{
int datetime800 = TimeLocal();
int hour0 = TimeHour(datetime800);
int minute0 = TimeMinute(datetime800);
if (hour0 != Hour2 && minute0 == Minute2)
{
Hour2 = hour0;
IfOrderDoesNotExist26();
}
}
void IfOrderDoesNotExist26()
{
bool exists = false;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderType() == OP_SELLSTOP && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists == false)
{
SellPendingOrder28();
}
}
void SellPendingOrder28()
{
int expire = TimeCurrent() + 60 * 60;
double price = NormalizeDouble(Bid, NDigits) - PriceOffset28*PipValue*Point;
double SL = price + SellStoploss28*PipValue*Point;
if (SellStoploss28 == 0) SL = 0;
double TP = price - SellTakeprofit28*PipValue*Point;
if (SellTakeprofit28 == 0) TP = 0;
if (60 == 0) expire = 0;
int ticket = OrderSend(Symbol(), OP_SELLSTOP, SellLots28, price, SellSlippage28, SL, TP, "My Expert", 1, expire, Red);
if (ticket == -1)
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
int deinit()
{
if (false) ObjectsDeleteAll();
}