//-------------------------------------------------------------
// Etasoft Inc. Forex EA and Script Generator version 6.0 EA
//-------------------------------------------------------------
// Keywords: MT4, Forex EA builder, create EA, expert advisor developer
#property copyright "Copyright © 2014-2015, Etasoft Inc. Forex EA Generator v6.0"
#property link "http://www.forexgenerator.com/"
#include <stdlib.mqh>
#include <WinUser32.mqh>
// exported variables
extern string Symbol5 = "GBPUSD";
extern double MaxSpread9 = 20;
extern int TrailingStop33 = 20;
extern int TrailingGap33 = 20;
extern int Gap20 = -30;
extern double SellLots32 = 0.1;
extern int SellStoploss32 = 50;
extern int SellTakeprofit32 = 1000;
extern string SellExpertName32 = "Rara_Jelita";
extern double MaxSellLots32 = 10;
extern double LotsSellMpOnLoss32 = 2;
extern int Gap22 = -30;
extern double BuyLots25 = 0.1;
extern int BuyStoploss25 = 50;
extern int BuyTakeprofit25 = 1000;
extern string BuyExpertName25 = "Kelvina_Lintang";
extern double MaxBuyLots25 = 10;
extern double LotsBuyMpOnLoss25 = 2;
extern int TrailingStop34 = 20;
extern int TrailingGap34 = 20;
extern int TrailingStop37 = 10;
extern int TrailingGap37 = 10;
extern int TrailingStop36 = 10;
extern int TrailingGap36 = 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; // current bar index, used by Cross Up, Cross Down and many other blocks
int varylots[101]; // used by Buy Order Varying, Sell Order Varying and similar
double CurrentSellLots32 = 1;
bool FirstSellLotsMgm32 = true;
double CurrentBuyLots25 = 1;
bool FirstBuyLotsMgm25 = true;
int init()
{
NDigits = Digits;
if (false) ObjectsDeleteAll(); // clear the chart
CurrentSellLots32 = SellLots32;
CurrentBuyLots25 = BuyLots25;
Comment(""); // clear the chart
return (0);
}
// Expert start
int start()
{
if (Bars < 10)
{
Comment("Not enough bars");
return (0);
}
if (Terminated == true)
{
Comment("EA Terminated.");
return (0);
}
OnEveryTick6();
return (0);
}
void OnEveryTick6()
{
PipValue = 1;
if (NDigits == 3 || NDigits == 5) PipValue = 10;
ClearAllObjects4();
IfCurrencyPair5();
}
void ClearAllObjects4()
{
ObjectsDeleteAll();
}
void IfCurrencyPair5()
{
if (Symbol() == Symbol5)
{
SpreadFilter9();
CheckLastOrderResult38();
CheckLastOrderResult39();
}
}
void SpreadFilter9()
{
if ((Ask-Bid) / Point / PipValue < MaxSpread9)
{
TechnicalAnalysis10();
TechnicalAnalysis11();
}
}
void TechnicalAnalysis10()
{
if (iAlligator(NULL, NULL,30,8,8,5,5,3,MODE_SMMA,PRICE_CLOSE,MODE_GATORLIPS,current) < iAlligator(NULL, NULL,30,8,8,5,5,3,MODE_SMMA,PRICE_CLOSE,MODE_GATORJAW,current))
{
TrailingStop33();
IfGap20();
IfOrderDoesNotExist12();
}
}
void TrailingStop33()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 21)
{
double takeprofit = OrderTakeProfit();
if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TrailingStop33*PipValue*Point)
{
if (OrderStopLoss() < Ask-(TrailingStop33+TrailingGap33)*PipValue*Point)
{
if (0 != 0) takeprofit = Ask+(0 + TrailingStop33)*PipValue*Point;
bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), Ask-TrailingStop33*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret1 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > TrailingStop33*PipValue*Point)
{
if (OrderStopLoss() > Bid+(TrailingStop33+TrailingGap33)*PipValue*Point)
{
if (0 != 0) takeprofit = Bid-(0 + TrailingStop33)*PipValue*Point;
bool ret2 = OrderModify(OrderTicket(), OrderOpenPrice(), Bid+TrailingStop33*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret2 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
}
}
else
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
void IfGap20()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 21)
{
if ((Gap20 < 0 && ((OrderType() == OP_BUY && Ask - OrderOpenPrice() < Gap20*PipValue*Point) ||
(OrderType() == OP_SELL && OrderOpenPrice() - Bid < Gap20*PipValue*Point))) ||
((Gap20 > 0 && ((OrderType() == OP_BUY && Ask - OrderOpenPrice() > Gap20*PipValue*Point) ||
(OrderType() == OP_SELL && OrderOpenPrice() - Bid > Gap20*PipValue*Point)))))
{
IfOrderDoesNotExist16();
}
}
}
else
Print("OrderSelect() 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_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists == false)
{
SellOrderLotsMgm32();
}
}
void SellOrderLotsMgm32()
{
double profit = 0;
datetime lastCloseTime = 0;
int cnt = OrdersHistoryTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1 && lastCloseTime < OrderCloseTime())
{
lastCloseTime = OrderCloseTime();
profit = OrderProfit();
CurrentSellLots32 = OrderLots();
}
}
if (profit > 0) // had profit
{
CurrentSellLots32 = CurrentSellLots32 * 1 + 0;
if (true)
CurrentSellLots32 = SellLots32;
}
else if (profit < 0) // had loss
{
CurrentSellLots32 = CurrentSellLots32 * LotsSellMpOnLoss32 + 0;
if (false) CurrentSellLots32 = SellLots32;
}
if (CurrentSellLots32 > MaxSellLots32)
{
CurrentSellLots32 = MaxSellLots32;
}
double lotvalue = CurrentSellLots32;
if (lotvalue < MarketInfo(Symbol(), MODE_MINLOT)) // make sure lot is not smaller than allowed value
{
lotvalue = MarketInfo(Symbol(), MODE_MINLOT);
}
if (lotvalue > MarketInfo(Symbol(), MODE_MAXLOT)) // make sure lot is not greater than allowed value
{
lotvalue = MarketInfo(Symbol(), MODE_MAXLOT);
}
double SL = Bid + SellStoploss32*PipValue*Point;
if (SellStoploss32 == 0) SL = 0;
double TP = Bid - SellTakeprofit32*PipValue*Point;
if (SellTakeprofit32 == 0) TP = 0;
FirstSellLotsMgm32 = false;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_SELL, lotvalue, Bid, 4, 0, 0, SellExpertName32, 1, 0, Red);
else
ticket = OrderSend(Symbol(), OP_SELL, lotvalue, Bid, 4, SL, TP, SellExpertName32, 1, 0, Red);
if (ticket > -1)
{
if (true)
{
bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Red);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void IfOrderDoesNotExist12()
{
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() == 21)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists == false)
{
IfOrderDoesNotExist16();
}
}
void TechnicalAnalysis11()
{
if (iAlligator(NULL, NULL,30,8,8,5,5,3,MODE_SMMA,PRICE_CLOSE,MODE_GATORLIPS,current) > iAlligator(NULL, NULL,30,8,8,5,5,3,MODE_SMMA,PRICE_CLOSE,MODE_GATORJAW,current))
{
IfGap22();
IfOrderDoesNotExist15();
TrailingStop34();
}
}
void IfGap22()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
if ((Gap22 < 0 && ((OrderType() == OP_BUY && Ask - OrderOpenPrice() < Gap22*PipValue*Point) ||
(OrderType() == OP_SELL && OrderOpenPrice() - Bid < Gap22*PipValue*Point))) ||
((Gap22 > 0 && ((OrderType() == OP_BUY && Ask - OrderOpenPrice() > Gap22*PipValue*Point) ||
(OrderType() == OP_SELL && OrderOpenPrice() - Bid > Gap22*PipValue*Point)))))
{
IfOrderDoesNotExist13();
}
}
}
else
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
void IfOrderDoesNotExist13()
{
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() == 21)
{
exists = true;
}
}
else
{
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
if (exists == false)
{
BuyOrderLotsMgm25();
}
}
void BuyOrderLotsMgm25()
{
double profit = 0;
datetime lastCloseTime = 0;
int cnt = OrdersHistoryTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 21 && lastCloseTime < OrderCloseTime())
{
lastCloseTime = OrderCloseTime();
profit = OrderProfit();
CurrentBuyLots25 = OrderLots(); // take lots from the last order
}
}
if (profit > 0) // had profit
{
CurrentBuyLots25 = CurrentBuyLots25 * 1 + 0;
if (true)
CurrentBuyLots25 = BuyLots25;
}
else if (profit < 0) // had loss
{
CurrentBuyLots25 = CurrentBuyLots25 * LotsBuyMpOnLoss25 + 0;
if (false) CurrentBuyLots25 = BuyLots25;
}
if (CurrentBuyLots25 > MaxBuyLots25)
{
CurrentBuyLots25 = MaxBuyLots25;
}
double lotvalue = CurrentBuyLots25;
if (lotvalue < MarketInfo(Symbol(), MODE_MINLOT)) // make sure lot is not smaller than allowed value
{
lotvalue = MarketInfo(Symbol(), MODE_MINLOT);
}
if (lotvalue > MarketInfo(Symbol(), MODE_MAXLOT)) // make sure lot is not greater than allowed value
{
lotvalue = MarketInfo(Symbol(), MODE_MAXLOT);
}
double SL = Ask - BuyStoploss25*PipValue*Point;
if (BuyStoploss25 == 0) SL = 0;
double TP = Ask + BuyTakeprofit25*PipValue*Point;
if (BuyTakeprofit25 == 0) TP = 0;
FirstBuyLotsMgm25 = false;
int ticket = -1;
if (true)
ticket = OrderSend(Symbol(), OP_BUY, lotvalue, Ask, 4, 0, 0, BuyExpertName25, 21, 0, Blue);
else
ticket = OrderSend(Symbol(), OP_BUY, lotvalue, Ask, 4, SL, TP, BuyExpertName25, 21, 0, Blue);
if (ticket > -1)
{
if (true)
{
bool sel = OrderSelect(ticket, SELECT_BY_TICKET);
bool ret = OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0, Blue);
if (ret == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
else
{
Print("OrderSend() error - ", ErrorDescription(GetLastError()));
}
}
void IfOrderDoesNotExist15()
{
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 == false)
{
IfOrderDoesNotExist13();
}
}
void TrailingStop34()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
double takeprofit = OrderTakeProfit();
if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TrailingStop34*PipValue*Point)
{
if (OrderStopLoss() < Ask-(TrailingStop34+TrailingGap34)*PipValue*Point)
{
if (0 != 0) takeprofit = Ask+(0 + TrailingStop34)*PipValue*Point;
bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), Ask-TrailingStop34*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret1 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > TrailingStop34*PipValue*Point)
{
if (OrderStopLoss() > Bid+(TrailingStop34+TrailingGap34)*PipValue*Point)
{
if (0 != 0) takeprofit = Bid-(0 + TrailingStop34)*PipValue*Point;
bool ret2 = OrderModify(OrderTicket(), OrderOpenPrice(), Bid+TrailingStop34*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret2 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
}
}
else
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
void CheckLastOrderResult38()
{
double profit = 0;
int orderId = -1;
datetime lastCloseTime = 0;
int cnt = OrdersHistoryTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
orderId = OrderMagicNumber();
if (OrderSymbol() == Symbol() && lastCloseTime < OrderCloseTime() && orderId == 21)
{
lastCloseTime = OrderCloseTime();
profit = OrderProfit();
}
}
if (profit < 0)
{
TrailingStop37();
}
}
void TrailingStop37()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 21)
{
double takeprofit = OrderTakeProfit();
if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TrailingStop37*PipValue*Point)
{
if (OrderStopLoss() < Ask-(TrailingStop37+TrailingGap37)*PipValue*Point)
{
if (0 != 0) takeprofit = Ask+(0 + TrailingStop37)*PipValue*Point;
bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), Ask-TrailingStop37*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret1 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > TrailingStop37*PipValue*Point)
{
if (OrderStopLoss() > Bid+(TrailingStop37+TrailingGap37)*PipValue*Point)
{
if (0 != 0) takeprofit = Bid-(0 + TrailingStop37)*PipValue*Point;
bool ret2 = OrderModify(OrderTicket(), OrderOpenPrice(), Bid+TrailingStop37*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret2 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
}
}
else
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
void CheckLastOrderResult39()
{
double profit = 0;
int orderId = -1;
datetime lastCloseTime = 0;
int cnt = OrdersHistoryTotal();
for (int i=0; i < cnt; i++)
{
if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
orderId = OrderMagicNumber();
if (OrderSymbol() == Symbol() && lastCloseTime < OrderCloseTime() && orderId == 1)
{
lastCloseTime = OrderCloseTime();
profit = OrderProfit();
}
}
if (profit < 0)
{
TrailingStop36();
}
}
void TrailingStop36()
{
for (int i=OrdersTotal()-1; i >= 0; i--)
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() == Symbol() && OrderMagicNumber() == 1)
{
double takeprofit = OrderTakeProfit();
if (OrderType() == OP_BUY && Ask - OrderOpenPrice() > TrailingStop36*PipValue*Point)
{
if (OrderStopLoss() < Ask-(TrailingStop36+TrailingGap36)*PipValue*Point)
{
if (0 != 0) takeprofit = Ask+(0 + TrailingStop36)*PipValue*Point;
bool ret1 = OrderModify(OrderTicket(), OrderOpenPrice(), Ask-TrailingStop36*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret1 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
if (OrderType() == OP_SELL && OrderOpenPrice() - Bid > TrailingStop36*PipValue*Point)
{
if (OrderStopLoss() > Bid+(TrailingStop36+TrailingGap36)*PipValue*Point)
{
if (0 != 0) takeprofit = Bid-(0 + TrailingStop36)*PipValue*Point;
bool ret2 = OrderModify(OrderTicket(), OrderOpenPrice(), Bid+TrailingStop36*PipValue*Point, takeprofit, OrderExpiration(), White);
if (ret2 == false)
Print("OrderModify() error - ", ErrorDescription(GetLastError()));
}
}
}
}
else
Print("OrderSelect() error - ", ErrorDescription(GetLastError()));
}
int deinit()
{
if (false) ObjectsDeleteAll();
return (0);
}
Tidak ada komentar:
Posting Komentar