Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Hi.... I'm trying to learn how to stop trading for the day if my profit target / loss limit is reached for the day.
Please take a look at my strategy's code. When I tried to backtest for over 1 year data, only the data of first day is being backtested and not anymore after the Profit / Loss limits are reached.
I tried to reset the totPnl if the time is between 3:45 AM and 3:46 AM (my local time at which the electronic market starts again after the daily break). but it is clearly not working....
I don't know how to reset this totPnl so that it would go back to zero again for the next day to backtest the data... Please help.
Can you help answer these questions from other members on NexusFi?
Just made some modifications to this code and here is the modified version
I have clearly understood that 'not being able to reset the 'return' is the only problem in the code... I deliberately increased the values of totPnl in this code and ran the strategy analyzer, it showed thousands of trades as the if () condition is satisfied. Can anyone enlighten me how to achieve this please....
The logic i wrote may be enough for trading live in the sim as it would stop trading after one of those conditions in the if() are met. I would shutdown my computer and restart tomorrow and the program must work normal as it is a fresh start for it. But for the sake of backtesting, I need to reset the totPnl and then evaluate if the strategies I'm going to write are profitable or not...
You need to store the PnL of previos days in if(FirstBarOfSession) totPnL=...
Then on each bar you query todays PnL as totPnL - Performance.AllTrades.TradesPerformance.Currency.CumProfit;