• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Does SetStopLoss() Cancel on Next Bar ?

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

    Does SetStopLoss() Cancel on Next Bar ?

    Just wanted to clarify something. If I am in a position via EnterLong() or EnterShort(). And I have called SetStopLoss(). Do I need to keep calling it on every bar?

    I'm having trouble with my stops constantly cancelling, and I can't work out if its a bug in my code of me misunderstanding the behavior in Ninjatrader.

    #2
    Hello kevinenergy,

    Thank you for the post.

    This is likely related to the specific logic you have used, if you are simply using SetStopLoss with an entry, it should remain active. You can create small tests to confirm items like this, here is an example you could apply to a 10 second chart to see what the expected outcome is.


    Code:
    protected override void OnBarUpdate()
    {
    	if(State != State.Realtime) return;
    	if(Position.MarketPosition == MarketPosition.Flat)
    	{
    		EnterLong();
    	}
    	if(Position.MarketPosition == MarketPosition.Long && BarsSinceEntryExecution() == 1)
    	{
    		Print("called SetStopLoss");
    		SetStopLoss(CalculationMode.Ticks, 10);
    	}
    }
    This type of test just submits a single order, waits for a bar then submits the stop which you can then watch as bars elapse to see if it cancels. I did not see it cancel but remained active.

    You can also form other samples like this to be more like what you have created to see if the logic you used is part of the problem. If you are unsure why something is happening still after reducing the logic or making a sample like this, I would be happy to review that with you.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by curious, Today, 02:17 AM
    2 responses
    7 views
    0 likes
    Last Post curious
    by curious
     
    Started by pmmkm, Yesterday, 11:13 PM
    0 responses
    3 views
    0 likes
    Last Post pmmkm
    by pmmkm
     
    Started by pulpiwapi, 03-04-2019, 11:18 PM
    11 responses
    149 views
    0 likes
    Last Post music_p13  
    Started by indy73, 06-25-2019, 10:52 PM
    3 responses
    21 views
    0 likes
    Last Post sledge
    by sledge
     
    Started by priceisking, Yesterday, 12:51 PM
    1 response
    23 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Working...
    X