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

Reversing Break Even Logic

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

    Reversing Break Even Logic

    Hello,Support!

    I`m trying to reverse the BE logic,so it should trigger when the price goes below entry(if long) and above entry(if short).

    Here`s the original logic snippet:

    Code:
    if(Position.MarketPosition == MarketPosition.Long)
    			{					
    				
    				//*****************************
    				// 			BreakEven
    				//*****************************
    				double bePrice = Position.AvgPrice + this.iAutoBreakEvenTicks * TickSize;												
    				
    				if(
    					// BE turned on via input
    					this.iAutoBreakEvenTicks != 0 
    					// price moved for breakeven						
    					&& Close[0] > bePrice && bePrice != 0
    					)
    				{			
    					
    					double nPrice = Position.AvgPrice + this.iBreakEvenPlusTicks * TickSize;										
    					for(int i = 1 ; i <= 3 ; i++)
    					{
    						if(tVars.iStopOrder[i] != null)
    						{
    							if(nPrice > tVars.iStopOrder[i].StopPrice)							
    								SubmitTargStop(sBIP, i, tVars.iStopOrder[i].FromEntrySignal, tVars.iStopOrder[i].Quantity, 0, nPrice);																			
    						}						
    					}									
    				}
    I`m trying to reverse the logic by doing this:

    Code:
    if(Position.MarketPosition == MarketPosition.Long)
    			{					
    				
    				//*****************************
    				// 			BreakEven
    				//*****************************
    				double bePrice = Position.AvgPrice - this.iAutoBreakEvenTicks * TickSize;												
    				
    				if(
    					// BE turned on via input
    					this.iAutoBreakEvenTicks != 0 
    					// price moved for breakeven						
    					&& Close[0] < bePrice && bePrice != 0
    					)
    				{			
    					
    					double nPrice = Position.AvgPrice - this.iBreakEvenPlusTicks * TickSize;										
    					for(int i = 1 ; i <= 3 ; i++)
    					{
    						if(tVars.iTargOrder[i] != null)
    						{
    							if(nPrice > tVars.iTargOrder[i].LimitPrice)							
    								SubmitTargStop(sBIP, i, tVars.iTargOrder[i].FromEntrySignal, tVars.iTargOrder[i].Quantity, 0, nPrice);																			
    						}						
    					}									
    				}
    Im also trying to get the Target order to be adjusted to the BE level instead of the Stop order,as per original logic.

    Nothing seems to work properly.What am i doing wrong?Any advices appreciated!

    Thanks!

    #2
    Hello,

    Thanks for your post.

    Just to clarify, if you are in a long position you want to change the breakeven trigger to be less than the breakeven/entry price?

    Typically a breakeven stop is used when you are in a positive position to protect against loss.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello,

      Thanks for your post.

      Just to clarify, if you are in a long position you want to change the breakeven trigger to be less than the breakeven/entry price?

      Typically a breakeven stop is used when you are in a positive position to protect against loss.
      I want the target order to be trigered and moved to the entry level,when i`m in negative position.

      Comment


        #4
        Hello,

        Thanks for your reply.

        A breakeven stop, in the case of a long position typically would be a stop order below price. If I understand you correctly, you want to move the target, which would typically be a limit order, to the entry price.

        You would want to move the target order.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Paul View Post
          Hello,

          Thanks for your reply.

          A breakeven stop, in the case of a long position typically would be a stop order below price. If I understand you correctly, you want to move the target, which would typically be a limit order, to the entry price.

          You would want to move the target order.
          I try exactly that as you may see in the second example in this post:



          To move the target order but it doesn`t work

          Comment


            #6
            Hello,

            Thanks for your reply.

            We do not know how SubmitTargStop() is going to handle the operators you submit to it. You need to debug your script if it is not performing as you need.

            If this is not your script, then please contact the developer.
            Paul H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mjairg, 07-20-2023, 11:57 PM
            3 responses
            213 views
            1 like
            Last Post PaulMohn  
            Started by TheWhiteDragon, 01-21-2019, 12:44 PM
            4 responses
            544 views
            0 likes
            Last Post PaulMohn  
            Started by GLFX005, Today, 03:23 AM
            0 responses
            3 views
            0 likes
            Last Post GLFX005
            by GLFX005
             
            Started by XXtrader, Yesterday, 11:30 PM
            2 responses
            12 views
            0 likes
            Last Post XXtrader  
            Started by Waxavi, Today, 02:10 AM
            0 responses
            7 views
            0 likes
            Last Post Waxavi
            by Waxavi
             
            Working...
            X