Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with my first strategy

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

    Help with my first strategy

    I’m trying to code my first strategy and I’m stuck on a couple of issues.

    Issue #1 – all of my signals line up and it gets in a short, hard target hits then it takes another one max loss. So my questions is, how do I code it to only take a another short after a long signal has printed.

    Issue #2 – when it enters a trade I want to put a limit order in on a SMA. But the problem I’m having is that it moves the order with the SMA. How can this be fixed?

    #2
    Hello EvilHong,

    Welcome to the NinjaTrader forums here. For item #1 this could be set by the sequences you define, commonly using either bool flags or UserVariables. That link will take you to a sample that uses uservariables to create sequences.

    For item #2 if you want to fix the price of your order to the indicator value at the time of entry, you could work with BarsSinceEntry() in the index value or "bars ago" value for the indicator.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      another question

      I have another question

      I’m trying to write a simpler code than before just to get it to work but I’m running into the same problem. When 2 SMA’s cross I want to set the target on the 40 SMA but it get’s out at the same price I just bought at.


      Any ideas?

      protectedoverridevoid OnOrderUpdate(IOrder order){
      DrawText(order.Token,
      "--",0,order.AvgFillPrice,Color.Red);
      }
      protectedoverridevoid OnBarUpdate()
      {
      // Condition set 1
      EntryHandling = EntryHandling.UniqueEntries;
      if (Position.MarketPosition != MarketPosition.Flat) return;
      if (CrossBelow(SMA(Fast), SMA(Slow), 1))
      {

      SetProfitTarget(SMA(
      40)[0]);
      EnterLong(DefaultQuantity,
      "");

      }
      Attached Files

      Comment


        #4
        It's likely a marketable limit order.

        To protect long position with SetProfitTarget, the strategy will submit a Sell Limit order.

        If SMA(40) is below the last traded price, then this order is considered marketable and you are filled right away.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Thanks Ryan,

          is there any way to fix that?

          Comment


            #6
            Yes, you could make checks against all these values before setting the value of your target. What is happening essentially is you're using the wrong order type -- using a limit order when a stop may be more appropriate.

            There's unfortunately not one answer here as it depends what you want to do. First step is to break down what outcome you want to see happen here. Like in cases where your strategy would submit this marketable limit order - would you want a stop loss order at your SMA(40) value? Would you want your target order at static value?
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ScottW, Today, 06:09 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by ScottWalsh, Today, 06:52 PM
            1 response
            5 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by ftsc2022, 10-25-2022, 12:03 PM
            5 responses
            256 views
            0 likes
            Last Post KeyonMatthews  
            Started by Board game geek, 10-29-2023, 12:00 PM
            14 responses
            244 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Waxavi, 04-19-2024, 02:10 AM
            4 responses
            56 views
            0 likes
            Last Post sonia0101  
            Working...
            X