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 usazencort, Today, 01:16 AM
          0 responses
          1 view
          0 likes
          Last Post usazencort  
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          603 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          22 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          21 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          230 views
          0 likes
          Last Post TradingLoss  
          Working...
          X