• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


Auto Price change

  • Filter
  • Time
  • Show
Clear All
new posts

    Auto Price change

    Hello Ninja Team,

    I am trying to improve my strategy by adding a new condition but I am not sure if it is even possible. So here is the condition logic:
    I always set fixed entry price manually and I want my strategy to enter at the same level all the time, however in the cases like this(please see explanation below) i want to readjust my initial entry price:
    Lets say my initial entry price was 2790 however price came to 2792 and bounced back where I missed my entry because price reversed 2 points away from my fixed entry price. So now I want to build a logic that if price will be within 5 points range from my entry price and if it does not reach my entry price within 2 15mins bar and I want my entry price to be readjusted 1 point up from the low of those 2 15mins candle.

    private double entryPrice = 2790; // this is my original entry price

    private double entryPriceAdjusted = 2795; // this is where price will go below 2795 and if price dont reach 2790 within 30mins (which is 2 15mins bar), I want to readjust my entry price to the low of 30mins again which 2 15 mins bar. lets say low of last 30mins was 2792 and I want my entry price to be readjusted to 2793 automatically when price comes back after 2 15mins candle close. However, if price gets executed within 30mins I want above logic to be not triggered at all. Also, I want to make sure when price is readjusted by meeting above condition, I want my initial entryPrice not to be triggered anymore in case next time price goes down.

    I would really appreciate if you could please write a sample educational code for me to implement above logic.
    Last edited by Bobisam; 03-27-2019, 07:59 PM.

    Hello Bobisam,

    Thanks for your post.

    Please note that we do not provide coding or debugging services. Asking for an educational example that demonstrates your specific example coding needs is outside of our support as it would be providing coding services.

    As this is your strategy you would need to code your strategy. If you are not able to code your strategy one option is to seek a 3rd party coder who could meet your needs and we would be able to provide links to these service providers if requested.

    The entry price can be obtained from Position.AveragePrice: https://ninjatrader.com/support/help...erageprice.htm

    You can count bars a couple of ways, either using an integer counter and incrementing it for each 15 minute bar after your trigger condition or saving the current bar number into an integer variable and then checking to see if the CurrentBar minus the savedBar == 2.

    To control the logic, you would want to use bool variables that are either true or false. Even though you are using NT8, this educational reference from NinjaTrader7 is applicable and will help illustrate: https://ninjatrader.com/support/help...g_concepts.htm

    Another reference to further help you programming wise is any C# on-line tutorial, such as http://li153-236.members.linode.com/...harp/index.php
    Paul H.NinjaTrader Customer Service


      Thanks Paul. I can take care of coding part if I understand what methods or ninjascript built in conditions to use. After reviewing I believe Position.AveragePrice only works if I have position already. However, in my case there is not position entered yet. What method or built in conditions I can use to reproduce following steps? Change my entryPrice from price $10 to $13 without having pending/accepted etc. order or position? I am trying to set the price range for ex: if the lowest low of last 3 bars above $2 from my entryPrice then change my entry price to the lowest low of last 3 bars above $1. This is what I am doing to achieve that

      private double entryPrice = 10;
      private bool adjustedPrice;
      adjustedPrice = (LowestBar(Low, 3) >= (entryPrice + 2)); // please let me know if this logic can identify that lowest low of last 3 bars away $2 from my initial entryPrice(which does not have open order or positions because price didnot reach my entryPrice)

      //if adjustedPrice true then change my entryPrice to 1$ above from the lowest low of last 3 candles for me to enter when price comes back later, basically my entryPrice should be adjusted based on adjustedPrice

      here I am not sure what to say to change my initial entryPrice(again no position or order yet) to adjustedPrice
      I want to change my double variable which I declared above

      Could you please let me know what I can use to code above logic? any reference should fine too. Probably I am not familiar well with ninjascript library and its capabilities yet(but slowly learning), I just need a direction what to use in order to reproduce above logic, the rest I can take care. Thanks again!
      Last edited by Bobisam; 03-28-2019, 10:10 PM.


        Hello Bobisam,

        Thanks for your reply.

        The help guide can be used to find the definitions of the methods. While the help guide mainly provides the ninjascript usage it will still help you to see the definition provided so that you can see what the methods return. In the case of the lowestbar the help guide definition is: "Returns the number of bars ago the lowest price value occurred within the specified look-back period." (reference: https://ninjatrader.com/support/help...?lowestbar.htm). As you are actually looking for the lowest price I would suggest using the MIN() indicator method (reference: https://ninjatrader.com/support/help...inimum_min.htm) which returns: "Returns the lowest value over the specified period.". For this method, you would want to change the input series to be the Low price, change the period to be 3.

        Here is a link to the Ninjascript alphabetical reference which may help you find things quicker: https://ninjatrader.com/support/help..._reference.htm

        You can change your entry price variable in the "actions" section of the set by assigning the new value to it. The variable will be found in the "misc" folder" and will have the word Set in front of it.
        Paul H.NinjaTrader Customer Service


        Latest Posts


        Topics Statistics Last Post
        Started by James Wallace, Today, 10:38 AM
        1 response
        Last Post NinjaTrader_Zachary  
        Started by mtamaku, Today, 10:22 AM
        1 response
        Last Post NinjaTrader_Jim  
        Started by mtamaku, Today, 10:16 AM
        4 responses
        Last Post mtamaku
        by mtamaku
        Started by hedgeplay, Yesterday, 08:04 PM
        1 response
        Last Post NinjaTrader_Kate  
        Started by UltraNIX, Today, 12:31 AM
        6 responses
        Last Post UltraNIX