EA-Setka-2/Libs/CtrlPanel/CtrlPanelExt.mqh
super.admin a4b861dd93 convert
2025-05-30 14:50:44 +02:00

392 lines
32 KiB
MQL5

//+------------------------------------------------------------------+
//| CtrlPanelIlnurLight.mqh |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#ifndef CTRL_PANEL_ILNUR_LIGHT_MQH
#define CTRL_PANEL_ILNUR_LIGHT_MQH
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class CCtrlPanelExt: public CCtrlPanelComment
{
public:
CCtrlPanelExt() {};
CCtrlPanelExt(const string param);
~CCtrlPanelExt() {};
virtual void CreatePanelItems();
virtual void OnTickCalculateEvent();
protected:
short _count_item;
short _row_sell_lvlvol;
short _row_buy_lvlvol;
short _row_sell_lentp;
short _row_buy_lentp;
short _row_sell_pandl;
short _row_buy_pandl;
short _row_sell_dist_tp;
short _row_buy_dist_tp;
short _row_block;
double _sell_profit;
double _buy_profit;
protected:
string ConcatLegLengthVolume(int lvl, int lvl_max, int len, int len_max, double vol,double vol_max);
string ConcatLegVol(int lvl, int lvl_max, double vol,double vol_max);
string ConcatLenTP(double len, double len_max, double tp_last);
string ConcatPANDL(double pandl,double profit);
string ConcatBlockedByTimer(timer_t* vol_timer, timer_t* spread_timer);
string ConcatTPDistance(double distance, double len);
string ConcatNextDistance(double distance, double distance_last);
string ConcatStopout(double stopout);
bool CalcGridParam(logic_handler* hdl, int lvl, double& len, double& vol, double& profit, double& dist_tp);
bool CalcTickParam(logic_handler* hdl, int lvl, double& pandl, double& dist_tp, double& len, double& dist_stop);
};
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
CCtrlPanelExt::CCtrlPanelExt(const string param):CCtrlPanelComment(param)
{
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string CCtrlPanelExt::ConcatLegVol(int lvl, int lvl_max, double vol,double vol_max)
{
return "Lvl:"+IntegerToString(lvl)+"/"+IntegerToString(lvl_max)+" "+ "Vol:"+DoubleToString(vol,2)+"/"+DoubleToString(vol_max,2);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string CCtrlPanelExt::ConcatLenTP(double len, double len_max, double tp_last)
{
return "Len:"+DoubleToString(len,0) +"/"+ DoubleToString(len_max,0)+" "+ "TP:"+DoubleToString(tp_last,0)+"("+DoubleToString(((len==0)?0:(tp_last/len*100)),2)+"%)";
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string CCtrlPanelExt::ConcatPANDL(double pandl,double profit)
{
return "P&L:"+DoubleToString(pandl,2) +"("+ DoubleToString(((kernel_account::balance()==0)?0: pandl/kernel_account::balance()*100),2)+"%)"
+"/"+DoubleToString(profit,2) +"("+ DoubleToString(((kernel_account::balance()==0)?0: profit/kernel_account::balance()*100),2)+"%)";
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string CCtrlPanelExt::ConcatTPDistance(double distance, double len)
{
return "Cur Len:"+ DoubleToString(len,0) + " Dist TP:"+DoubleToString(distance,0) +"("+ DoubleToString(((len==0)?0:distance/len*100),2)+"%)";
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string CCtrlPanelExt::ConcatBlockedByTimer(timer_t* vol_timer, timer_t* spread_timer)
{
if(!GC_CHECK_PTR(vol_timer) && !GC_CHECK_PTR(spread_timer))
{
return "";
}
string name="";
datetime dt=layer::time_current();
str_builder s;
s.append("Blocked by ");
if(GC_CHECK_PTR(vol_timer) && vol_timer.ent_time()>dt)
{
name= "volatility filter";
dt=vol_timer.ent_time();
}
if(GC_CHECK_PTR(spread_timer) && spread_timer.ent_time()>dt)
{
name= "spread filter";
dt=spread_timer.ent_time();
}
if(StringLen(name)==0)
return "";
s.append(name);
s.append(" until ");
s.append(ttos(dt));
return s.to_str();
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string CCtrlPanelExt::ConcatNextDistance(double distance, double distance_last)
{
return CTRL_PANEL_CAPTION_GRID_PARAM_NEXT_DISTANCE+":"+DoubleToString(distance,0)+"/"+DoubleToString(distance_last,0)+"("+ DoubleToString(((distance_last==0)?0:(1-distance/distance_last)*100),2)+"%)";
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
string CCtrlPanelExt::ConcatStopout(double stopout)
{
return CTRL_PANEL_CAPTION_GRID_PARAM_STOPOUT_DISTANCE+":"+DoubleToString(stopout,0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CCtrlPanelExt::CreatePanelItems()
{
string str;
_count_item=1;
_panel.SetText(0,GenerateHeader(), _color_caption);
// Информация о сете
str=PrepStr(set_name,"; ")+PrepStr(set_pair,"; ")+PrepStr(set_version,"; ","v.")+PrepStr(set_author,";");
if(StringLen(str))
_panel.SetText(_count_item++,str,_color_text);
// Опции мультиторгов
str=PrepStr(IntegerToString(MaxTradePairs),"; ","MaxTradePairs=","0")
+PrepStr(IntegerToString(CurrencyBlock),"; ","CurrencyBlock=","0")
+PrepStr(IntegerToString(No1Order_ByDrawdownPercent), PrepStr(IntegerToString(No1Order_ByDrawdownPercent_Off),"%; ","% OFF=","0","%; "),"No1OrderByDD=","0")
+PrepStr(
PrepStr
(
/*value*/PrepStr(DoubleToString(CloseAllOrders_ByDrawdownMoney,0),(kernel_account::currency()=="USD")?"$":kernel_account::currency(),"","0")
/*postfix*/,PrepStr(
DoubleToString(CloseAllOrders_ByDrawdownPercent,1)
, "% "
+PrepStr(DoubleToString(short_hd._settings.close_orders_by_drawdown_for_001lot,0),((kernel_account::currency()=="USD")?"$":kernel_account::currency())+"/0.01 lot sell "," | ","0")
+PrepStr(DoubleToString(long_hd._settings.close_orders_by_drawdown_for_001lot,0),((kernel_account::currency()=="USD")?"$":kernel_account::currency())+"/0.01 lot buy"," | ","0")
," | "
,"0.0"
, PrepStr(DoubleToString(short_hd._settings.close_orders_by_drawdown_for_001lot,0),((kernel_account::currency()=="USD")?"$":kernel_account::currency())+"/0.01 lot sell "," | ","0")
+PrepStr(DoubleToString(long_hd._settings.close_orders_by_drawdown_for_001lot,0),((kernel_account::currency()=="USD")?"$":kernel_account::currency())+"/0.01 lot buy"," | ","0")
)
/*prefix*/,""
/*value_for_none*/,""
/*null_value*/,PrepStr(
DoubleToString(CloseAllOrders_ByDrawdownPercent,1)
, "% "
+PrepStr(DoubleToString(short_hd._settings.close_orders_by_drawdown_for_001lot,0),((kernel_account::currency()=="USD")?"$":kernel_account::currency())+"/0.01 lot sell "," | ","0")
+PrepStr(DoubleToString(long_hd._settings.close_orders_by_drawdown_for_001lot,0),((kernel_account::currency()=="USD")?"$":kernel_account::currency())+"/0.01 lot buy"," | ","0")
,""
,"0.0"
, PrepStr(DoubleToString(short_hd._settings.close_orders_by_drawdown_for_001lot,0),((kernel_account::currency()=="USD")?"$":kernel_account::currency())+"/0.01 lot sell","","0")
+PrepStr(DoubleToString(long_hd._settings.close_orders_by_drawdown_for_001lot,0),((kernel_account::currency()=="USD")?"$":kernel_account::currency())+"/0.01 lot buy"," | ","0")
)
),"; ","Stop="
);
if(StringLen(str))
_panel.SetText(_count_item++,str,_color_text);
// SELL
_panel.SetText(_count_item++,CTRL_PANEL_CAPTION_SELL_GRID,_color_sell);
// Опции разрешения торговли
str=PrepStr(TradeSell?"Y":"NO","; ","TradeSell=","Y")+PrepStr(S_OpenFirstOrder?"Y":"NO","; ","OpenFirstOrder=","Y");
if(StringLen(str))
_panel.SetText(_count_item++,str,_color_text);
_row_sell_lvlvol=_count_item++;
str= ConcatLegVol(_sell_lvl, _sell_grid_levels.count, 0, _sell_volume_max);
_panel.SetText(_row_sell_lvlvol,str,_color_text);
_row_sell_lentp=_count_item++;
str= ConcatLenTP(0, _sell_len_max, 0);
_panel.SetText(_row_sell_lentp,str,_color_text);
_row_sell_pandl=_count_item++;
str= ConcatPANDL(0, 0);
_panel.SetText(_row_sell_pandl,str,_color_text);
_row_sell_dist_tp=_count_item++;
str= ConcatTPDistance(0,0);
_panel.SetText(_row_sell_dist_tp,str,_color_text);
// BUY
_panel.SetText(_count_item++,CTRL_PANEL_CAPTION_BUY_GRID,_color_buy);
// Опции разрешения торговли
str=PrepStr(TradeBuy?"Y":"NO","; ","TradeBuy=","Y")+PrepStr(B_OpenFirstOrder?"Y":"NO","; ","OpenFirstOrder=","Y");
if(StringLen(str))
_panel.SetText(_count_item++,str,_color_text);
_row_buy_lvlvol=_count_item++;
str= ConcatLegVol(_buy_lvl, _buy_grid_levels.count, 0, _buy_volume_max);
_panel.SetText(_row_buy_lvlvol,str,_color_text);
_row_buy_lentp=_count_item++;
str= ConcatLenTP(0, _buy_len_max, 0);
_panel.SetText(_row_buy_lentp,str,_color_text);
_row_buy_pandl=_count_item++;
str= ConcatPANDL(0, 0);
_panel.SetText(_row_buy_pandl,str,_color_text);
_row_buy_dist_tp=_count_item++;
str= ConcatTPDistance(0,0);
_panel.SetText(_row_buy_dist_tp,str,_color_text);
_row_block=_count_item++;
str= ConcatBlockedByTimer(handler_base_spread_block_trading_timer,handler_base_vol_block_trading_timer);
_panel.SetText(_row_block,str,_color_err);
// Примечание
str=GetParamString("comment","");
if(StringLen(str))
_panel.SetText(_count_item++,str,_color_text);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CCtrlPanelExt::CalcGridParam(logic_handler* hdl, int lvl, double& len, double& vol, double& profit, double& dist_tp)
{
vol=0;
len=0;
profit=0;
dist_tp=0;
list<c_order *>* orders = layer_order::get(hdl._order_settings);
layer_order_data* order_data=layer_order::get_by_setting(hdl._order_settings);
double take_profit = layer::correct_price(calc_take_profit::get(hdl._settings, hdl._order_settings, lvl));
len= (lvl<=1)?0:MathAbs((orders.last_or_default().open_price-orders.first_or_default().open_price)/layer_market::tick_size());
dist_tp=((lvl==0)?0:tool_order::get_distance(hdl._order_settings.order_type, orders.last_or_default().open_price, take_profit)/layer_market::tick_size());
LIST_FOREACH(orders, c_order *, item,
{
vol += item.lot;
if(item.is_order())
{
profit += item.commission + item.swap;
profit += item.get_profit_in_currency(take_profit);
continue;
}
if(item.is_before_line(take_profit))
{
profit += item.get_profit_in_currency(take_profit);
}
});
return true;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
bool CCtrlPanelExt::CalcTickParam(logic_handler* hdl,int lvl, double& pandl, double& dist_tp, double& len, double& dist_stop)
{
dist_tp=0;
dist_stop=0;
pandl=0;
list<c_order *>* orders = layer_order::get(hdl._order_settings);
layer_order_data* order_data=layer_order::get_by_setting(hdl._order_settings);
pandl=order_data.profit_clear_currency();
double take_profit = layer::correct_price(calc_take_profit::get(hdl._settings, hdl._order_settings, lvl));
double current_price = layer_market::price_close(hdl._order_settings.order_type);
dist_tp=(lvl==0)?0:tool_order::get_distance(hdl._order_settings.order_type, current_price,take_profit)/layer_market::tick_size();
len=(lvl==0)?0:tool_order::get_distance(hdl._order_settings.order_type, current_price,orders.first_or_default().open_price)/layer_market::tick_size();
return true;
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void CCtrlPanelExt::OnTickCalculateEvent()
{
CCtrlPanelComment::OnTickCalculateEvent();
string str;
double len,vol, dist_tp,pandl,dist_stop;
if(_readyForUpdate)
{
// SELL
CalcGridParam(short_hd, _sell_lvl, len, vol, _sell_profit,dist_tp);
str= ConcatLegVol(_sell_lvl, _sell_grid_levels.count, vol, _sell_volume_max);
_panel.SetText(_row_sell_lvlvol,str,_color_text);
str= ConcatLenTP(len, _sell_len_max, dist_tp);
_panel.SetText(_row_sell_lentp,str,_color_text);
// BUY
CalcGridParam(long_hd, _buy_lvl, len, vol, _buy_profit,dist_tp);
str= ConcatLegVol(_buy_lvl, _buy_grid_levels.count, vol, _buy_volume_max);
_panel.SetText(_row_buy_lvlvol,str,_color_text);
str= ConcatLenTP(len, _buy_len_max, dist_tp);
_panel.SetText(_row_buy_lentp,str,_color_text);
}
// SELL
CalcTickParam(short_hd, _sell_lvl, pandl, dist_tp, len,dist_stop);
str = ConcatPANDL(pandl, _sell_profit);
_panel.SetText(_row_sell_pandl,str,_color_text);
str= ConcatTPDistance(dist_tp,len);
_panel.SetText(_row_sell_dist_tp,str,_color_text);
// BUY
CalcTickParam(long_hd, _buy_lvl, pandl, dist_tp,len, dist_stop);
str= ConcatPANDL(pandl, _buy_profit);
_panel.SetText(_row_buy_pandl,str,_color_text);
str= ConcatTPDistance(dist_tp,len);
_panel.SetText(_row_buy_dist_tp,str,_color_text);
str= ConcatBlockedByTimer(handler_base_vol_block_trading_timer,handler_base_spread_block_trading_timer);
_panel.SetText(_row_block,str,_color_err);
_readyForUpdate=true;
};
#endif
//+------------------------------------------------------------------+