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

how to update a variable !!

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

    how to update a variable !!

    Hello,
    I created a method to calculate a range. The value of this range is used to calculate the Exit.
    The problem is that the value of the Range does not remain stationary, but varies with each candle. How can I do to make it stay fixed?
    Example:

    # Region OrderRouting //Region to manage the position Long
    private void ManagerOrder ()

    if (Position.MarketPosition == MarketPosition.Long)
    {
    if ( High [0]> Position.AvgPrice + RangeLong () ) the value of the Range is not that calculated when EnterLong, changes each candle
    }




    private double RangeLong () //method to calculate the Range

    return (MAX (HIGH, 5) [0]-MIN (Low, 10) [5]);




    protected override void OnBarUpdate ()
    RangeLong ();
    if (Low [0] <MAX (High, 5) [0] - RangeLong ())
    EnterLong



    If, instead, I try to do this:

    RangeLong () = VariableM
    the value of variableM becomes equal to the value of the Range, remains as the initial default (1).
    How can I do?
    Thanks.
    Hello.
    Roberto

    #2
    Hello Roberto,

    You are working with programming language so there is not just one answer here.

    One approach is using a bool flag to force the calculation only once. You set the bool flag to the opposite of what you check for.

    In your code, it will most likely be simpler to move away from the custom method and capture the value you want after certain conditions.

    Code:
     
    if (Position.MarketPosition == MarketPosition.Long && callOnce)
    {
    double myRangeLong = (MAX (HIGH, 5) [0] - MIN (Low, 10) [5]);
    callOnce = false;
    }
     
    if ( High [0]> Position.AvgPrice + myRangeLong)
    //exit here
     
    if (Position.MarketPosition == MarketPosition.Flat) //resets your bool flag when flat
    callOnce = true;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      thanks RyanM,
      now I try, I'll let you know.
      Ciao.
      Roberto

      Comment


        #4
        Hello RyanM,
        I am attaching the code where I made the changes, the value is always the default (1). and for the profit target for the management of Exit not updated.
        If you can help me I would be grateful because they are blocked by two weeks on this point.
        Thanks.
        Ciao.
        Roberto
        Attached Files

        Comment


          #5
          Roberto, we could unfortunately not code or debug this for you - if you look to get this custom coded for you a certified NinjaScript consultant would be a potential route to choose -

          BertrandNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bortz, 11-06-2023, 08:04 AM
          47 responses
          1,607 views
          0 likes
          Last Post aligator  
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          9 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          19 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          6 views
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          15 views
          0 likes
          Last Post Javierw.ok  
          Working...
          X