2,5 КиБ
2,5 КиБ
PosMgmt
Open position management: breakeven, partial closes by volume, and partial closes conditioned on indicators.
Main features
- Breakeven by fixed points, ATR or risk/reward ratio (
CBreakEven,CBreakEvenSimple,CBreakEvenAtr,CBreakEvenRR). - Partial closes by volume/TP percentage across multiple stages (
CPartials). - Conditional partial closes, triggered by a pluggable condition (e.g. RSI) instead of a fixed level (
CConditionalPartials,CConditionalPartialsFactory) — see ConditionalPartial for the class hierarchy.
Basic usage
Breakeven
//--- Atr
atr_ultra_optimized.SetVariables(_Period, _Symbol, 0, 14);
atr_ultra_optimized.SetInternalPointer();
//--- Configure the breakeven values so it can be used
break_even.SetBeByAtr(InpBeAtrMultiplier, InpBeAtrMultiplierExtra, GetPointer(atr_ultra_optimized));
break_even.SetBeByFixedPoints(InpBeFixedPointsToPutBe, InpBeFixedPointsExtra);
break_even.SetBeByRR(InpBeRrDbl, InpBeTypeExtraRr, InpBeExtraPointsRrOrAtrMultiplier, GetPointer(atr_ultra_optimized));
break_even.SetInternalPointer(InpTypeBreakEven);
break_even.obj.AddLogFlags(InpLogLevelBe);
Partial closes
g_partials.AddLogFlags(InpLogLevelPartials);
g_partials.Init(InpMagic, _Symbol, InpVolumePercentageToClose, InpTpPercentagesForPartials);
Conditional partial closes
if(InpPartialsIsEnable)
{
// Atr creation
g_atr = new CAtr();
g_atr.Create(_Period, _Symbol, 14, true, true);
g_atr.SetAsSeries(true);
CAutoCleaner::AddPtr(g_atr); // auto-deleted on deinit
// Dynamic instance from the factory
g_partials = CConditionalPartialsFactory::Create(InpPartialsClassManagerType);
g_partials.AddLogFlags(InpPartialsLogLevel);
// RSI condition
CConditionalPartialsIndRsi* rsi_condition = new CConditionalPartialsIndRsi();
if(!rsi_condition.Init(InpPartialsRsiTimeframe, _Symbol, InpPartialsRsiPeriod, InpPartialsRsiOverBoughtLevel, InpPartialsRsiOverSoldLevel))
return INIT_PARAMETERS_INCORRECT;
ConditionalPartialConfig config;
config.condition = rsi_condition;
config.min_distance_to_close_pos = CreateDiffptr(MODE_DIFF_BY_ATR, _Symbol, g_atr, 0, InpPartialsMinDistanceInAtrMul);
config.str_percentage_volume_to_close = InpPartialsVolumeToClosePercentage;
config.magic_number = InpMagic;
if(!g_partials.Init(config))
return INIT_PARAMETERS_INCORRECT;
else
CAutoCleaner::AddPtr(g_partials);
}
Only the most representative classes are shown here.