#include <WinUser32.mqh>
#property show_inputs
extern int stoploss = 0,
takeprofit = 0,
Magic = 123456;
bool SELL = false,
BUY = false;
extern double Lot = 0.01;
extern int slippage = 3;
double SL,TP;
double uni_cross_up;
double uni_cross_down;
double flat_up;
double flat_down;
double flat_flat;
void OPENORDER(string ord)
{
int k=OrdersTotal();
//k-количество открытых ордеров, ставим 10 - откроет 10 одинаковых сделок
if (k<4)
{
//getLots() - включаем мартин для лота
if (ord=="Buy" ) OrderSend(Symbol(),OP_BUY, /*Lot*/ getLots(),NormalizeDouble(Ask,Digits),slippage,SL,TP,"BUY",Magic,0,Blue);
if (ord=="Sell") OrderSend(Symbol(),OP_SELL,/*Lot*/ getLots(),NormalizeDouble(Bid,Digits),slippage,SL,TP,"SELL",Magic,0,Red);
}
return(0);
}
int init()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double arrow_up_blue1 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,0,0);
double arrow_up_blue2 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,0,1);
double arrow_up_blue3 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,0,2);
double arrow_up_blue4 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,0,3);
double arrow_up_blue5 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,0,4);
double arrow_down_red1 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,1,0);
double arrow_down_red2 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,1,1);
double arrow_down_red3 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,1,2);
double arrow_down_red4 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,1,3);
double arrow_down_red5 =iCustom(Symbol(),0,"Buy-Sell_Alerts",5,240,false,false,1,4);
uni_cross_up =iCustom(Symbol(),0, "uni_cross",0,7);
uni_cross_down=iCustom(Symbol(),0, "uni_cross",1,7);
flat_up=iCustom(Symbol(),0,"Pulse Flat",20,2.0,20,1.5,12,3,1);
flat_down=iCustom(Symbol(),0,"Pulse Flat",20,2.0,20,1.5,12,2,1);
flat_flat=iCustom(Symbol(),0,"Pulse Flat",20,2.0,20,1.5,12,4,1);
Comment("flat_up=",flat_up," flat_down=",flat_down," flat=",flat_flat);
if ((arrow_up_blue1>0)&&
(arrow_up_blue2>0) &&
(arrow_up_blue3>0) &&
(arrow_up_blue4>0) &&
(arrow_up_blue5>0) &&
(arrow_down_red1==0) &&
(arrow_down_red2==0) &&
(arrow_down_red3==0) &&
(uni_cross_up<10000000) &&
(flat_up<0) &&
(arrow_down_red5==0))
{
SELL=false;
BUY=true;
}
if ((arrow_down_red1>0) &&
(arrow_down_red2>0) &&
(arrow_down_red3>0) &&
(arrow_down_red4>0) &&
(arrow_down_red5>0) &&
(arrow_up_blue1==0) &&
(arrow_up_blue2==0) &&
(arrow_up_blue3==0) &&
(arrow_up_blue4==0) &&
(uni_cross_down<1000000) &&
(flat_down>0) &&
(arrow_up_blue5==0))
{
BUY=false;
SELL=true;
}
//============Функции для открытия ордеров
if (BUY)
{
//=======Закрываем ордера на продажу перед открытием на покупку=============
for (int i=OrdersTotal()-1; i>=0; i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderType()==OP_SELL) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),slippage);
}
//============================================================================
//if (takeprofit!=0) TP = NormalizeDouble(Ask + takeprofit*Point,Digits); else TP=0;
//if (stoploss!=0) SL = NormalizeDouble(Ask - stoploss*Point,Digits); else SL=0;
if (takeprofit!=0) TP=Ask+takeprofit*Point;
if (stoploss!=0) SL=Ask-stoploss*Point;
OPENORDER ("Buy");
}
if (SELL)
{
//=====Закрываем ордера на покупку перед открытием на продажу=====================================================
for ( i=OrdersTotal()-1; i>=0; i--)
{
if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) break;
if (OrderType()==OP_BUY ) OrderClose (OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),slippage);
}
//=====================================================================================
//if (takeprofit!=0) TP = NormalizeDouble(Bid - takeprofit*Point,Digits); else TP=0;
//if (stoploss!=0) SL = NormalizeDouble(Bid + stoploss*Point,Digits); else SL=0;
if (takeprofit!=0) TP=Bid-takeprofit*Point;
if (stoploss!=0) SL=Bid+stoploss*Point;
OPENORDER ("Sell");
}
//----
return(0);
}
//Мартингейл
//+--------------------------- getLots ----------------------------------+
double getLots()
{
double minlot = MarketInfo(Symbol(), MODE_MINLOT);
int round = MathAbs(MathLog(minlot) / MathLog(10.0)) + 0.5;
double result = Lot;
int total = OrdersHistoryTotal();
double spread = MarketInfo(Symbol(), MODE_SPREAD);
// double k = (tp + sl) / (tp - spread);
for (int i = 0; i < total; i++)
{
OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if (OrderProfit() > 0)
{
result = Lot;
}
else
{
result = result * 2;
}
}
result = NormalizeDouble(result, round);
double maxlot = MarketInfo(Symbol(), MODE_MAXLOT);
if (result > maxlot)
{
result = maxlot;
}
RefreshRates();
return(result);
}