Hi, I'm testing a strategy and I would like the backtest to close all position and stop the script from running if my netprofit has reached x $.
Is there a function to stop the strategy completely when profittarget has been reaches?
I can't make that happen with setprofittarget(x$)
Also, is there an alternative to the function BarSinceEntry?
I'm using 1 second graph and if there are no trades on every second, each bar does not represent 1 second. I want to be able to close my orders if TimeSinceEntry >1800(seconds) and not BarSinceEntry>1800(bars xx).
how to stop script when netprofit reaches targetprofit? [SOLVED]
- JoshM
- Posts: 2195
- Joined: 20 May 2011
- Location: The Netherlands
- Has thanked: 1544 times
- Been thanked: 1565 times
- Contact:
Re: how to stop script when netprofit reaches targetprofit? [SOLVED]
This will not literally "stop" a script, but any statement after `#return` will not be executed:Hi, I'm testing a strategy and I would like the backtest to close all position and stop the script from running if my netprofit has reached x $.
Is there a function to stop the strategy completely when profittarget has been reaches?
I can't make that happen with setprofittarget(x$)
Code: Select all
if (NetProfit > 1000) then
#return;
// All statements that appear below
// return are not executed
You can use `PosTradeEntryDateTime` for that:Also, is there an alternative to the function BarSinceEntry?
I'm using 1 second graph and if there are no trades on every second, each bar does not represent 1 second. I want to be able to close my orders if TimeSinceEntry >1800(seconds) and not BarSinceEntry>1800(bars xx).
Code: Select all
Variables:
oneSecondDT(ELTimeToDateTime_s(1)),
timeSinceEntry(0);
timeSinceEntry = ComputerDateTime - PosTradeEntryDateTime(1, 0);
if (timeSinceEntry > (1800 * oneSecondDT)) then
// exit