Hi,
Plz, could somebody insert into this ea an option, the code for forcing a reverse trade ?
tnx
//--------------------------------------------------------
// Expert Advisor By Bodisatva
//--------------------------------------------------------
#property copyright "Copyright Bodisatva"
#property link "...."
#include <stdlib.mqh>
// exported variables
extern double BuyLots4 = 0.1;
extern int BuyStoploss4 = 20;
extern int BuyTakeprofit4 = 30;
extern double SellLots10 = 0.1;
extern int SellStoploss10 = 20;
extern int SellTakeprofit10 = 30;
// local variables
double PipValue=1; // this variable is here to support 5-digit brokers
bool Terminated = false;
int init()
{
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);
}
OnEveryTick1();
}
void OnEveryTick1()
{
if (true) PipValue = 10;
TechnicalAnalysis2();
TechnicalAnalysis8();
}
void TechnicalAnalysis2()
{
if (iAlligator(NULL, NULL,5,10,20,6,3,1,MODE_SMA,PRICE_CLOSE,MODE_GATORLIPS,0) < iCCI(NULL, NULL,20,PRICE_CLOSE,0))
{
BuyOrder4();
}
}
void BuyOrder4()
{
double SL = Ask - BuyStoploss4*PipValue*Point;
if (BuyStoploss4 == 0) SL = 0;
double TP = Ask + BuyTakeprofit4*PipValue*Point;
if (BuyTakeprofit4 == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_BUY, BuyLots4, Ask, 2, 0, 0, "My Expert", 1, 0, Blue);
else
ticket = OrderSend(Symbol(), OP_BUY, BuyLots4, Ask, 2, SL, TP, "My Expert", 1, 0, Blue);
if (ticket > -1)
{
if (true)
{
OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
CloseOrder6();
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void CloseOrder6()
{
int orderstotal = OrdersTotal();
int orders = 0;
int ordticket[30][2];
for (int i = 0; i < orderstotal; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
{
continue;
}
ordticket[orders][0] = OrderOpenTime();
ordticket[orders][1] = OrderTicket();
orders++;
}
if (orders > 1)
{
ArrayResize(ordticket,orders);
ArraySort(ordticket);
}
for (i = 0; i < orders; i++)
{
if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
{
bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 2, Red);
if (ret == false)
Print("OrderClose() error - ", ErrorDescription(GetLastError()));
}
}
}
void TechnicalAnalysis8()
{
if (iAlligator(NULL, NULL,5,10,20,6,3,1,MODE_SMA,PRICE_CLOSE,MODE_GATORLIPS,0) > iCCI(NULL, NULL,45,PRICE_CLOSE,0))
{
SellOrder10();
}
}
void SellOrder10()
{
double SL = Bid + SellStoploss10*PipValue*Point;
if (SellStoploss10 == 0) SL = 0;
double TP = Bid - SellTakeprofit10*PipValue*Point;
if (SellTakeprofit10 == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_SELL, SellLots10, Bid, 4, 0, 0, "My Expert", 2, 0, Red);
else
ticket = OrderSend(Symbol(), OP_SELL, SellLots10, Bid, 4, SL, TP, "My Expert", 2, 0, Red);
if (ticket > -1)
{
if (true)
{
OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
CloseOrder12();
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void CloseOrder12()
{
int orderstotal = OrdersTotal();
int orders = 0;
int ordticket[30][2];
for (int i = 0; i < orderstotal; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 2)
{
continue;
}
ordticket[orders][0] = OrderOpenTime();
ordticket[orders][1] = OrderTicket();
orders++;
}
if (orders > 1)
{
ArrayResize(ordticket,orders);
ArraySort(ordticket);
}
for (i = 0; i < orders; i++)
{
if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
{
bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 2, Red);
if (ret == false)
Print("OrderClose() error - ", ErrorDescription(GetLastError()));
}
}
}
int deinit()
{
}
Plz, could somebody insert into this ea an option, the code for forcing a reverse trade ?
tnx
//--------------------------------------------------------
// Expert Advisor By Bodisatva
//--------------------------------------------------------
#property copyright "Copyright Bodisatva"
#property link "...."
#include <stdlib.mqh>
// exported variables
extern double BuyLots4 = 0.1;
extern int BuyStoploss4 = 20;
extern int BuyTakeprofit4 = 30;
extern double SellLots10 = 0.1;
extern int SellStoploss10 = 20;
extern int SellTakeprofit10 = 30;
// local variables
double PipValue=1; // this variable is here to support 5-digit brokers
bool Terminated = false;
int init()
{
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);
}
OnEveryTick1();
}
void OnEveryTick1()
{
if (true) PipValue = 10;
TechnicalAnalysis2();
TechnicalAnalysis8();
}
void TechnicalAnalysis2()
{
if (iAlligator(NULL, NULL,5,10,20,6,3,1,MODE_SMA,PRICE_CLOSE,MODE_GATORLIPS,0) < iCCI(NULL, NULL,20,PRICE_CLOSE,0))
{
BuyOrder4();
}
}
void BuyOrder4()
{
double SL = Ask - BuyStoploss4*PipValue*Point;
if (BuyStoploss4 == 0) SL = 0;
double TP = Ask + BuyTakeprofit4*PipValue*Point;
if (BuyTakeprofit4 == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_BUY, BuyLots4, Ask, 2, 0, 0, "My Expert", 1, 0, Blue);
else
ticket = OrderSend(Symbol(), OP_BUY, BuyLots4, Ask, 2, SL, TP, "My Expert", 1, 0, Blue);
if (ticket > -1)
{
if (true)
{
OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
CloseOrder6();
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void CloseOrder6()
{
int orderstotal = OrdersTotal();
int orders = 0;
int ordticket[30][2];
for (int i = 0; i < orderstotal; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() != OP_BUY || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
{
continue;
}
ordticket[orders][0] = OrderOpenTime();
ordticket[orders][1] = OrderTicket();
orders++;
}
if (orders > 1)
{
ArrayResize(ordticket,orders);
ArraySort(ordticket);
}
for (i = 0; i < orders; i++)
{
if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
{
bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 2, Red);
if (ret == false)
Print("OrderClose() error - ", ErrorDescription(GetLastError()));
}
}
}
void TechnicalAnalysis8()
{
if (iAlligator(NULL, NULL,5,10,20,6,3,1,MODE_SMA,PRICE_CLOSE,MODE_GATORLIPS,0) > iCCI(NULL, NULL,45,PRICE_CLOSE,0))
{
SellOrder10();
}
}
void SellOrder10()
{
double SL = Bid + SellStoploss10*PipValue*Point;
if (SellStoploss10 == 0) SL = 0;
double TP = Bid - SellTakeprofit10*PipValue*Point;
if (SellTakeprofit10 == 0) TP = 0;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_SELL, SellLots10, Bid, 4, 0, 0, "My Expert", 2, 0, Red);
else
ticket = OrderSend(Symbol(), OP_SELL, SellLots10, Bid, 4, SL, TP, "My Expert", 2, 0, Red);
if (ticket > -1)
{
if (true)
{
OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
CloseOrder12();
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void CloseOrder12()
{
int orderstotal = OrdersTotal();
int orders = 0;
int ordticket[30][2];
for (int i = 0; i < orderstotal; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 2)
{
continue;
}
ordticket[orders][0] = OrderOpenTime();
ordticket[orders][1] = OrderTicket();
orders++;
}
if (orders > 1)
{
ArrayResize(ordticket,orders);
ArraySort(ordticket);
}
for (i = 0; i < orders; i++)
{
if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
{
bool ret = OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 2, Red);
if (ret == false)
Print("OrderClose() error - ", ErrorDescription(GetLastError()));
}
}
}
int deinit()
{
}
- May Buddha bless you.