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 Rapine Heihei, Today, 08:19 PM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Rapine Heihei, Today, 08:25 PM
          0 responses
          4 views
          0 likes
          Last Post Rapine Heihei  
          Started by f.saeidi, Today, 08:01 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by Rapine Heihei, Today, 07:51 PM
          0 responses
          6 views
          0 likes
          Last Post Rapine Heihei  
          Started by frslvr, 04-11-2024, 07:26 AM
          5 responses
          96 views
          1 like
          Last Post caryc123  
          Working...
          X