oprava rel profit + exit protection
This commit is contained in:
@ -38,6 +38,7 @@ def close_position(state, data, direction: TradeDirection, reason: str, followup
|
||||
|
||||
#pri uzavreni tradu zapisujeme SL history - lepsi zorbazeni v grafu
|
||||
insert_SL_history(state)
|
||||
state.dont_exit_already_activated = False
|
||||
state.vars.pending = state.vars.activeTrade.id
|
||||
state.vars.activeTrade = None
|
||||
state.vars.last_exit_index = data["index"]
|
||||
|
||||
@ -21,34 +21,53 @@ def dontexit_protection_met(state, data, direction: TradeDirection):
|
||||
else:
|
||||
smer = "short"
|
||||
|
||||
mother_signal = state.vars.activeTrade.generated_by
|
||||
#zapracovana optimalizace, kdy po aktivovanem DONTEXITU to opet klesne pod profit a neprodá se
|
||||
#vyreseno pri kazde aktivaci se vyplni flag already_activated
|
||||
#pri naslednem false podminky se v pripade, ze je aktivovany flag posle True -
|
||||
#take se vyrusi v closu
|
||||
def process_result(result):
|
||||
if result:
|
||||
state.dont_exit_already_activated = True
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
if mother_signal is not None:
|
||||
#TESTUJEME DONT_EXIT_
|
||||
cond_dict = state.vars.conditions[KW.dont_exit][mother_signal][smer]
|
||||
def evaluate_result():
|
||||
mother_signal = state.vars.activeTrade.generated_by
|
||||
|
||||
if mother_signal is not None:
|
||||
#TESTUJEME DONT_EXIT_
|
||||
cond_dict = state.vars.conditions[KW.dont_exit][mother_signal][smer]
|
||||
#OR
|
||||
result, conditions_met = evaluate_directive_conditions(state, cond_dict, "OR")
|
||||
state.ilog(lvl=1,e=f"DONT_EXIT {mother_signal} {smer} =OR= {result}", **conditions_met, cond_dict=cond_dict, already_activated=str(state.dont_exit_already_activated))
|
||||
if result:
|
||||
return True
|
||||
|
||||
#OR neprosly testujeme AND
|
||||
result, conditions_met = evaluate_directive_conditions(state, cond_dict, "AND")
|
||||
state.ilog(lvl=1,e=f"DONT_EXIT {mother_signal} {smer} =AND= {result}", **conditions_met, cond_dict=cond_dict, already_activated=str(state.dont_exit_already_activated))
|
||||
if result:
|
||||
return True
|
||||
|
||||
cond_dict = state.vars.conditions[KW.dont_exit]["common"][smer]
|
||||
#OR
|
||||
result, conditions_met = evaluate_directive_conditions(state, cond_dict, "OR")
|
||||
state.ilog(lvl=1,e=f"DONT_EXIT {mother_signal} {smer} =OR= {result}", **conditions_met, cond_dict=cond_dict)
|
||||
state.ilog(lvl=1,e=f"DONT_EXIT common {smer} =OR= {result}", **conditions_met, cond_dict=cond_dict, already_activated=str(state.dont_exit_already_activated))
|
||||
if result:
|
||||
return True
|
||||
|
||||
#OR neprosly testujeme AND
|
||||
result, conditions_met = evaluate_directive_conditions(state, cond_dict, "AND")
|
||||
state.ilog(lvl=1,e=f"DONT_EXIT {mother_signal} {smer} =AND= {result}", **conditions_met, cond_dict=cond_dict)
|
||||
if result:
|
||||
return True
|
||||
|
||||
cond_dict = state.vars.conditions[KW.dont_exit]["common"][smer]
|
||||
#OR
|
||||
result, conditions_met = evaluate_directive_conditions(state, cond_dict, "OR")
|
||||
state.ilog(lvl=1,e=f"DONT_EXIT common {smer} =OR= {result}", **conditions_met, cond_dict=cond_dict)
|
||||
if result:
|
||||
return True
|
||||
|
||||
#OR neprosly testujeme AND
|
||||
result, conditions_met = evaluate_directive_conditions(state, cond_dict, "AND")
|
||||
state.ilog(lvl=1,e=f"DONT_EXIT common {smer} =AND= {result}", **conditions_met, cond_dict=cond_dict)
|
||||
return result
|
||||
state.ilog(lvl=1,e=f"DONT_EXIT common {smer} =AND= {result}", **conditions_met, cond_dict=cond_dict, already_activated=str(state.dont_exit_already_activated))
|
||||
return result
|
||||
|
||||
#nejprve evaluujeme vsechny podminky
|
||||
result = evaluate_result()
|
||||
|
||||
#pak evaluujeme vysledek a vracíme
|
||||
return process_result(result)
|
||||
|
||||
|
||||
def exit_conditions_met(state, data, direction: TradeDirection):
|
||||
if direction == TradeDirection.LONG:
|
||||
|
||||
@ -96,6 +96,13 @@ def eval_close_position(state: StrategyState, data):
|
||||
if max_price_signal or dontexit_protection_met(state=state, data=data,direction=TradeDirection.SHORT) is False:
|
||||
close_position(state=state, data=data, direction=TradeDirection.SHORT, reason=f"PROFIT or MAXPROFIT REACHED {max_price_signal=}")
|
||||
return
|
||||
#pokud je cena horsi, ale byla uz dont exit aktivovany - pak prodavame také
|
||||
elif state.dont_exit_already_activated == True:
|
||||
#TODO toto mozna take na direktivu, timto neprodavame pokud porkacuje trend - EXIT_PROT_BOUNCE_IMMEDIATE
|
||||
#if dontexit_protection_met(state=state, data=data,direction=TradeDirection.SHORT) is False:
|
||||
close_position(state=state, data=data, direction=TradeDirection.SHORT, reason=f"EXIT PROTECTION BOUNCE {state.dont_exit_already_activated=}")
|
||||
state.dont_exit_already_activated = False
|
||||
return
|
||||
|
||||
#FORCED EXIT PRI KONCI DNE
|
||||
if eod_exit_activated(state, data, TradeDirection.SHORT):
|
||||
@ -177,7 +184,14 @@ def eval_close_position(state: StrategyState, data):
|
||||
if max_price_signal or dontexit_protection_met(state, data, direction=TradeDirection.LONG) is False:
|
||||
close_position(state=state, data=data, direction=TradeDirection.LONG, reason=f"PROFIT or MAXPROFIT REACHED {max_price_signal=}")
|
||||
return
|
||||
|
||||
#pokud je cena horsi, ale byl uz dont exit aktivovany - pak prodavame také
|
||||
elif state.dont_exit_already_activated == True:
|
||||
#TODO toto mozna take na direktivu, timto neprodavame pokud porkacuje trend - EXIT_PROT_BOUNCE_IMMEDIATE
|
||||
# if dontexit_protection_met(state=state, data=data,direction=TradeDirection.LONG) is False:
|
||||
close_position(state=state, data=data, direction=TradeDirection.LONG, reason=f"EXIT PROTECTION BOUNCE {state.dont_exit_already_activated=}")
|
||||
state.dont_exit_already_activated = False
|
||||
return
|
||||
|
||||
#FORCED EXIT PRI KONCI DNE
|
||||
if eod_exit_activated(state, data, TradeDirection.LONG):
|
||||
close_position(state=state, data=data, direction=TradeDirection.LONG, reason="EOD EXIT ACTIVATED")
|
||||
|
||||
@ -55,7 +55,7 @@ def populate_all_indicators(data, state: StrategyState):
|
||||
#TODO tento lof patri spis do nextu classic SL - je poplatny typu stratefie
|
||||
#TODO na toto se podivam, nejak moc zajasonovani a zpatky -
|
||||
#PERF PROBLEM
|
||||
state.ilog(lvl=1,e="ENTRY", msg=f"LP:{lp} P:{state.positions}/{round(float(state.avgp),3)} SL:{state.vars.activeTrade.stoploss_value if state.vars.activeTrade is not None else None} GP:{state.vars.activeTrade.goal_price if state.vars.activeTrade is not None else None} profit:{round(float(state.profit),2)} profit_rel:{round(np.mean(state.rel_profit_cum),6) if len(state.rel_profit_cum)>0 else 0} Trades:{len(state.tradeList)} pend:{state.vars.pending}", rel_profit_cum=str(state.rel_profit_cum), activeTrade=json.loads(json.dumps(state.vars.activeTrade, default=json_serial)), prescribedTrades=json.loads(json.dumps(state.vars.prescribedTrades, default=json_serial)), pending=str(state.vars.pending))
|
||||
state.ilog(lvl=1,e="ENTRY", msg=f"LP:{lp} P:{state.positions}/{round(float(state.avgp),3)} SL:{state.vars.activeTrade.stoploss_value if state.vars.activeTrade is not None else None} GP:{state.vars.activeTrade.goal_price if state.vars.activeTrade is not None else None} profit:{round(float(state.profit),2)} profit_rel:{round(np.sum(state.rel_profit_cum),6) if len(state.rel_profit_cum)>0 else 0} Trades:{len(state.tradeList)} pend:{state.vars.pending}", rel_profit_cum=str(state.rel_profit_cum), activeTrade=json.loads(json.dumps(state.vars.activeTrade, default=json_serial)), prescribedTrades=json.loads(json.dumps(state.vars.prescribedTrades, default=json_serial)), pending=str(state.vars.pending))
|
||||
|
||||
#kroky pro CONFIRMED BAR only
|
||||
if conf_bar == 1:
|
||||
|
||||
Reference in New Issue
Block a user