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

bool longTradeOk / What´s wrong here?

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

    bool longTradeOk / What´s wrong here?

    Hi,
    the only thing i want to do is to avoid a new Trade after realizied 8 Ticks profit, in the same direction.
    Maybe, it sounds a little bit funny:but i want only to take some profit at the turning points and then wait for another turnarond and so on.

    Can somebody help me to realize this plan.

    Thanks for supporting me.
    Attached Files

    #2
    Hello Deogenes,
    You can compare the total long trades and total short trades taken by the strategy and then place the trades accordingly. A rough idea will be like
    Code:
    if (this.Performance.LongTrades.Count >= this.Performance.ShortTrades.Count)
    {
    	//take short trade only
    }
    else if (this.Performance.LongTrades.Count < this.Performance.ShortTrades.Count)
    {
    	//take long trade only
    }



    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Hello Joydeep, thank you for support

      your idea sonds absolutely logical and it is the nearest i´ve ever read. But even i do a lot of things wrong, look at that: Can you help me out?

      [ private bool LongTrades = true;
      private bool ShortTrades = true;
      private int target = 8 ;

      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the strategy and is called once before any strategy method is called.
      /// </summary>
      protected override void Initialize()
      {
      //SetProfitTarget("buy", CalculationMode.Ticks, 8);
      //SetProfitTarget("sell", CalculationMode.Ticks, 8);

      CalculateOnBarClose = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (this.Performance.LongTrades.Count < this.Performance.ShortTrades.Count)
      {
      If( Close[0] > SuperTrend(10, 0.5, true).UpTrend[0]);
      EnterLong(DefaultQuantity, "buy");
      SetProfitTarget("buy", CalculationMode.Ticks, 8);
      LongTrades = true;
      ShortTrades = false;
      }
      else if(this.Performance.LongTrades.Count>=this.Perform ance.ShortTrades.Count)
      {
      If (Close[0] < SuperTrend(10, 0.5, true).DownTrend[0]);

      EnterShort(DefaultQuantity, "sell");
      SetProfitTarget("sell", CalculationMode.Ticks, 8);
      LongTrades = false;
      ShortTrades = true;

      }

      #region Properties
      #endregion
      }
      }
      ]

      Comment


        #4
        protected override void OnBarUpdate()
        {
        // Condition set 1
        if (longTradeOk && Close[0] > SuperTrend(10, 0.5, true).UpTrend[0])
        {
        EnterLong(DefaultQuantity, "buy");
        SetProfitTarget("buy", CalculationMode.Ticks, 8);
        longTradeOk = false;
        shortTradeOk = true;
        }
        else if(shortTradeOk && Close[0] < SuperTrend(10, 0.5, true).DownTrend[0])
        { EnterShort(DefaultQuantity, "sell");
        SetProfitTarget("sell", CalculationMode.Ticks, 8);
        longTradeOk = true;
        shortTradeOk = false;
        }

        Comment


          #5
          Great, sledge !!

          I´ am so happy that this thing lately works like i wanted.
          Thank you very much. I would offer you a glass of wine - if i could.
          Thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by hazylizard, Today, 08:38 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by geddyisodin, Today, 05:20 AM
          2 responses
          16 views
          0 likes
          Last Post geddyisodin  
          Started by Max238, Today, 01:28 AM
          5 responses
          44 views
          0 likes
          Last Post Max238
          by Max238
           
          Started by giulyko00, Yesterday, 12:03 PM
          3 responses
          13 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by habeebft, Today, 07:27 AM
          1 response
          16 views
          0 likes
          Last Post NinjaTrader_ChristopherS  
          Working...
          X