Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reference a custom value

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

    #16
    If you have no need to process it over and over just add a filter to it.

    Code:
    if (CurrentBar == 0)
    {
         // do something;
    }
    Josh P.NinjaTrader Customer Service

    Comment


      #17
      yes, which goes back to what we were talking about early in the thread.

      you only want to call the SetProfitTarget in 2 different cases.

      1. When you first enter.
      2. If the Swing value changes your target point.

      you have to code this if you don't want it to be calculated each new bar; i agree, you don't
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #18
        hi josh thanks for tuning in.
        hmmm.. maybe I should use another approach then swing indicator for this?

        Unfortunately I still cant get this to work. In my other trading software it's so easy to realize this:

        Code:
        //HILO SWING
        HiHi = Highest(High, 10);
        LoLo = Lowest(Low, 10);
        
        //First Exit Target
        If Marketpositionlong and CurrentContracts=4 then Exitlong ("TakeProfit") 2 Contracts at (Entryprice+(Entryprice-LoLo)) Limit;
        If MarketpositionShort and CurrentContracts=4 then Cover ("TakeProfit") 2 Contracts at (Entryprice-(Hihi-Entryprice)) Limit;
        I am really confused with all the scale in and scale out routines necessary to do this.

        Is there no other possibility??

        Comment


          #19
          Phaseshifter,

          Maybe this reference sample will help you. http://www.ninjatrader-support2.com/...ead.php?t=3751
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            yeah this might help.
            I now have it this way:

            Code:
                 
            
                    #region Variables
                    // Wizard generated variables
                    private int Swingbars = 5; // Default setting for MyInput0
                    // User defined variables (add any user defined variables below)
                    private double TarDis;
            
                   protected override void Initialize()
                    {
                         CalculateOnBarClose = true;    
                        EntriesPerDirection = 1;
                        EntryHandling         = EntryHandling.UniqueEntries;
                        SetProfitTarget("Long1", CalculationMode.Ticks, TarDis);
                        SetProfitTarget("Short1", CalculationMode.Ticks, TarDis);
                    }
            
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                        // ENTER LONG #1
                        if (Close[0] > Open[0])
                        {
                            EnterLongStop(2, High[0] + 1 * TickSize, "Long1");
                            EnterLongStop(2, High[0] + 1 * TickSize, "Long2");
                        }
            
                        // ENTER SHORT #1
                        if (Close[0] < Close[0])
                        {
                            EnterShortStop(2, Low[0] -1 * TickSize, "Short1");
                            EnterShortStop(2, Low[0] -1 * TickSize, "Short2");
                        }
            
                           // PROFIT TARGET LONG
                        
                        if (Position.MarketPosition == MarketPosition.Long)
                        {
                            TarDis=((Position.AvgPrice-(Swing(Swingbars).SwingLow[0]))/TickSize);
                        }
                        
                           // PROFIT TARGET SHORT
                        if (Position.MarketPosition == MarketPosition.Short)
                        {
                            TarDis=(((Swing(Swingbars).SwingHigh[0])-Position.AvgPrice)/TickSize);
                        }
            The problem now is variable "TarDis" seems to be always=0.
            Position Target Profit is immediately reached and it exits.

            Where is my problem in calucating the Profit Distance?

            Comment


              #21
              wrong logic,

              no actual target is defined.

              Comment


                #22
                You want to move Set() into OnBarUpdate() and just call them when you want to update their values. From Initialize() they are not updated.
                Josh P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                558 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                324 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                101 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                545 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                547 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X