#include <stdlib.mqh>
extern string ExpertName = "NewsTrader_v5";
extern int Magic = 55555;
extern int Slippage = 6;
extern string Main_Parameters = " Trade Volume & Trade Method";
extern string CalendarName = "Calendar0207.txt";
extern double Lots = 0.1; // Lot size
extern int TimeZone = 0; // Difference between server time and local time
extern int TimeGap = 5; // Time Gap between News Time and Order Open Time in min
extern int OrderDuration = 15; // Order Duratiton Time in min
extern int ProcessTime = 2; // Order processing Time in min
extern int SessionEnd = 24; // Session End Time
extern int FridayEnd = 23; // Session End Time in Friday
extern int OrdersNum = 1; // Number of pending orders from one side
extern double PendOrdGap = 20; // Gap for Pending Orders from current price in pips
extern double OrdersStep = 10; // Step between orders in pips
extern int DelOpposite = 0; // Switch of orders deleting: 0-off,1-on
extern int TrailOpposite = 0; // Trailing of Opposite Orders: 0-off,1-on
extern double TakeProfit = 100; // Take Profit in pips
extern double TrailingStop = 0; // Trailing Stop in pips
extern double InitialStop = 50; // Initial Stop in pips
extern double BreakEven = 0; // Breakeven in pips
extern bool DisplayLine = false; // Display Line Option (Visualization mode)
extern bool DisplayText = false; // Display Text Option (Visualization mode)
extern string cFilter = " Currency Filter ";
extern bool USD = true;
extern bool EUR = true;
extern bool GBP = true;
extern bool JPY = true;
extern bool AUD = true;
extern bool CAD = true;
extern bool CHF = true;
extern bool NZD = true;
extern string rFilter = " Rating Filter ";
extern int MaxRating = 3;
extern int MinRating = 1;
extern string MM_Parameters = " MoneyManagement by L.Williams ";
extern bool MM = false; // ?? Switch
extern double MaxRisk = 0.05; // Risk Factor
extern double LossMax = 0; // Maximum Loss by 1 Lot
datetime FinTime=0;
string sDate[1000]; // Date
string sTime[1000]; // Time
string sCurrency[1000]; // Currency
string sDescription[1000]; // Description
string sRating[1000]; // Rating
datetime dt[1000];
int BEvent=0, NewsNum, TriesNum=5;
int init()
{
// код доступен только после оплаты
}
double MoneyManagement()
{
double lot_min =MarketInfo(Symbol(),MODE_MINLOT);
double lot_max =MarketInfo(Symbol(),MODE_MAXLOT);
double lot_step=MarketInfo(Symbol(),MODE_LOTSTEP);
double contract=MarketInfo(Symbol(),MODE_LOTSIZE);
double vol;
if(lot_min<0 || lot_max<=0.0 || lot_step<=0.0)
{
Print("CalculateVolume: invalid MarketInfo() results [",lot_min,",",lot_max,",",lot_step,"]");
return(0);
}
if(AccountLeverage()<=0)
{
Print("CalculateVolume: invalid AccountLeverage() [",AccountLeverage(),"]");
return(0);
}
if ( MM )
vol=NormalizeDouble(AccountFreeMargin()*MaxRisk*AccountLeverage()/contract,2);
else
vol=Lots;
vol=NormalizeDouble(vol/lot_step,0)*lot_step;
if(vol<lot_min) vol=lot_min;
if(vol>lot_max) vol=lot_max;
return(vol);
}
void TrailStop()
{
int error;
bool result=false;
double Gain = 0;
for (int cnt=0;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if (mode==OP_BUY)
{
if ( BreakEven > TrailingStop && BEvent==0 )
{
Gain = (MarketInfo(Symbol(),MODE_BID) - OrderOpenPrice())/Point;
if( Gain >= BreakEven && OrderStopLoss()<=OrderOpenPrice()+1*Point)
{
double BuyStop = NormalizeDouble(OrderOpenPrice()+1*Point,Digits);
BEvent=1;
}
}
else
if( TrailingStop > 0) BuyStop = NormalizeDouble(Bid - TrailingStop*Point,Digits);
if( NormalizeDouble(OrderOpenPrice(),Digits)<= BuyStop || OrderStopLoss() == 0)
{
if ( BuyStop > NormalizeDouble(OrderStopLoss(),Digits))
{
for(int k = 0 ; k < TriesNum; k++)
{
result = OrderModify(OrderTicket(),OrderOpenPrice(),
BuyStop,
OrderTakeProfit(),0,Lime);
error=GetLastError();
if(error==0) break;
else {Sleep(5000); RefreshRates(); continue;}
}
}
}
}
if (mode==OP_SELL)
{
if ( BreakEven > TrailingStop && BEvent==0)
{
Gain = (OrderOpenPrice()-MarketInfo(Symbol(),MODE_ASK))/Point;
if( Gain >= BreakEven && OrderStopLoss()>=OrderOpenPrice()-1*Point)
{
double SellStop = NormalizeDouble(OrderOpenPrice()-1*Point,Digits);
BEvent=-1;
}
}
else
if( TrailingStop > 0) SellStop = NormalizeDouble(MarketInfo(Symbol(),MODE_ASK) + TrailingStop*Point,Digits);
if((NormalizeDouble(OrderOpenPrice(),Digits) >= SellStop && SellStop>0) || OrderStopLoss() == 0)
{
if( SellStop < NormalizeDouble(OrderStopLoss(),Digits))
{
for( k = 0 ; k < TriesNum; k++)
{
result = OrderModify(OrderTicket(),OrderOpenPrice(),
SellStop,
OrderTakeProfit(),0,Orange);
error=GetLastError();
if(error==0) break;
else {Sleep(5000); RefreshRates(); continue;}
}
}
}
}
}
}
}
int SellOrdOpen(double price,double sl,double tp,int num)
{
int ticket = 0;
int tr = 1;
while ( ticket <= 0 && tr <= TriesNum)
{
ticket = OrderSend( Symbol(),OP_SELLSTOP,MoneyManagement(),
NormalizeDouble(price , Digits),
Slippage,
NormalizeDouble(sl, Digits),
NormalizeDouble(tp, Digits),
ExpertName+" SELL:"+num,Magic,0,Red);
if(ticket > 0)
{
BEvent=0;
if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("SELLSTOP order opened : ", OrderOpenPrice());
}
else
if(ticket < 0)
{
Sleep(5000);
RefreshRates();
tr += 1;
if(GetLastError()>0)
Print("SELLSTOP: OrderSend failed with error #",ErrorDescription(GetLastError()));
}
}
return(ticket);
}
int BuyOrdOpen(double price,double sl,double tp,int num)
{
int ticket = 0;
int tr = 1;
while ( ticket <= 0 && tr <= TriesNum)
{
ticket = OrderSend(Symbol(),OP_BUYSTOP,MoneyManagement(),
NormalizeDouble(price , Digits),
Slippage,
NormalizeDouble(sl, Digits),
NormalizeDouble(tp, Digits),
ExpertName+" BUY:"+num,Magic,0,Blue);
if(ticket > 0)
{
BEvent=0;
if (OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
Print("BUYSTOP order opened : ", OrderOpenPrice());
}
else
if(ticket < 0)
{
Sleep(5000);
RefreshRates();
tr += 1;
if(GetLastError()>0)
Print("BUYSTOP : OrderSend failed with error #",ErrorDescription(GetLastError()));
}
}
return(ticket);
}
int ScanTrades(int ord,int mode)
{
int total = OrdersTotal();
int numords = 0;
bool type = false;
int trd = 0;
for(int cnt=0; cnt<total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
if ( ord != 0 )
{
if ( OrderType()==0 || OrderType()==2 || OrderType()==4 ) trd = 1;
if ( OrderType()==1 || OrderType()==3 || OrderType()==5 ) trd = 2;
} else trd=0;
if (mode == 0) type = OrderType()<=OP_SELLSTOP;
if (mode == 1) type = OrderType()<=OP_SELL;
if (mode == 2) type = OrderType()>OP_SELL && OrderType()<=OP_SELLSTOP;
if(OrderSymbol() == Symbol() && type && trd==ord && OrderMagicNumber() == Magic)
numords++;
}
return(numords);
}
datetime FinishTime(int Duration)
{
int total = OrdersTotal();
datetime ftime=0;
for(int i=0; i<total; i++)
{
OrderSelect(i, SELECT_BY_POS);
if(OrderSymbol() == Symbol() && OrderType()<=OP_SELLSTOP && OrderMagicNumber() == Magic)
ftime=OrderOpenTime()+ Duration*60;
}
return(ftime);
}
void PendOrdDel(int mode)
{
bool result = false;
for (int i=0; i<OrdersTotal(); i++)
{
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if ( Symbol()==OrderSymbol() && OrderMagicNumber()==Magic)
{
if((mode==0 || mode==1) && OrderType()==OP_BUYSTOP)
{
result = OrderDelete(OrderTicket());
if(!result) Print("BUYSTOP: OrderDelete failed with error #",GetLastError());
}
else
if((mode==0 || mode==2) && OrderType()==OP_SELLSTOP)
{
result = OrderDelete( OrderTicket() );
if(!result) Print("SELПоказано первые 50% кода (символов: 13104)
Введите ваш email и нажмите кнопку, чтобы перейти к оплате.