NexusFi: Find Your Edge


Home Menu

 





try and catch changes strategy outcome


Discussion in NinjaTrader

Updated
    1. trending_up 1,462 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

try and catch changes strategy outcome

  #1 (permalink)
 stearno 
Muscat, Oman
 
Experience: Intermediate
Platform: Ninja and MT4
Trading: Forex
Posts: 15 since Apr 2012
Thanks Given: 4
Thanks Received: 3

I just found something out on my strategy. If I use try and catch on my strategy, that it actually alters the code. I ran the strategy with try and catch code in there. I got 14,000 trades. I only put "//" in front of the try and catch code with no other changes and then ran the strategy and got 7 trades.

Here is a video showing this: https://drive.google.com/file/d/0B5nlvdyRv0qYckwxeWdxUDNUUkk/view?usp=sharing

Anybody else have this issue? Few more questions: How does it happen, why does it happen, how do I fix it?

-Stearno

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
GFIs1 1 DAX trade per day journal
11 thanks
  #3 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


Check the "Log" tab in the Control Center. You'll probably find error messages in there because your code probably has runtime exception(s). You need to take care of that. Your try/catch that you commented out must have been "handling" the exceptions so the backtest could continue to run without further problems. WIthout the try/catch there the strategy will stop trading when exceptions occur.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 stearno 
Muscat, Oman
 
Experience: Intermediate
Platform: Ninja and MT4
Trading: Forex
Posts: 15 since Apr 2012
Thanks Given: 4
Thanks Received: 3


shodson View Post
Check the "Log" tab in the Control Center. You'll probably find error messages in there because your code probably has runtime exception(s). You need to take care of that. Your try/catch that you commented out must have been "handling" the exceptions so the backtest could continue to run without further problems. WIthout the try/catch there the strategy will stop trading when exceptions occur.

Thanks for your advice! It does not make sense to me how it could be covering up the error because the try and catch are on the same line with no code in between it. But I will debug as per your advice as you know more than me and it does not need to make sense to me ).

I will update as I find the error.

-Stearno

Started this thread Reply With Quote
  #5 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


stearno View Post
Thanks for your advice! It does not make sense to me how it could be covering up the error because the try and catch are on the same line with no code in between it. But I will debug as per your advice as you know more than me and it does not need to make sense to me ).

I will update as I find the error.

-Stearno

try/catch will catch exceptions so you can "handle" them in the catch code block so the program can continue on in a way that you see fit. Without the try/catch if an exception happens Ninjatrader will just stop running your strategy if your exception is not handled

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
 stearno 
Muscat, Oman
 
Experience: Intermediate
Platform: Ninja and MT4
Trading: Forex
Posts: 15 since Apr 2012
Thanks Given: 4
Thanks Received: 3


shodson View Post
try/catch will catch exceptions so you can "handle" them in the catch code block so the program can continue on in a way that you see fit. Without the try/catch if an exception happens Ninjatrader will just stop running your strategy if your exception is not handled

Okay, that is what it does. But can what you said still be true when I have the code written like this:

try{}catch (Exception e) {Print(Time[0] + " " + e.ToString()); }

As you can see, I don't have any code inbetween the "try" and the "catch". So that is what I mean about it is hard to believe that it is catching an error.

But obviously, you are right because it is stopping an error from happening when it is in the code, even when written like that.

By the way, what is the point of the Log? You said to reference the log. Does it only just notify you of an error? Because it does not give any specifics. So basically, if the log has an error, then you use the try/catch to find out what that error is?

-stearno

Started this thread Reply With Quote
  #7 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


stearno View Post
Okay, that is what it does. But can what you said still be true when I have the code written like this:

try{}catch (Exception e) {Print(Time[0] + " " + e.ToString()); }

As you can see, I don't have any code inbetween the "try" and the "catch". So that is what I mean about it is hard to believe that it is catching an error.

But obviously, you are right because it is stopping an error from happening when it is in the code, even when written like that.

By the way, what is the point of the Log? You said to reference the log. Does it only just notify you of an error? Because it does not give any specifics. So basically, if the log has an error, then you use the try/catch to find out what that error is?

-stearno

The try/catch you wrote is useless because there is no code in the try{} block.

The log just tells you an error occurred somewhere in your code. You have to track it down using try/catch and Print() statements.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote




Last Updated on December 29, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts