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

Setting up different stoploss for different positions

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

    Setting up different stoploss for different positions

    Hello,
    Is there a way to set up two separate stop loss targers if I enter two different positions as a result of my trading signal. E.g. I have an automated trading strategy and I enter two long ES positions but I want to have different stop losses for both of them, may be 8 ticks for the first one and 4 for the second position.

    Is there a way to accomplish this in NT? I came up with the following code,but it does not seem to work.

    SetStopLoss("Long 1",CalculationMode.Ticks, stoplossticks);
    SetStopLoss("Long 2",CalculationMode.Ticks, stoplossticks);

    Any help??

    #2
    pandyav, that would be the correct approach, are you two entry signals then named accordingly to tie into your stops ("Long1", "Long2")?

    Best would be running the script with TraceOrders enabled to get a more detailed debug assist - http://www.ninjatrader.com/support/f...ead.php?t=3627
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Also make sure when entering the orders that you are selecting the right Signal name.
      e.g. in your case "Long 1" and "Long 2" are signal names. It should work.

      Comment


        #4
        Hi Bertrand and Stockfundoo,
        Thank you for your quick replies. I looked at the strategy again and it still does not seem to work.


        Here is a slightly detailed code, nothing too complicated. It is a crossover based strategy but I am adding an element of hedging in it. I am trying to enter a long and short at the same time by giving signals a different name. And then setting different profit and loss targets for them. Here is the error message I get when i try to compile the strategy: " No overload for method 'SetStopLoss' takes '3' arguments"

        protected override void Initialize()
        {
        //Regular Profit and Stoploss Targets
        SetProfitTarget("Long",CalculationMode.Ticks, profittargetticks);
        SetProfitTarget("Short",CalculationMode.Ticks, profittargetticks);
        SetStopLoss("Long",CalculationMode.Ticks, stoplossticks);
        SetStopLoss("Short",CalculationMode.Ticks, stoplossticks);

        //Hedge Profit and Stoploss Targets
        SetProfitTarget("Long Hedge",CalculationMode.Ticks, hedgeprofittargetticks );
        SetProfitTarget("Short Hedge",CalculationMode.Ticks,hedgeprofittargettick s );
        SetStopLoss("Long Hedge",CalculationMode.Ticks, hedgestoplossticks);
        SetStopLoss("Short Hedge",CalculationMode.Ticks, hedgestoplossticks);

        CalculateOnBarClose = true;
        }

        protected override void OnBarUpdate()
        {
        if (CurrentBar < 500)
        return;

        //Long Criteria
        if ((CrossAbove(((T3(14,1,0.1))),(VMA(vma1,vma1vol)), 1)))
        EnterLong(1,"Long");

        if ((CrossBelow(((T3(14,1,0.1))),(VMA(vma2,vma2vol)), 1)))
        ExitLong(1,"LongExit","Long");

        //Long Hedge Criteria
        if ((CrossAbove(((T3(14,1,0.1))),(VMA(vma1,vma1vol)), 1)))
        EnterShort(1,"Long Hedge");

        if ((CrossBelow(((T3(14,1,0.1))),(VMA(vma2,vma2vol)), 1)))
        ExitShort(1,"Long Hedge Exit","Long Hedge");

        //Short Criteria
        if ((CrossBelow(((T3(14,1,0.1))),(VMA(vma1,vma1vol)), 1)))
        EnterShort(1,"Short");

        if ((CrossAbove(((T3(14,1,0.1))),(VMA(vma2,vma2vol)), 1)))
        ExitShort(1,"ShortExit","Short");

        //Short Hedge Criteria
        if(CrossBelow(((T3(14,1,0.1))),(VMA(vma1,vma1vol)) ,1))
        EnterLong(1,"Short Hedge");

        if ((CrossAbove(((T3(14,1,0.1))),(VMA(vma2,vma2vol)), 1)))
        ExitLong(1,"Short Hedge Exit","Short Hedge");

        }

        Any thoughts??

        Comment


          #5
          That error is because correct syntax is below:
          SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)

          You can set simulated to false.

          Also keep your order entry and exit signals by same name.

          Comment


            #6
            pandyav, after working StochFundoo's suggestions in, please recheck the outcomes you get. If it still fails for any reason, please rerun with TraceOrders to get a better feedback.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Bertrand and StockFundoo,
              Thank you very much for your replies. The suggestion that StockFundoo had about Stoploss worked like magic and I was able to compile the strategy without any problems.

              The challenge I am running into now is that when I load the strategy on a chart, I do not see any trades placed by 'Long Hedge' and 'Short Hedge' entry signals. Per Bertrand's suggestion, I traced the order and I get the following output.

              3/18/2014 6:50:00 AM Entered internal PlaceOrder() method at 3/18/2014 6:50:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''
              3/18/2014 6:50:00 AM Entered internal PlaceOrder() method at 3/18/2014 6:50:00 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long Hedge' FromEntrySignal=''
              3/18/2014 6:50:00 AM Cancelled pending entry order on opposite side of the market: BarsInProgress=0: Order='NT-00966/Sim101' Name='Long Hedge' State=Working Instrument='ES 03-14' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='VMACross2' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='58b91471493246458393164c0d299baf' Gtd='12/1/2099 12:00:00 AM'

              For some reason, the system is cancelling my order on the opposite side. Any ideas on why this is happening?

              Again, very much appreciate your help and support in advance.

              Comment


                #8
                Originally posted by pandyav View Post
                Bertrand and StockFundoo,
                Thank you very much for your replies. The suggestion that StockFundoo had about Stoploss worked like magic and I was able to compile the strategy without any problems.

                The challenge I am running into now is that when I load the strategy on a chart, I do not see any trades placed by 'Long Hedge' and 'Short Hedge' entry signals. Per Bertrand's suggestion, I traced the order and I get the following output.

                3/18/2014 6:50:00 AM Entered internal PlaceOrder() method at 3/18/2014 6:50:00 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long' FromEntrySignal=''
                3/18/2014 6:50:00 AM Entered internal PlaceOrder() method at 3/18/2014 6:50:00 AM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Long Hedge' FromEntrySignal=''
                3/18/2014 6:50:00 AM Cancelled pending entry order on opposite side of the market: BarsInProgress=0: Order='NT-00966/Sim101' Name='Long Hedge' State=Working Instrument='ES 03-14' Action=SellShort Limit price=0 Stop price=0 Quantity=1 Strategy='VMACross2' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='58b91471493246458393164c0d299baf' Gtd='12/1/2099 12:00:00 AM'

                For some reason, the system is cancelling my order on the opposite side. Any ideas on why this is happening?

                Again, very much appreciate your help and support in advance.
                Yes. Read the NT Help about using Set methods and trying to place opening orders in the opposing direction.

                ref: http://www.ninjatrader.com/support/h...d_approach.htm

                Expand and read the last folded section in the page: about the Internal Order Handling Rules ...

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by samish18, 04-17-2024, 08:57 AM
                16 responses
                55 views
                0 likes
                Last Post samish18  
                Started by arvidvanstaey, Today, 02:19 PM
                3 responses
                9 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by jordanq2, Today, 03:10 PM
                2 responses
                8 views
                0 likes
                Last Post jordanq2  
                Started by traderqz, Today, 12:06 AM
                10 responses
                18 views
                0 likes
                Last Post traderqz  
                Started by algospoke, 04-17-2024, 06:40 PM
                5 responses
                47 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X