EA-Setka-2/framework/tool/tool_take_profit.mqh
super.admin a4b861dd93 convert
2025-05-30 14:50:44 +02:00

101 lines
No EOL
2.9 KiB
MQL5

#ifndef FRAMEWORK_TOOL_TAKE_PROFIT_MQH
#define FRAMEWORK_TOOL_TAKE_PROFIT_MQH
class tool_take_profit {
public:
static double get_avg_price_by_lot_factor ( list<c_order *> *orders,
int skip_stop_order_count,
bool with_virtual_order = false,
double virtual_price = 0.0,
double virtual_lot = 0.0 ) {
double result = 0,
lots = 0;
c_order *last_order = NULL;
for ( int i = 0; i < orders.count; i++ ) {
last_order = orders.items[i];
if ( skip_stop_order_count != 0
&& last_order.is_order_stop () ) {
skip_stop_order_count -= 1;
continue;
}
result += last_order.open_price * last_order.lot;
lots += last_order.lot;
}
if ( with_virtual_order
&& orders.count > 0 ) {
result += virtual_price * virtual_lot;
lots += virtual_lot;
}
//+------------------------------------------------------------------+
//Capteen 190807 http://tlap.com/forum/laboratoriya-profitfx/24/open-source-sovetnik-forex-setka-trader-mod-i-ea-setka/2738/?do=findComment&comment=432167
//+------------------------------------------------------------------+
return lots != 0 ? result / lots : 0;
}
static double get_level_without_loss ( list<c_order *> *orders,
int skip_stop_order_count,
bool with_virtual_order = false,
double virtual_price = 0.0,
double virtual_lot = 0.0 ) {
double lots = 0.0;
double profit = 0.0;
double profit_pips;
c_order *last_order = NULL;
if (orders.count == 0) return 0.0;
for ( int i = 0; i < orders.count; i++ ) {
//#ifdef MQL4
last_order = orders.items[i];
//#endif
//#ifdef MQL5
// last_order = new orders.items[i];
//#endif
if ( skip_stop_order_count != 0
&& last_order.is_order_stop () ) {
skip_stop_order_count -= 1;
continue;
}
profit += last_order.get_profit_in_currency();
lots += last_order.lot;
if ( last_order.is_order () ) {
profit += last_order.commission + last_order.swap; //*layer_market::tick_value();
}
}
//if ( with_virtual_order
// && orders.count > 0 ) {
// profit += c_order::get_profit_in_currency ( last_order.order_type,
// virtual_price,
// virtual_lot );
// lots += virtual_lot;
//}
if ( profit == 0.0
&& orders.count > 0 ) {
return layer_market::price_close ( last_order.order_type );
}
if (lots ==0 || layer_market::tick_value ()==0)
profit_pips = 0;
else
profit_pips = ( profit / lots ) / layer_market::tick_value ();
double profit_points = layer_market::to_points ( profit_pips );
// double ret = tool_order::deduct_points_from_current_price ( last_order.order_type, profit_points );
return tool_order::deduct_points_from_current_price ( last_order.order_type, profit_points );
//#ifdef MQL5
// delete last_order;
//#endif
// return ret;
}
};
#endif