Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

"Can not implicitly convert type"

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

    "Can not implicitly convert type"

    I am running into this error when I am trying to enter a stop loss order in OnBarUpdate() and link it to an Entry Order.

    The script that I am using is this:
    Code:
    LongStopA = SetStopLoss("LongEntryA",CalculationMode.Price,SMA(sMAPeriod)[0] - ((High[0]-Low[0])*StopPerc),false);
    At this point I can not figure out what I am doing wrong. Are you able to help me see it?

    Thank you very much

    #2
    Originally posted by jg123 View Post
    I am running into this error when I am trying to enter a stop loss order in OnBarUpdate() and link it to an Entry Order.

    The script that I am using is this:
    Code:
    LongStopA = SetStopLoss("LongEntryA",CalculationMode.Price,SMA(sMAPeriod)[0] - ((High[0]-Low[0])*StopPerc),false);
    At this point I can not figure out what I am doing wrong. Are you able to help me see it?

    Thank you very much
    Typically that type error is because you may not have correctly declared a variable, or you need to change a variable type. For example declared as a double but (trying to be) used as an integer. Somebody else may be able to look at your statement and see the error but the best thing is to look at the statements in the help guide to make sure you have integers or doubles where needed.

    Comment


      #3
      jg123, what would LongStopA be here? The Set's would not have an IOrder return per default to track them...
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Thank you both for your responses.

        LongStopA is in the variables section as:

        Code:
        private IOrder LongStopA;
        I don't see anything else is that bit of code that would be the wrong variable type.
        ---"LongEntryA" is the long entry that is defined immediately previously to this bit of code.
        ---CalculationMode.Price is pretty straightforward
        ---SMA(sMAPeriod)[0] - ( (High[0] - Low[0]) * StopPerc ) comes from the indicator SMA and sMAPeriod has been used in other parts of the code with no problems as well as StopPerc
        --- false is the bool for if it should be a simulated stop or not.

        I am sure that i am missing something incredibly simple. haha thank you for any help that you are able to offer.

        Comment


          #5
          Thanks, but that would not be working due to the fact the the Set() methods do not provide an IOrder return. The return type you get is void / empty and it expects to get an IOrder...

          If you need the IOrder returns, either work with the more advanced Exit methods or custom track the Set()s as shown here - http://www.ninjatrader.com/support/f...ead.php?t=5790
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Great, thank you

            I will take some time to study that and come up with something and get back to you.

            Comment


              #7
              So it looks like in order to accomplish this I need to create an array that will deal with my stop loss order and then do everything under OnOrderUpdate (IOrder).

              Is that correct?

              there is quite a bit in this section that I am not understanding, but I will just go through it step by step and will probably have a lot of questions to ask along the way.

              Comment


                #8
                Also, I do not see an IOrder variable for the stop loss on the sample that you sent. Is that because everything is tracked through the Array?

                Comment


                  #9
                  Correct, as there is no IOrder return for a Set method. If you rather want to work with the familiar IOrder interface, just rework your logic with out the Set()s, but using the Exit() methods, which would carry the IOrder return.
                  Last edited by NinjaTrader_Bertrand; 03-26-2014, 05:52 AM.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Would it be possible for someone to define what is happening in this code. This is an excerpt from the sample code that was suggested in post #5 of this thread - but it is a bit confusing to me.

                    Code:
                    		protected override void OnOrderUpdate(IOrder order)
                    		{
                    			// If OnOrderUpdate() is called from a stop loss or profit target order add it to the appropriate collection
                    			if (order.OrderState == OrderState.PendingSubmit)
                    			{
                    				// Add the "Stop loss" orders to the Stop Loss collection
                    				if (order.Name == "Stop loss")
                    					stopLossOrders.Add(order);
                    				
                    				// Add the "Profit target" orders to the Profit Target collection
                    				else if (order.Name == "Profit target")
                    					profitTargetOrders.Add(order);
                    			}
                    Basically, I do not understand what is happening inside of the ()'s and then the response if the statement is true

                    Comment


                      #11
                      If the OnOrderUpdate is called for an order of name StopLoss or Profit Target (the names the Set's would have) and the order state is PendingSubmit then you record / add the order into your collection for referencing.
                      BertrandNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by burtoninlondon, Today, 12:38 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post burtoninlondon  
                      Started by AaronKoRn, Yesterday, 09:49 PM
                      0 responses
                      12 views
                      0 likes
                      Last Post AaronKoRn  
                      Started by carnitron, Yesterday, 08:42 PM
                      0 responses
                      11 views
                      0 likes
                      Last Post carnitron  
                      Started by strategist007, Yesterday, 07:51 PM
                      0 responses
                      13 views
                      0 likes
                      Last Post strategist007  
                      Started by StockTrader88, 03-06-2021, 08:58 AM
                      44 responses
                      3,982 views
                      3 likes
                      Last Post jhudas88  
                      Working...
                      X