Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Referencing Entry Bar

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

    Referencing Entry Bar

    Hello,

    I am trying to strictly use the wizard as my programming is quite weak, but I believe I will have to unlock and get into iOrders to accomplish this task. I hope someone can point me in the right direction.

    I'd like to store the high/low price of my entryBar and reference it as a stop loss. For example, set a stop loss at a tick below entry bar low (and keep it there) until it hits or an exit is called.

    Thanks for any help with this..

    #2
    Jander, thanks for the post - our NinjaScript support trainee will review and get back to you.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hello Jander,

      Thanks for your note.

      Yes, this is something you will have to unlock your code and modify to get working.

      While saving the High/Low to a variable is indeed possible with the Strategy Wizard, the Stop Loss and Profit Targets are set by the wizard when the strategy is initialized and wouldn't be able to reference the variable.

      In the code, if you moved the line:
      "SetStopLoss("", CalculationMode.Price, Variable1, false);"

      From the Initialize() function to the OnBarUpdate() function, under the line:
      Variable1 = Low[0];

      Would set the Stop Loss to the entry bar low price. Any trades would need to be done after this point.

      I have attached a sample wizard created strategy, which i edited to demonstrate what I mean.

      Below I've added a link to a forum post that goes over setting the Stop Loss and Profit Target in NinjaScripts.
      http://www.ninjatrader.com/support/f...ead.php?t=3222

      If you have limited time or programming capabilities, you can discuss your requirements with any of our certified NinjaScript consultants.
      Click here for a list of certified NinjaScript Consultants
      Attached Files
      Last edited by NinjaTrader_ChelseaB; 01-31-2013, 09:52 AM.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Thank you for the help.

        I am confused about how to keep the stopLoss at the right point if I put that variable assignment inside the OnBarUpdate ?

        For Instance, something like:

        Variable1 = Low[0] - 1 * TickSize;
        "SetStopLoss("", CalculationMode.Price, Variable1, false);"

        Does the SetStopLoss only run once immediately following entry, even inside the OnBarUpdate?

        Comment


          #5
          Hello Jander,

          Thank you for your note.

          Variable1 = Low[0] - 1 * TickSize;
          "SetStopLoss("", CalculationMode.Price, Variable1, false);"
          With that code the stop loss would indeed be updated after every OnBarUpdate() call.

          In my example i use the following code:

          if (High[0] > Low[0] && Position.MarketPosition == MarketPosition.Flat)
          {
          Variable0 = High[0];
          Variable1 = Low[0];
          SetStopLoss("", CalculationMode.Price, Variable1, false);
          EnterLong(1, "");
          }

          What this does is it checks if the high is higher than the low for my entry condition. This is almost always true.

          Then it checks to see if the position is flat. This is so the SetStopLoss will only be set when the conditions for entry are met. After entering a position the code will not run until the position is flat again.

          Next it sets the high and low current bar values to variables.
          Then sets the stop loss to Variable1 which is the low value.
          Last it enters the trade with an EnterLong();
          Last edited by NinjaTrader_ChelseaB; 01-31-2013, 10:53 AM.
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by sidlercom80, 11-25-2021, 06:38 AM
          2 responses
          46 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by traderhawk, Today, 05:53 AM
          1 response
          23 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by ezrollin, Yesterday, 11:26 PM
          1 response
          42 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by ezrollin, Yesterday, 09:10 PM
          1 response
          52 views
          0 likes
          Last Post NinjaTrader_PaulH  
          Started by Angus7, Today, 04:31 AM
          8 responses
          59 views
          0 likes
          Last Post Angus7
          by Angus7
           
          Working...
          X