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

stoploss modification

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

    stoploss modification

    I looked over the sample stoploss modification but its for long only, how would u set it up for combination w a short? Should there be a seperate reset if flat for both sides? I tried the below but only one of the stops triggers orders.

    Code:
    	SetStopLoss("EnterLong", CalculationMode.Ticks, stopticks, true);//100
    			SetStopLoss("EnterShort", CalculationMode.Ticks, stopticksS, true);//85
                            SetProfitTarget("EnterLong", CalculationMode.Ticks, profittarget);//79
    			SetProfitTarget("EnterShort",CalculationMode.Ticks, profittargetS);//55
    			
            }
    
            protected override void OnBarUpdate()
    		{
    #region Stoploss Modification			
    		// Resets the stop loss to the original value when all positions are closed
    			
    			if (Position.MarketPosition == MarketPosition.Flat)
    			{
    				SetStopLoss("EnterLong", CalculationMode.Ticks, stopticks, true);
    			}
    			
    			// If a long position is open, allow for stop loss modification
    			else if (Position.MarketPosition == MarketPosition.Long)
    			{
    if (Close[0] >= Position.AvgPrice + (TickSize*10))
    				{
    					SetStopLoss("EnterLong", CalculationMode.Price, Close[0] - (TickSize*15), true);
    			        }
                            }
    			
    	if (Position.MarketPosition == MarketPosition.Short)
    			{
    			
    				if (Close[0] <= Position.AvgPrice - (TickSize*12))
    				{
    				SetStopLoss("EnterShort", CalculationMode.Ticks, TickSize*15, true);
    				}
    			}
    Last edited by zachj; 02-10-2014, 03:09 PM.

    #2
    Hello ZachJ,

    From your script, I see that you are missing a closing } after the SetStopLoss for the long position check and could be causing a logic issue with the code.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I just missed it went pasting in here, that's not the issue. Edited post. Got anything else?

      Comment


        #4
        Thanks Zachj

        Are you saying that the MarketPosition.Long works but the Short does not when a trade is active?
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          When backtesting..in my trades tab there will be a bunch of stop modifications triggered on long side but none for short side. Only way I can get shorts to trigger on short side is from the fixed stop in initialize.

          Comment


            #6
            Zachj,

            Can you attach the strategy so that I can test this on my end?
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              I think I got it working. Just to make sure though, should I have seperate code as I have below to reset the Long and then another to reset the Short position? The "fromEntrySignal" directs each accordingly?

              Code:
              if (Position.MarketPosition == MarketPosition.Flat)
              			{
              				SetStopLoss("EnterLong", CalculationMode.Ticks, 100, true);
              			}
              			
              if (Position.MarketPosition == MarketPosition.Flat)
              			{
              				SetStopLoss("EnterShort", CalculationMode.Ticks, 85, true);
              			}

              Comment


                #8
                Correct, you would be better off on combining those two statements as each StopLoss has its own fromEntrySignal
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  You meant NOT combining right?

                  Comment


                    #10
                    I meant TO combine them as they will process the same way as they do now but without the extra logic to run a test for MarketPosition.
                    Cal H.NinjaTrader Customer Service

                    Comment


                      #11
                      I have a different stoploss ticks for short and long so if I combined them it actually would not process the same?

                      Comment


                        #12
                        Not quite how you're thinking it will work.

                        Since you are using different fromEntrySignals the StopLoss's that are being called will have their own separate logic for the entries.

                        If you combined them you would be telling the system that any Entry Signal with those names to use the associated parameters.
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Cal View Post
                          Not quite how you're thinking it will work.

                          Since you are using different fromEntrySignals the StopLoss's that are being called will have their own separate logic for the entries.

                          If you combined them you would be telling the system that any Entry Signal with those names to use the associated parameters.
                          I don't want them to use any Entry Signal, I am wanting the stop for the Entry signal for the long to use its associated parameters and vice versa for the short. The long has a stop of 100 ticks and the short 85 ticks. So I need to keep them seperate?

                          Comment


                            #14
                            Zachj,

                            Code:
                            if (Position.MarketPosition == MarketPosition.Flat)
                            	{
                            		SetStopLoss("EnterLong", CalculationMode.Ticks, 100, true);
                            	}
                            			
                            if (Position.MarketPosition == MarketPosition.Flat)
                            	{
                            		SetStopLoss("EnterShort", CalculationMode.Ticks, 85, true);
                            	}
                            OR

                            Code:
                            if(Position.MarketPosition == MarketPosition.Flat)
                            {
                                 SetStopLoss("EnterLong", CalculationMode.Ticks, 100, true);
                                 SetStopLoss("EnterShort", CalculationMode.Ticks, 85, true);
                            }
                            Both will produce the same results the bottom has just one less logic to calculate.
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #15
                              Oh that's all you were saying! Sorry I thought you meant use the same stop for the long and short. Thanks man

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X