Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

update Variables

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

    update Variables

    Hello. I created a region for the order management Long / Short called: ManagerOrder().
    The variables double myRangeLong and double my RangeShort, are used to determine the Exit. The Long part works fine, while the Short, opens and closes the position on the same bar. If, however, use only the code for the Short is okay.
    Ciao
    Roberto


    Code:
    # region OrderRouting
    private void ManagerOrder ()
    {
    if (Position.MarketPosition == MarketPosition.Long && callOnce )
    double myRangeLong = (MAX (HIGH, 3) [0]-MIN (Low, 10) [1]);
    callOnce = false; // OK
    }

    {
    if ( High [0]> (Position.AvgPrice +myRangeLong * 0.5)// myRangeLong OK
    SetStopLoss (CalculationMode.Price, Position.AvgPrice);
    }

    if (Position.MarketPosition == MarketPosition.Short && callOnceB )
    double myRangeShort = ((MIN (Low, 2) [0] - MAX (H, 10) [2]) *- 1);
    callOnceB = false;//if the position is short the variable is true instead of false Why?

    {
    if ( Low [0]< (Position.AvgPrice - myRangeShort * 0.5)//myRangeShort not update. It remains default ( 1 ).
    SetStopLoss (CalculationMode.Price, Position.AvgPrice);
    }


    protected override void OnBarUpdate ()

    if (Position.MarketPosition == MarketPosition.Flat)
    callOnce = true;
    if (Position.MarketPosition == MarketPosition.Flat)
    callOnceB = true;


    ManagerOrder ();

    if (Position.MarketPosition! = MarketPosition.Flat) return;

    / / Long
    Etc. ....

    / / Short
    Etc. ...

    #2
    Hello,

    This code below has perenthesis order issues. Please check all our parenthises.

    private void ManagerOrder ()
    {
    if (Position.MarketPosition == MarketPosition.Long && callOnce )
    double myRangeLong = (MAX (HIGH, 3) [0]-MIN (Low, 10) [1]);
    callOnce = false; // OK
    }

    BRETT: This parenthises closes off private void ManagerOrder(), I believe you intended this to close out your if statement however.


    {
    if ( High [0]> (Position.AvgPrice +myRangeLong * 0.5)// myRangeLong OK
    SetStopLoss (CalculationMode.Price, Position.AvgPrice);
    }

    if (Position.MarketPosition == MarketPosition.Short && callOnceB )
    double myRangeShort = ((MIN (Low, 2) [0] - MAX (H, 10) [2]) *- 1);
    callOnceB = false;//if the position is short the variable is true instead of false Why?

    {
    if ( Low [0]< (Position.AvgPrice - myRangeShort * 0.5)//myRangeShort not update. It remains default ( 1 ).
    SetStopLoss (CalculationMode.Price, Position.AvgPrice);
    }
    BrettNinjaTrader Product Management

    Comment


      #3
      Hello Brett,
      I tried as you said, but the problem remains , they work well only Long.

      Code:
      # region OrderRouting
      private void ManagerOrder ()
      {
      {

      if (Position.MarketPosition == MarketPosition.Long && callOnce )
      double myRangeLong = (MAX (HIGH, 3) [0]-MIN (Low, 10) [1]);
      callOnce = false; // OK
      }

      } // The problem remains.

      {
      if ( High [0]> (Position.AvgPrice +myRangeLong * 0.5)// myRangeLong OK
      SetStopLoss (CalculationMode.Price, Position.AvgPrice);
      }

      if (Position.MarketPosition == MarketPosition.Short && callOnceB )
      double myRangeShort = ((MIN (Low, 2) [0] - MAX (H, 10) [2]) *- 1);
      callOnceB = false;//if the position is short the variable is true instead of false Why?

      {
      if ( Low [0]< (Position.AvgPrice - myRangeShort * 0.5)//myRangeShort not update. It remains default ( 1 ).
      SetStopLoss (CalculationMode.Price, Position.AvgPrice);
      }


      protected override void OnBarUpdate ()

      if (Position.MarketPosition == MarketPosition.Flat)
      callOnce = true;
      if (Position.MarketPosition == MarketPosition.Flat)
      callOnceB = true;


      ManagerOrder ();

      if (Position.MarketPosition! = MarketPosition.Flat) return;

      / / Long
      Etc. ....

      / / Short
      Etc. ...

      Comment


        #4
        Hello,

        You still have major parenthesis issues.This is more basic coding. The Parenetheses you added ended ManagerOrder() to early. Please see my below changes. I'm unsure if this will effect your short order but we need to get this handled first.

        private void ManagerOrder ()
        {


        if (Position.MarketPosition == MarketPosition.Long && callOnce )
        {
        double myRangeLong = (MAX (HIGH, 3) [0]-MIN (Low, 10) [1]);
        callOnce = false; // OK
        }



        if ( High [0]> (Position.AvgPrice +myRangeLong * 0.5)// myRangeLong OK
        {
        SetStopLoss (CalculationMode.Price, Position.AvgPrice);
        }

        if (Position.MarketPosition == MarketPosition.Short && callOnceB )
        {
        double myRangeShort = ((MIN (Low, 2) [0] - MAX (H, 10) [2]) *- 1);
        callOnceB = false;//if the position is short the variable is true instead of false Why?
        }

        if ( Low [0]< (Position.AvgPrice - myRangeShort * 0.5)//myRangeShort not update. It remains default ( 1 ).
        {
        SetStopLoss (CalculationMode.Price, Position.AvgPrice);
        }


        }
        BrettNinjaTrader Product Management

        Comment


          #5
          Thanks Brett

          Thanks Brett,
          Thank you to aid me always. Everything is OK with the code.
          Merry Christmas

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          666 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          377 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          110 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          575 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          580 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X