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 TraderJA, Today, 12:06 AM
          0 responses
          3 views
          0 likes
          Last Post TraderJA  
          Started by SnailHorn, Yesterday, 10:49 PM
          0 responses
          7 views
          0 likes
          Last Post SnailHorn  
          Started by naanku, Yesterday, 07:25 PM
          0 responses
          8 views
          0 likes
          Last Post naanku
          by naanku
           
          Started by milfocs, Yesterday, 07:23 PM
          0 responses
          6 views
          0 likes
          Last Post milfocs
          by milfocs
           
          Started by PaulMohn, Yesterday, 06:59 PM
          0 responses
          8 views
          0 likes
          Last Post PaulMohn  
          Working...
          X