Announcement

Collapse
No announcement yet.

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 sgordet, Today, 08:50 PM
0 responses
1 view
0 likes
Last Post sgordet
by sgordet
 
Started by futurenow, Today, 07:17 PM
0 responses
4 views
0 likes
Last Post futurenow  
Started by Emma1, Today, 07:15 PM
0 responses
1 view
0 likes
Last Post Emma1
by Emma1
 
Started by n8dogg59, 05-10-2019, 08:00 AM
14 responses
622 views
0 likes
Last Post brownsfan019  
Started by [email protected], Today, 06:03 PM
0 responses
4 views
0 likes
Last Post bpatel20@gmail.com  
Working...
X