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

user variable in strategy wizard

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

    user variable in strategy wizard

    Hi guys,
    I am new to the forum and just starting to get familiar with strategy wizard and ninja's editor.
    I have defined the following inputs:
    n= number of lookback bars
    bx= percentage multiplier of range

    I've then defined variable0 as being the Range over the last n bars using the indicator "Range".

    I would like to buy when the current price (c) crosses over c+bx*variable0

    How can I define in the wizard a new variable1=c+bx*variable0?

    If not possible from the wizard what would be the correct syntax to define this variable on the editor?

    thanks,
    Giovanni

    #2
    Hi Giovanni,

    Thanks for your post.

    The math needed for this cannot be down with the Strategy Wizard, so this must be hand coded in the code editor.

    You mention "I would like to buy when the current price (c) crosses over c+bx*variable0"

    If c is the close price, it would seem unlikely that the close price could cross over a higher number if this is calculated and re-saved on each bar.

    Are you wanting to save the value of c+bx*variable0 on the first bar (or another previous bar) to be compared with later?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      OK I made some confusion:It is probably easier to start from scratch and explain exactly the strategy I am trying to code:

      BRange= the price range over the last n bars=the highest high of the last n bars (including the current bar) minus the lowest low of the last n bars (including the current bar)
      n= number of lookback bars
      bx= percentage multiplier of the BRange
      c=current price
      buyCh= c+ bx* Brange
      enter long position if next bar higher than buyCh


      tks
      Last edited by balucang; 11-24-2013, 08:56 AM.

      Comment


        #4
        Hello balucang,

        It sounds like you want something like the following:

        Code:
        int n = 10;
        double brange = 0;
        double bx = 1.5;
        double buych = 0;
        protected override void OnBarUpdate()
        {
        if (Close[0] > buych)
        EnterLong();
        
        brange = MAX(Close, n)[0] - MIN(Close, n)[0];
        buych = Close[0]+bx*brange;
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          ok tks for your help

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          32 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by stafe, 04-15-2024, 08:34 PM
          7 responses
          32 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by merzo, 06-25-2023, 02:19 AM
          10 responses
          823 views
          1 like
          Last Post NinjaTrader_ChristopherJ  
          Started by frankthearm, Today, 09:08 AM
          5 responses
          21 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Started by jeronymite, 04-12-2024, 04:26 PM
          3 responses
          43 views
          0 likes
          Last Post jeronymite  
          Working...
          X