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

Draw at Entry Point

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

    Draw at Entry Point

    I am trying to draw a dot at my entry point that represents my SetStopLoss immediately. However, it is drawing a dot at every point my entry condition is met. Find the code below. Thank you in advance for the help.

    Code:
    			// Long Entry Conditions
                if (Close[0] >= DonchianChannelATR(EntryPeriod).UpperLine[1]) // Enter long position if close is >= given high
                {
                    EnterLong((int)oneUnit, "LongPosition1");
    			// Long Exit Conditions	
    				SetStopLoss("LongPosition1", CalculationMode.Price, (int)trailingLongStopATR, true);
    				DrawDot(CurrentBar.ToString(), true, 0, trailingLongStopATR, Color.Yellow);

    #2
    Hello cfree5119,
    Thanks for writing in and I am happy to assist you.

    Please draw the dot from OnOrderUpdate and also make sure you are using an unique tag id like:
    Code:
    protected override void OnOrderUpdate(IOrder order)
    {
    			if (order.Name == "Stop loss") DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow);
    Please let me know if I can assist you any further.
    Last edited by NinjaTrader_Joydeep; 02-21-2012, 11:15 AM.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      This places a dot at the correct bar but does not place the dot on the y-axis value that I specified earlier, trailingLongStopATR. The x-axis is correct though.
      Last edited by cfree5119; 02-21-2012, 11:54 AM.

      Comment


        #4
        Hello cfree5119,
        In the sample code I have used the stop price. Please modify the code accordingly as per your need.

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          However, the stop price does not reside at the stop price but at 0. See the attached image.
          The sample code you gave me and I modified looks like this. I want the dot placed at my stoploss previously coded.

          Code:
          			// Long Entry Conditions
                      if (Close[0] >= DonchianChannelATR(EntryPeriod).UpperLine[1]) // Enter long position if close is >= given high
                      {
                          EnterLong((int)oneUnit, "LongPosition1");
          			// Long Exit Conditions	
          				SetStopLoss("LongPosition1", CalculationMode.Price, (int)trailingLongStopATR, true);
                      }
          			if (Close[0] <= DonchianChannelATR(ExitPeriod).LowerLine[1]) // Exit Long position if close <= given low
          			{
          				ExitLong();
          			}
                  }
          		
          		protected override void OnOrderUpdate(IOrder order)
          		{
          			if (order.Name == "LongPosition1") DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow);
          		}
          Attached Files

          Comment


            #6
            Hello cfree5119,
            You have set the Calculation mode as Price while have used an integer as the value. Please debug your code using the Print function and see whether the stop price is the value as per your desire http://www.ninjatrader.com/support/h...html?print.htm

            For more on debugging please refer here http://www.ninjatrader.com/support/f...d.php?t=3418as

            Please let me know if I can assist you any further.
            JoydeepNinjaTrader Customer Service

            Comment


              #7
              I have fixed that mistake yet the code you wrote is still yielding zero. Also, the print function shows my my desired value. Forgive me for my lack of programming experience. I am using the the string "LongPosition1" in the draw code that is both associated with my long entry and StopLoss. I can't think of anything else to try.

              Comment


                #8
                Hello cfree5119,
                If you set the stop order as simulated then OnOrderUpdate will not be triggered as the order is not real. Set the same to false.
                Also the order name will be Stop loss. Please find the below rectified code.

                Code:
                	// Long Entry Conditions
                 if (Close[0] >= DonchianChannelATR(EntryPeriod).UpperLine[1]) // Enter long position if close is >= given high
                {
                       	EnterLong((int)oneUnit, "LongPosition1");
                	// Long Exit Conditions	
                	SetStopLoss("LongPosition1", CalculationMode.Price, (int)trailingLongStopATR, [B][COLOR="Blue"]false[/COLOR][/B]);
                }
                if (Close[0] <= DonchianChannelATR(ExitPeriod).LowerLine[1]) // Exit Long position if close <= given low
                {
                	ExitLong();
                }
                 
                		
                protected override void OnOrderUpdate(IOrder order)
                {
                	if (order.Name == "[COLOR="blue"][B]Stop loss[/B][/COLOR]") DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow);
                }
                Please let me know if I can assist you any further.
                JoydeepNinjaTrader Customer Service

                Comment


                  #9
                  Thank you. This works well now as far as the y-value is concerned. Now the dot is being plotted where the instrument is exited opposed to my original plan of wanting the dot plotted upon entry.

                  Comment


                    #10
                    Hello cfree5119,
                    Glad its working.

                    Have you set the simulated to false (in SetStopLoss(...))? If set thus, the dot will be drawn when the entry is filled itself.

                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      I made the corrections you suggested. Here is the updated code below. I would prefer to have the dot placed upon the long position entering not exiting. Also, see the screenshot to visualize what I am speaking of.

                      Code:
                      			// Long Conditions
                                  if (Close[0] >= DonchianChannelATR(EntryPeriod).UpperLine[1]) // Enter long position if close is >= given high
                                  {
                                      EnterLong((int)oneUnit, "LongPosition1");
                      				SetStopLoss("LongPosition1", CalculationMode.Price, trailingLongStopATR, false);
                                  }
                      			
                      			if (Close[0] <= DonchianChannelATR(ExitPeriod).LowerLine[1]) // Exit Long position if close <= given low
                      			{
                      				ExitLong();
                      			}
                              }
                      		
                      		protected override void OnOrderUpdate(IOrder order)
                      		{
                      			if (order.Name == "Stop loss") DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow);
                      		}
                      Attached Files

                      Comment


                        #12
                        Hello cfree5119,
                        The dot is drawn when the entry was made. But it is subsequently changed when the stop is getting filled/cancelled upon exit since the tag name is the same.

                        Add an additional check to make sure the dot is drawn on the entry bar only.
                        Code:
                        if (order.Name == "Stop loss" && BarsSinceEntry("LongPosition1") == 0) DrawDot(order.OrderId, true, 0, order.StopPrice, Color.Yellow);
                        Please let me know if I can assist you any further.
                        JoydeepNinjaTrader Customer Service

                        Comment


                          #13
                          I see, easy enough. Let say I wanted to draw a line wherever the dynamically changing stop is. Would it be best to use a plot function for this or draw a line from the entry and exit? The stop will only change upon another entry that scales in. Thanks again for the wonderful help.

                          Comment


                            #14
                            Hello cfree5119,
                            You can use a Plot for the purpose or a line. Both has their own pros and cons and it depends on what exactly you want to do.

                            To assign plot values from a strategy please refer to this sample code http://ninjatrader.com/support/forum...ead.php?t=6651

                            Please let me know if I can assist you any further.
                            JoydeepNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by cmtjoancolmenero, Yesterday, 03:58 PM
                            4 responses
                            24 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by Brevo, Today, 01:45 AM
                            1 response
                            14 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by rjbtrade1, 11-30-2023, 04:38 PM
                            2 responses
                            74 views
                            0 likes
                            Last Post DavidHP
                            by DavidHP
                             
                            Started by suroot, 04-10-2017, 02:18 AM
                            5 responses
                            3,022 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by Stanfillirenfro, Today, 07:23 AM
                            1 response
                            7 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Working...
                            X