Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting ATM Quantities

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    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, 11:22 AM.

    Comment


      #17
      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");
      			}
      MatthewNinjaTrader Product Management

      Comment


        #18
        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 Files

        Comment


          #19
          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.
          MatthewNinjaTrader Product Management

          Comment


            #20
            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 Files

            Comment


              #21
              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
              MatthewNinjaTrader Product Management

              Comment


                #22
                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 Files
                Last edited by djkiwi; 06-19-2012, 01:25 PM.

                Comment


                  #23
                  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?
                  MatthewNinjaTrader Product Management

                  Comment


                    #24
                    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 Files

                    Comment


                      #25
                      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.
                      MatthewNinjaTrader Product Management

                      Comment


                        #26
                        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

                        Comment


                          #27
                          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
                          MatthewNinjaTrader Product Management

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Rogers101, 05-05-2024, 11:30 AM
                          8 responses
                          31 views
                          0 likes
                          Last Post Rogers101  
                          Started by llanqui, Today, 07:04 AM
                          1 response
                          5 views
                          0 likes
                          Last Post NinjaTrader_BrandonH  
                          Started by cmtjoancolmenero, 04-25-2024, 03:58 PM
                          20 responses
                          114 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by knowmad, Today, 03:52 AM
                          1 response
                          20 views
                          0 likes
                          Last Post NinjaTrader_ChelseaB  
                          Started by llanqui, Yesterday, 03:51 PM
                          5 responses
                          23 views
                          0 likes
                          Last Post NinjaTrader_Gaby  
                          Working...
                          X