NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > ATM Strategies (Discretionary Trading)

ATM Strategies (Discretionary Trading) Support for Advanced Trade Management, AutoTrail, AutoBreakeven, Stop Strategy and Simulated Stops etc...

Reply
 
Thread Tools Display Modes
Old 06-18-2012, 11:16 AM   #16
djkiwi
Senior Member
 
Join Date: Mar 2010
Posts: 320
Thanks: 87
Thanked 5 times in 5 posts
Default

Hi Brett, because this default point value for equities in ninjatrader is wrong I'm having to try and perform a workaround. However the workaround isn't working either and would appreciate some advice. The code below says if it's a stock then multiply the point value by 100. If it's a future leave as point value. The problem is this part doesn't work:

//if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Stock);

I'm not sure if I'm using this correctly and would appreciate some guidance.

If I put in the actual stock name such as this it works ok. (please see code):

if (Instrument.MasterInstrument.Name == "TNA")

PHP Code:
//if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Stock);
            
if (Instrument.MasterInstrument.Name == "TNA")
            {
            
RR2T = ((reward1/risk1+reward2/risk2)/2);            
            
Reward2TMath.Round(((reward1+reward2) * Instrument.MasterInstrument.PointValue)*1002MidpointRounding.AwayFromZero);
            
Risk2TMath.Round(((risk1+risk2) * Instrument.MasterInstrument.PointValue)*1002MidpointRounding.AwayFromZero);
            
            
RR3T = ((reward1/risk1+reward2/risk2+reward3/risk3)/3);
            
Reward3TMath.Round(((reward1+reward2+reward3) * Instrument.MasterInstrument.PointValue)*1002MidpointRounding.AwayFromZero);
            
Risk3TMath.Round(((risk1+risk2+risk3) * Instrument.MasterInstrument.PointValue)*1002MidpointRounding.AwayFromZero);                
            }
            
            
//if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Future);
            
if (Instrument.MasterInstrument.Name == "TF")
            {
            
RR2T = ((reward1/risk1+reward2/risk2)/2);            
            
Reward2TMath.Round(((reward1+reward2) * Instrument.MasterInstrument.PointValue), 2MidpointRounding.AwayFromZero);
            
Risk2TMath.Round(((risk1+risk2) * Instrument.MasterInstrument.PointValue), 2MidpointRounding.AwayFromZero);    
                
            
RR3T = ((reward1/risk1+reward2/risk2+reward3/risk3)/3);
            
Reward3TMath.Round(((reward1+reward2+reward3) * Instrument.MasterInstrument.PointValue), 2MidpointRounding.AwayFromZero);
            
Risk3TMath.Round(((risk1+risk2+risk3) * Instrument.MasterInstrument.PointValue), 2MidpointRounding.AwayFromZero);               
            } 
The goal is not to have to put in every individual stock. I'd like the system to be able to automatically know if it's a stock or a future before putting on the trade. This will call up a different ATM strategy as well depending on whether it's a stock or a future.

Any ideas on this one?

Thanks in advance
DJ
Last edited by djkiwi; 06-18-2012 at 11:22 AM.
djkiwi is offline  
Reply With Quote
Old 06-18-2012, 11:30 AM   #17
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
Default

DJ,

Do you have the semi colon at the end of your statement checking for InstrumentType? Can you remove that and try again?

Can you run a quick test using the following segment and let me know if "Is stock" is printed to the output window, or if it does not return:

Code:
			if (Instrument.MasterInstrument.InstrumentType == InstrumentType.Stock)
			{
				Print("Is stock");
			}
NinjaTrader_Matthew is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Matthew for this post:
Old 06-18-2012, 12:32 PM   #18
djkiwi
Senior Member
 
Join Date: Mar 2010
Posts: 320
Thanks: 87
Thanked 5 times in 5 posts
Default

Thanks Matthew for picking that up. Now it works perfectly. It was indeed the issue and need to pay closer attention to these things. I have another odd one though I'd appreciate some help. I'm using this for the unrealized gain calculation:

Variables:

private double unrealized = 0;


Onbarupdate()

unrealized = GetAtmStrategyUnrealizedProfitLoss(atmStrategyId1) ;

Then use drawtextfixed in an Infopanel to show the unrealized gain/loss on the chart:

"Unreal: " + "$"+((unrealized)).ToString("N0") + "\n"+

Issue:

Now I have been using this for sometime with futures without any issue at all. It calls this:

if (GetAtmStrategyMarketPosition(atmStrategyId1) != MarketPosition.Flat)

So once in a position it will invoke the real time unrealized part above. For some unknown reason there is a problem with equities which appears in the log. I've attached a picture of it. This is a method error. Is there some different type of method for equities than futures? Never had a single error with futures.

Thanks
DJ



Thanks in advance
DJ
Attached Images
File Type: png unrealized.PNG (58.3 KB, 3 views)
djkiwi is offline  
Reply With Quote
Old 06-18-2012, 01:07 PM   #19
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
Default

Hello,

Are you also checking the atmStrategID contains a value?

Please refer to our Reference Sample on SampleATMPnL:

Code:
			if (atmStrategyId.Length > 0)
			{
				unrealizedProfitLoss = Instrument.MasterInstrument.Round2TickSize(GetAtmStrategyUnrealizedProfitLoss(atmStrategyId));
			}
Can you please try implementing your code as closely as you can as our example and let me know if you still get this method error.
NinjaTrader_Matthew is offline  
Reply With Quote
Old 06-19-2012, 10:56 AM   #20
djkiwi
Senior Member
 
Join Date: Mar 2010
Posts: 320
Thanks: 87
Thanked 5 times in 5 posts
Default

Hi Matthew, unfortunately that doesn't work either. I ran the sample atmPNL strategy on an equities instrument and put a sell stop order on my charts (see chart). I set COBC to false. Once the order was triggered I got the same error (see attached). There seems to be some problem using this unrealized code on equities. I also put this in my code:

PHP Code:
if (atmStrategyId1.Length 0)
            {    
            
//unrealized = GetAtmStrategyUnrealizedProfitLoss(atmStrategyId1);
            
unrealized =Instrument.MasterInstrument.Round2TickSize(GetAtmStrategyUnrealizedProfitLoss(atmStrategyId1));
                                 
            } 
I got the same error. As mentioned in my last post I get ZERO errors on futures. I suggest you try this sampleatmpnl on equities and see if you get the same issue.

Cheers
DJ
Attached Images
File Type: png tnaunrealized.PNG (73.9 KB, 6 views)
File Type: jpg tna chart.jpg (50.8 KB, 4 views)
djkiwi is offline  
Reply With Quote
Old 06-19-2012, 01:03 PM   #21
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
Default

DJ,

I have no issues running this on Stocks, Futures or Forex and never receive this area.

Are you resetting atmStrategyId1 anywhere in your code?

Can you download and run the SampleATMPnL strategy on a stock with or without errors?
Attached Files
File Type: zip SampleATMPnL_NT7.zip (2.2 KB, 8 views)
NinjaTrader_Matthew is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Matthew for this post:
Old 06-19-2012, 01:18 PM   #22
djkiwi
Senior Member
 
Join Date: Mar 2010
Posts: 320
Thanks: 87
Thanked 5 times in 5 posts
Default

Hi Matthew, this is very strange. All I did was run the sampleatmpnl with nothing else and same errors. I tried it again. Same thing. Here are the charts and sampleatmpnl with my atm strategy included.

I'm not resetting anything here just running sampleatmpnl.

Cheers
DJ
Attached Images
File Type: png sample ATM1.PNG (128.9 KB, 3 views)
File Type: png sampleatm2.PNG (159.8 KB, 7 views)
Attached Files
File Type: cs SampleATMPnL.cs (4.7 KB, 5 views)
Last edited by djkiwi; 06-19-2012 at 01:25 PM.
djkiwi is offline  
Reply With Quote
Old 06-19-2012, 02:25 PM   #23
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
Default

Hello,

I only received errors with your version of the script when I did not have an ATM Strategy called TNAtwotargets

Once I named an ATM Strategy TNAtwotargets, everything worked as expected. Can you double check your ATM Strategy name and the string you're using?
NinjaTrader_Matthew is offline  
Reply With Quote
Old 06-19-2012, 02:37 PM   #24
djkiwi
Senior Member
 
Join Date: Mar 2010
Posts: 320
Thanks: 87
Thanked 5 times in 5 posts
Default

Hi Matthew, the name is correct. I've also tried different names. If you look at the screenshot in my last message you can see the chart on the left shows sampleATMpln running and the the chart on the right is showing the trade AFTER the sampleATMpnl strategy has placed the order. If the name was incorrect no orders would have been placed. The moment the strategy places the order then I get the message. No other strategies are loaded apart from sampleATMpnl

Here is a screenshot of the strategy name. Everything works fine apart from this unrealized issue. As I said before no problems on futures.

It's got me baffled.

Cheers
DJ
Attached Images
File Type: png TNAtwotargets.PNG (21.1 KB, 5 views)
djkiwi is offline  
Reply With Quote
Old 06-19-2012, 02:39 PM   #25
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
Default

DJ,

Interesting. Would you be able to email me the script with issues to support[at]ninjatrader[dot]com.

Please also include a reference to this thread.
NinjaTrader_Matthew is offline  
Reply With Quote
Old 06-19-2012, 04:16 PM   #26
djkiwi
Senior Member
 
Join Date: Mar 2010
Posts: 320
Thanks: 87
Thanked 5 times in 5 posts
Default

Hi Matthew, all of my scripts have the same issue. I'm guessing that because sampleATMPnl has the same issue means there is some other default setting for equities somewhere on ninjatrader that is a problem. Bear in mind this is an equities only issue not futures. I have never seen this issue once trading futures. I want to bring my equities trading to Ninjatrader now.

Cheers
DJ
djkiwi is offline  
Reply With Quote
Old 06-20-2012, 07:21 AM   #27
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,770
Thanks: 158
Thanked 562 times in 553 posts
Default

DJ,

Can you please send me your database file so I can look into this further.

You can do this by going to the Control Center-> Help-> Mail to Support-> check "Database file"

Please reference this thread in the body of the email
NinjaTrader_Matthew is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting Initial Stop Loss Using ATM Mr_T_Fx Strategy Development 1 08-21-2011 06:30 AM
MOC order if ATM setting not reached? vero-chan ATM Strategies (Discretionary Trading) 1 04-18-2010 01:53 PM
HELp plz. with setting up new ATM......... mdsvtr ATM Strategies (Discretionary Trading) 1 03-11-2010 11:53 AM
Help setting up these ATM Strategys please.... mdsvtr ATM Strategies (Discretionary Trading) 2 03-08-2010 01:07 PM
Re: Setting a trailing stop & ATM Strategy mikesbarrett SuperDOM and other Order Entry Windows 1 06-29-2007 08:57 AM


All times are GMT -6. The time now is 10:53 AM.