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

sell prior high

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

    sell prior high

    Hi,
    I'm trying to buy a specific percentage point below the high of the day, using current day OHL indicator which works fine, but I'm also trying to sell at the high of day that occured prior to my entry. I've tried setting the prior high as a variable (priorHigh = CurrentDayOHL1.CurrentHigh[0]) but this doesn't work, presumably since that value is always changing as new highs happen. What's a good way to save the high prior to my entry and use it as an exit point?
    thanks,
    David

    #2
    Hello trader3000a,

    Is this variable being assigned from the same condition set that submits the order?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      no, it's in it's own set

      PriorHIgh = 0;
      }
      else if (State == State.Configure)
      {
      }
      else if (State == State.DataLoaded)
      {
      CurrentDayOHL1 = CurrentDayOHL(Close);
      SetStopLoss("", CalculationMode.Ticks, StopTicks, false);
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      // Set 1
      if (Position.MarketPosition == MarketPosition.Flat)
      {
      PriorHIgh = 0;
      }

      if (CurrentBars[0] < 1)
      return;

      // Set 2
      if (Position.MarketPosition == MarketPosition.Long)
      {
      PriorHIgh = CurrentDayOHL1.CurrentHigh[0];
      }

      // Set 3
      if (Position.MarketPosition == MarketPosition.Long)
      {
      ExitLongLimit(Convert.ToInt32(DefaultQuantity), PriorHIgh, "", "");
      }

      // Set 4
      if (Times[0][0].TimeOfDay >= new TimeSpan(10, 0, 0))
      {
      EnterLong(Convert.ToInt32(DefaultQuantity), "");
      }

      Comment


        #4
        Hello trader3000a,

        You want to save the value when the entry is submitted, correct?

        Set the variable from the condition set that submits the entry.

        Print the variable and the time of the bar to confirm the value.
        https://ninjatrader.com/support/foru...121#post791121
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          got it, thx Chelsea, I'll give it a go

          Comment


            #6
            still can't get it happening. weird results. have a look if you can ?
            Attached Files

            Comment


              #7
              Hello trader3000a,

              Are wanting to put multiple entries in a direction? Are you checking the position is flat before placing a new entry and saving this value?

              Please save the output from the prints and trace orders in the NinjaScript Output window to a text file and include this with your reply.

              I am happy to assist with analyzing the debugging output.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Without boring you with too many parameters, I simply want to buy a close below the HOD and sell at the HOD. Is there an easier way? It seems like the variable won't stick once price rises above it.
                Attached Files
                Last edited by trader3000a; 05-16-2022, 02:44 PM.

                Comment


                  #9
                  Hello trader3000a,

                  It is very helpful to put a label before each value printed to know what is being printed and how this is being compared.

                  What are you printing? Are you printing the variable only?

                  Is this the output?
                  3887.25
                  3917.75

                  Is the variable being printed, then being changed, then being printed again?

                  Previously you were attempting to save the current day high at the moment an entry is being submitted. Is this no longer what you are wanting to achieve? Is this a new script?
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kaywai, Yesterday, 11:36 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post kaywai
                  by kaywai
                   
                  Started by Havencapital, Yesterday, 11:27 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post Havencapital  
                  Started by AdeptistJune, Yesterday, 10:00 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post AdeptistJune  
                  Started by Genesis2021, Yesterday, 04:13 PM
                  1 response
                  26 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by tonystarks, Yesterday, 05:00 PM
                  2 responses
                  11 views
                  0 likes
                  Last Post tonystarks  
                  Working...
                  X