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

Auto Price change

Collapse
X
 
  • 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.

    #2
    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

    Comment


      #3
      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){
      //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.

      Comment


        #4
        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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by mgco4you, Today, 09:46 PM
        1 response
        3 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by wzgy0920, Today, 09:53 PM
        0 responses
        3 views
        0 likes
        Last Post wzgy0920  
        Started by Rapine Heihei, Today, 08:19 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        6 views
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X