Bonsoir,
Voilà j'ai fais un petit EA pour placer des buy stop et sell stop a une heure précise seulement je ne comprend pas il fonctionne bien en back test mais en live il ne me place aucun stop buy et sell quand l'heure H arrive il ne me pose pas mes stop !
Voici le code si quelqu'un pourrais me dire pourquoi !
Merci a vous ;)
Voilà j'ai fais un petit EA pour placer des buy stop et sell stop a une heure précise seulement je ne comprend pas il fonctionne bien en back test mais en live il ne me place aucun stop buy et sell quand l'heure H arrive il ne me pose pas mes stop !
Voici le code si quelqu'un pourrais me dire pourquoi !
Merci a vous ;)
Code
#include <stdlib.mqh>
#include <WinUser32.mqh>
// exported variables
extern int OpenOrdersLimit17 = 2;
extern int Hour18 = 16;
extern int Minute18 = 20;
extern double BuyLots21 = 0.1;
extern int BuyStoploss21 = 3;
extern int BuyTakeprofit21 = 3;
extern int PriceOffset21 = 5;
extern double SellLots19 = 0.1;
extern int SellStoploss19 = 3;
extern int SellTakeprofit19 = 3;
extern int PriceOffset19 = 5;
// 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 Today18 = -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);
}
OnEveryTick14();
}
void OnEveryTick14()
{
if (true == false && false) PipValue = 10;
if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;
IfOrderExists2();
IfOrderExists3();
LimitOpenOrders17();
AtCertainTime18();
}
void IfOrderExists2()
{
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)
{
DeletePendingOrder4();
}
}
void DeletePendingOrder4()
{
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 IfOrderExists3()
{
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)
{
DeletePendingOrder5();
}
}
void DeletePendingOrder5()
{
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 LimitOpenOrders17()
{
int count = 0;
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol())
if (OrderMagicNumber() == 1)
{
count++;
}
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
if (count < OpenOrdersLimit17)
{
}
}
void AtCertainTime18()
{
int datetime800 = TimeLocal();
int hour0 = TimeHour(datetime800);
int minute0 = TimeMinute(datetime800);
if (DayOfWeek() != Today18 && hour0 == Hour18 && minute0 == Minute18)
{
Today18 = DayOfWeek();
IfOrderDoesNotExist20();
IfOrderDoesNotExist16();
}
}
void IfOrderDoesNotExist20()
{
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)
{
BuyPendingOrder21();
}
}
void BuyPendingOrder21()
{
int expire = TimeCurrent() + 60 * 120;
double price = NormalizeDouble(Ask, NDigits) + PriceOffset21*PipValue*Point;
double SL = price - BuyStoploss21*PipValue*Point;
if (BuyStoploss21 == 0) SL = 0;
double TP = price + BuyTakeprofit21*PipValue*Point;
if (BuyTakeprofit21 == 0) TP = 0;
if (120 == 0) expire = 0;
int ticket = OrderSend(Symbol(), OP_BUYSTOP, BuyLots21, price, 3, SL, TP, "My Expert", 1, expire, Blue);
if (ticket == -1)
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void IfOrderDoesNotExist16()
{
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)
{
SellPendingOrder19();
}
}
void SellPendingOrder19()
{
int expire = TimeCurrent() + 60 * 120;
double price = NormalizeDouble(Bid, NDigits) - PriceOffset19*PipValue*Point;
double SL = price + SellStoploss19*PipValue*Point;
if (SellStoploss19 == 0) SL = 0;
double TP = price - SellTakeprofit19*PipValue*Point;
if (SellTakeprofit19 == 0) TP = 0;
if (120 == 0) expire = 0;
int ticket = OrderSend(Symbol(), OP_SELLSTOP, SellLots19, price, 3, SL, TP, "My Expert", 1, expire, Red);
if (ticket == -1)
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
int deinit()
{
if (false) ObjectsDeleteAll();
}
Modifié le 2013-10-11 21:40:20 par
stepaustras