try and catch changes strategy outcome - futures io
futures io futures trading



try and catch changes strategy outcome


Discussion in NinjaTrader

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




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

try and catch changes strategy outcome

(login for full post details)
  #1 (permalink)
Muscat, Oman
 
Experience: Intermediate
Platform: Ninja and MT4
Trading: Forex
 
Posts: 15 since Apr 2012
Thanks: 4 given, 3 received

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 futures io?
Work with historical tcks data on MUltichart NET PowerLa …
MultiCharts
Improve current ZigZag indicator in NT8
NinjaTrader
Reading A set of Trading Signals
EasyLanguage Programming
ZigZag with Depth and Backstep
EasyLanguage Programming
Help Needed: TOS Options Chain IV & IMPL MOVE Calcul …
ThinkOrSwim
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Battlestations: Show us your trading desks!
124 thanks
Big Mike in Ecuador
61 thanks
Want your NinjaTrader indicator created, free?
28 thanks
If you needed one-on-one help with any trading issue, ho …
26 thanks
Selling Options on Futures?
21 thanks
 
(login for full post details)
  #3 (permalink)
OC, California, USA
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,958 since Jun 2009
Thanks: 528 given, 3,648 received


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 futures io Trade Journal Reply With Quote
The following user says Thank You to shodson for this post:
 
(login for full post details)
  #4 (permalink)
Muscat, Oman
 
Experience: Intermediate
Platform: Ninja and MT4
Trading: Forex
 
Posts: 15 since Apr 2012
Thanks: 4 given, 3 received


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
 
(login for full post details)
  #5 (permalink)
OC, California, USA
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,958 since Jun 2009
Thanks: 528 given, 3,648 received


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 futures io Trade Journal Reply With Quote
 
(login for full post details)
  #6 (permalink)
Muscat, Oman
 
Experience: Intermediate
Platform: Ninja and MT4
Trading: Forex
 
Posts: 15 since Apr 2012
Thanks: 4 given, 3 received


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
 
(login for full post details)
  #7 (permalink)
OC, California, USA
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,958 since Jun 2009
Thanks: 528 given, 3,648 received


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 futures io Trade Journal Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > try and catch changes strategy outcome


Last Updated on December 29, 2014


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts