Daily PT and SL for Backtesting Only
I'm having trouble getting any script to backtest properly with a Daily PT and SL (I'm intra-day trading). For example, let's say a script can take numerous trades during the day, including multiple entries in the same direction. Each trade has its own individual PT and SL. With AI help (chatGPT, cursor, Claude) I've been trying to get a script to recognize a daily PT and SL so it would quit trading for the day (again, on a backtest only) once one of those are hit. I already have this set up for live trading in Portfolio Trader through an MM signal, but it doesn't work outside of Portfolio Trader. I don't need the script to call on any equity positions or anything, just simply track cumulative PnL (with everyday beginning at zero) and cut off trading if daily PT or SL is hit. Is this something someone has successfully implemented?
- faraz
- Posts: 204
- Joined: Feb 25 2011
- Location: 1stchoicestrategy.com
- Has thanked: 26 times
- Been thanked: 67 times
Code: Select all
vars: DailyPnL(0), DailyPT(1000), DailySL(-500), TradePnL(0);
if D<>D[1] then begin DailyPnL = 0; end;
TradePnL = I_OpenEquity - I_OpenEquity[1];
DailyPnL = DailyPnL + TradePnL;
if DailyPnL >= DailyPT or DailyPnL <= DailySL then begin
// Stop trading for the day and exit trades
condition1 = false;
sell next bar market;
buytocover next bar market;
end else begin
condition1 = true;
If contition1 then begin
// Any trading code below here //////////////////////////////////////
// Any trading code above here //////////////////////////////////////
end;
end;
Trading Excellence ! ! !
1stChoiceStrategy.com