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

Adopt Account Position, SetStopLoss, SetProfitTarget

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

  • Camdo
    replied
    sagetrade, I think the attached strategy will do what you want.
    It will assume the current position and immediately place stoploss and profit target orders.

    It was designed to carry a futures contract into to next day without triggering overnight margin requirements. After assuming the current position, it will exit the position at a chosen time (end of session), and then re-enter the position at another time (start of the next session).

    Thanks to AlanP for the code example to get me started. I hope this will do the same for you.
    AssumeExitReenter.zip

    Leave a comment:


  • sagetrade
    replied
    Dear Alan,

    thanks for your work. I used parts from your code to send a stopp once the strategy is started. The only problem that I have left is the timelag that occurs as the stopp is placed from within the onbarupdate method and I have it set to calculate onbarclose the first bar needs to finish before the SL is sent. I would like to keep my settings at onbarclose though.

    Is there an easy way to have this code processed once in the beginning of the startup of a strategy?

    Leave a comment:


  • Camdo
    replied
    Alan, Thank you very much for the code sample. It is just what I needed.

    Leave a comment:


  • NinjaTrader_AlanP
    replied
    Hello Camdo,

    SetStopLoss and SetProfitTarget are going to apply to entry orders made by the strategy.

    I have built a strategy which when you apply it to a data series with an open position, will submit a stop loss and profit target using ExitShortLimit/ExitShortStopMarket for shorts and ExitLongtLimit/ExitLongStopMarket for longs. If either the stop or profit target order is filled, or if the position becomes flat through a manual trade to the account, the SL and PT orders will be canceled.

    Please let us know if you have any questions.
    Attached Files

    Leave a comment:


  • Camdo
    started a topic Adopt Account Position, SetStopLoss, SetProfitTarget

    Adopt Account Position, SetStopLoss, SetProfitTarget

    I am writing a strategy that needs to assume an existing account position upon startup and then place a stop loss and profit target order around the strategy position.
    The code essentials are:

    Code:
    protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				IsAdoptAccountPositionAware = true;
    				StartBehavior = StartBehavior.AdoptAccountPosition;
    				
    				
    			}
    			else if (State == State.Configure)
    			{
    				SetProfitTarget(CalculationMode.Price, ProfitTargetPrice);
    				SetStopLoss(CalculationMode.Ticks, StopLossTicks);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
                          //do something
    		}
    The problem is SetStopLoss() and SetProfitTarget() do not execute around the adopted account position upon strategy startup.

    The instructions for SetStopLoss() and SetProfitTarget() say:
    Profit target orders are submitted in real-time on incoming executions from entry orders
    Apparently AdoptAccountPosition does not simulate the necessary conditions for Set...() to work.

    Is there a way for a strategy to adopt an account position and then apply a stop loss and profit target?

Latest Posts

Collapse

Topics Statistics Last Post
Started by mattbsea, Today, 05:44 PM
0 responses
4 views
0 likes
Last Post mattbsea  
Started by RideMe, 04-07-2024, 04:54 PM
6 responses
31 views
0 likes
Last Post RideMe
by RideMe
 
Started by tkaboris, Today, 05:13 PM
0 responses
2 views
0 likes
Last Post tkaboris  
Started by GussJ, 03-04-2020, 03:11 PM
16 responses
3,282 views
0 likes
Last Post Leafcutter  
Started by WHICKED, Today, 12:45 PM
2 responses
20 views
0 likes
Last Post WHICKED
by WHICKED
 
Working...
X