How to write "Cut Loss Twice then Stop Auto Trade today ?"

Example

Buy = Cross( MACD(), Signal() );
Sell = Cross( Signal(), MACD() );

i have found the way to limit the trade signal per day, but fail to find limit cut loss ways

// modify Buy array and allow only first N signals
Buy = Buy AND Sum( Buy, BarsSince( newDay) +1 ) <= N;

How can change it to limit number of cut loss trade?

Thanks!

It is similar to response in recent thread of yours

Same conclusion here... you have to write CBT (custom backtest) code but not high level but in this case rather starting mid level one.

Porfolio Backtester Interface Reference

  • high-level approach (the easiest)
    using Backtest() method and it runs default backtest procedure (as in old versions) - allows simple implementation of custom metrics
  • mid-level approach
    using PreProcess()/ProcessTradeSignal()/PostProcess() methods - allows to modify signals, query open positions (good for advanced position sizing)
  • low-level approach (the most complex)
    using PreProcess()/EnterTrade()/ExitTrade()/ScaleTrade()/UpdateStats()/HandleStops()/PostProcess() methods - provides full control over entire backtest process for hard-code programmers only

But same as in previous thread you have to use GetProfit method to check for losses (and to count loss trades) within BarCount iteration.


If it is not backtest but live trading then (if possible) retrieve loss information via your broker's API to stop auto-trading.

Yes yes, i have been succeed to set the max loss wif code api during auto trade wif ibcontroller, but seems fail to show in backtest