//+------------------------------------------------------------------+ //| Adam_1.0.mq5 | //| Magistr Sanich | //| | //+------------------------------------------------------------------+ #property copyright "Magistr Sanich" #property link "" #property version "1.00" #define BUY "Buy" #define SELL "Sell" #define PLAY "Play" #define STOP "Stop" #include #include #include #include #include #include #include #include #include #include #include #include #include #include //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ input int set_imp=80;//Импульс [Pips] input int set_count_bar_imp=1;//Количество баров в импульсе input ENUM_TIMEFRAMES period=PERIOD_M5;//Таймфрейм input bool set_un_damage=true;//Общий безубыток [вкл/выкл] input int set_dist_price=30;// Расстояние 1-го ордера от ТЦ [Pips] input int set_step=50;//Шаг ордеров [Pips] input int set_add_undamage=3;//+[pips] к безуюытку input double coofLot=1;//Коэффициент лота input int spred=15; // Спред [Pips] input int slip=15;//Проскальзывание [Pips] input long Magic=1;//Магик input bool alert=true;//Алерт [вкл/выкл] input bool alert_sound=false;//Звук алерта [вкл/выкл] input int wt_begin_hh=8;//Начало [hours] input int wt_begin_mm=0;//Начало [min] input int wt_end_hh=20;//Конец [hours] input int wt_end_mm=0;//Конец [min] input string s1="ПАРАМЕТРЫ ОРДЕРОВ";//ОРДЕР 1 input double or1_risk=2;//Риск [%] input int or1_take_pr=80;//Тейк [Pips] input int or1_stop=30;//Стоп лосс [Pips] input string s3="-----------------------";//ОРДЕР 2 input double or2_risk=40;//Доля от 1 ордера [%] input int or2_take_pr=80;//Тейк [Pips] input string s4="-----------------------";//ОРДЕР 3 input double or3_risk=20;//Доля от 1 ордера [%] input int or3_take_pr=80;//Тейк [Pips] input string s5="-----------------------";//ОРДЕР 4 input double or4_risk=0;//Доля от 1 ордера [%] input int or4_take_pr=0;//Тейк [Pips] input string s6="-----------------------";// ОРДЕР 5 input double or5_risk=0;//Доля от 1 ордера [%] input int or5_take_pr=0;//Тейк [Pips] input double min_lot=0.1;//Минимальный объем лота input string com343="НАСТРОЙКИ УРОВНЯ БЕЗУБЫТКА";//----------------------- input bool lev_use=true;//Использовать линию [вкл/выкл] input int lev_size=1;//Толщина уровня input color lev_color=clrLightGray;//Цвет уровня input ENUM_LINE_STYLE lev_style=STYLE_SOLID;//Тип уровня input string com1="НАСТРОЙКИ КНОПОК";//----------------------- input bool But_use=true;//Отображать кнопки [вкл/выкл] input int But_x=60;//Смещение по Х input int But_y=185;//Смещение по У input int But_dist=15;//Расстояние между кнопками input int But_width=160;// Ширина input int But_height=25;// Высота input int But_font_size=10; // Рразмер шрифта input color But_clr=clrDarkGray; //Цвеет текста input color But_back_clr=clrBlack; // Цвет фона input color But_border_clr=clrDarkGray; // цвет границы input string com666="НАСТРОЙКИ ИНФ. ПАНЕЛИ";//------------------------------- input bool Lab_use=true;//Отображать текст [вкл/выкл] input color Lab_colorText=clrDarkGray; // Цвет текста input int Lab_size=8; // Размер шрифта input int Lab_offset_x=15; // Смещение по Х input int Lab_offset_y=20; // Смещение по Y input int Lab_distText=15; // Расстояние между строками //---Global Var---- CArrayObj *netOrders; CArrayDouble *riskOrders; CArrayInt *takeOrders; MqlTick last_tick; CSymbolInfo *symbol_info; ulong netTickets[5]; CButton *btnWork; CChartObjectHLine *lineZero; CChartObjectLabel *labStopLevel; CChartObjectLabel *labBalance; CChartObjectLabel *labGain; CChartObjectLabel *labDrowdown; CChartObjectLabel *labAllProfit; CChartObjectLabel *labAllLost; CChartObjectLabel *labNett; CChartObjectLabel *labTotalVolume; CChartObjectLabel *labTimeWork; int netSize; int index_last; int count_orders; int count_positions; string netType; double valueFirstOrder; double undamage_price; datetime last_checking; datetime last_open; bool workingNet; double textLoss; double textProfit; double textBalance; double textGain; double textDrowdown; double textNett; double textVolume; double textTimeWorl; double maxBalance; double startBalance; bool notFirst; long workTime; long lastTime; ulong lastTick; int max_spread; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void SetParams() { riskOrders.Clear(); riskOrders.Add(or1_risk); riskOrders.Add(or2_risk); riskOrders.Add(or3_risk); riskOrders.Add(or4_risk); riskOrders.Add(or5_risk); takeOrders.Clear(); takeOrders.Add(or1_take_pr); takeOrders.Add(or2_take_pr); takeOrders.Add(or3_take_pr); takeOrders.Add(or4_take_pr); takeOrders.Add(or5_take_pr); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void reculcOrders() { int count=0; index_last=0; for(int i=0;i=0;i--) { if(netTickets[i]!=0) { index_last=i+1; break; } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ double culcLot(int numb) { if(numb==0) { CAccountInfo account_info=new CAccountInfo(); symbol_info.Refresh(); valueFirstOrder=(riskOrders.At(0)/100*account_info.Balance())/(or1_stop+symbol_info.Spread())*coofLot; if(valueFirstOrdersymbol_info.LotsMax()) valueFirstOrder=symbol_info.LotsMax(); return valueFirstOrder; } else { symbol_info.Refresh(); double l_lot=valueFirstOrder*riskOrders.At(numb)/100; if(l_lotsymbol_info.LotsMax()) l_lot=symbol_info.LotsMax(); return l_lot; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void closeAll() { CPositionInfo pos_inf=new CPositionInfo(); COrderInfo ord_inf=new COrderInfo(); CTrade my_trade=new CMyTrade(); for(int i=0;iset_dist_price) { double price=last_tick.ask+set_dist_price*_Point; double sl=price-or1_stop*_Point; double tp=price+or1_take_pr*_Point; CMyTrade my_trade=new CMyTrade(); my_trade.Modify(netTickets[0],price,sl,tp); } } else if(netType==SELL) { int dist=(int)((last_tick.bid-ord_inf.PriceOpen())/_Point); if(dist>set_dist_price) { double price=last_tick.bid-set_dist_price*_Point; double sl=price+or1_stop*_Point; double tp=price-or1_take_pr*_Point; CMyTrade my_trade=new CMyTrade(); my_trade.Modify(netTickets[0],price,sl,tp); } } } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void doUndamage() { CPositionInfo pos_inf=new CPositionInfo(); pos_inf.Select(_Symbol); if(index_last<=2 || pos_inf.Ticket()<=0) return; CTrade my_trade=new CTrade(); COrderInfo ord_inf=new COrderInfo(); for(int i=netSize-1;i>=0;i--) { if(!PositionSelectByTicket(netTickets[i])) continue; double cur_sl=PositionGetDouble(POSITION_SL); double cur_tp=PositionGetDouble(POSITION_TP); if(Equal(cur_sl,0)==0 && Equal(cur_tp,0)==0) continue; ctrLine(); if(Equal(cur_sl,undamage_price)==0 || undamage_price==0) return; //Print("Pos Tick: ",netTickets[i]," PosStop: ",cur_sl,"; PosTake: ",cur_tp); SymbolInfoTick(_Symbol,last_tick); if((netType==BUY && undamage_price>=last_tick.bid) || (netType==SELL && undamage_price<=last_tick.ask)) { closeAll(); return; } //Print(Traders()); bool suc=my_trade.PositionModify(netTickets[i],undamage_price,PositionGetDouble(POSITION_TP)); if(!suc) Print("UndamageModify Error! #",my_trade.ResultRetcode()," ask: ",last_tick.ask," bid:",last_tick.bid); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void ctrLine() { if(index_last<=2) { lineZero.Delete(); return; } CPositionInfo pos_inf = new CPositionInfo(); CSymbolInfo sym_inf = new CSymbolInfo(); CDealInfo deal_inf= new CDealInfo(); symbol_info.Name(_Symbol); SymbolInfoTick(_Symbol,last_tick); if(pos_inf.Ticket()<=0) return; double AllProfit=0; double volumeLots=0; for(int i=0;i=netSize || index_last<1) return; if(ord_inf.Select(netTickets[index_last-1])) return; CPositionInfo pos_inf=new CPositionInfo(); pos_inf.Select(_Symbol); SymbolInfoTick(_Symbol,last_tick); if(netType==BUY) { CMyTrade ord= netOrders.At(index_last); double price=last_tick.ask+_Point*set_step; double l_lot=culcLot(index_last); string comment=IntegerToString(index_last); int sl=(int)MathAbs((pos_inf.StopLoss()-last_tick.ask)/_Point); netTickets[index_last]=ord.buyStop(price,l_lot,sl,or1_take_pr,Magic,slip,comment); index_last++; } else if(netType==SELL) { CMyTrade ord=netOrders.At(index_last); double price=last_tick.bid-_Point*set_step; double l_lot=culcLot(index_last); string comment=IntegerToString(index_last); int sl=(int)MathAbs((pos_inf.StopLoss()-last_tick.bid)/_Point); netTickets[index_last]=ord.sellStop(price,l_lot,sl,or1_take_pr,Magic,slip,comment); index_last++; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void culcParam() { CDealInfo deal_inf=new CDealInfo(); if(!HistorySelect(last_checking,TimeCurrent())) return; int his_tot=HistoryDealsTotal(); for(int i=0;i0) textProfit+=pr; else textLoss+=pr; textVolume+=deal_inf.Volume(); } for(int i=0;i=sec_beg && sec_nowmax_spread) max_spread=si.Spread();*/ if(index_last==0) { //culcParam(); } if(!CheckTimeWork()) { if(btnWork.IsEnabled()) { workingNet=false; btnWork.Text(PLAY); btnWork.Disable(); } } else { if(!btnWork.IsEnabled()) { workingNet=true; btnWork.Text(STOP); workTime=0; btnWork.Enable(); } } if(workingNet) { if(lastTime!=TimeCurrent()) { workTime+=TimeCurrent()-lastTime; lastTime=TimeCurrent(); } if(index_last==0) { symbol_info.Refresh(); if(symbol_info.Spread()maxBalance) maxBalance=acc_inf.Balance(); else { double dd=(maxBalance-acc_inf.Balance()+textBalance)/maxBalance*100; if(dd>textDrowdown) textDrowdown=dd; } textNett=textProfit+textLoss; labAllLost.SetString(OBJPROP_TEXT,"All loss: "+DoubleToString(textLoss,2)); labAllProfit.SetString(OBJPROP_TEXT,"All Profit: "+DoubleToString(textProfit,2)); labBalance.SetString(OBJPROP_TEXT,"Balance: "+DoubleToString(textBalance,2)); labDrowdown.SetString(OBJPROP_TEXT,"Drowdown: "+DoubleToString(textDrowdown,2)); labGain.SetString(OBJPROP_TEXT,"Gain: "+DoubleToString((acc_inf.Balance()-startBalance)/startBalance*100,2)); labNett.SetString(OBJPROP_TEXT,"Nett: "+DoubleToString(textNett,2)); labTimeWork.SetString(OBJPROP_TEXT,"Working hours: "+DoubleToString(workTime/60/60,0)+":"+DoubleToString(workTime/60%60,0)+" [hh:mm]"); labTotalVolume.SetString(OBJPROP_TEXT,"Total volume: "+DoubleToString(textVolume,2)); } } //+------------------------------------------------------------------+ void OnTrade() { CPositionInfo pos_inf=new CPositionInfo(); COrderInfo ord_inf=new COrderInfo(); CHistoryOrderInfo his_inf=new CHistoryOrderInfo(); CDealInfo deal_inf=new CDealInfo(); if(!HistorySelect(last_checking,TimeCurrent())) return; pos_inf.Select(_Symbol); if(pos_inf.Ticket()<=0) // Удаление одиноких ордеров { for(int i=1;i