Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set Stop Loss Programming Question

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

    Set Stop Loss Programming Question

    I am trying to wean myself off Strategy Wizard, so any help would be greatly appreciated...(searched help files but I still come up wrong)

    I am simply trying to establish a STOP LOSS (intrabar) based on a calculation:

    Stop Loss = Entry Price - (ATR(previous bar) * Multiple)

    So, here are some issues:

    1. SetStopLoss is inserted in script before [CalculateOnBarClose = TRUE]. This is good, assuming that SetStopLoss OVERRULES everything else and will exit a trade on tick that price touches calculated StopLoss.

    2. Entry Conditions are inserted after [CalculateOnBarClose = TRUE]. Again, correct per my strategy. Bar data only is sufficient.

    So, where(how?) do I create this variable called, Stop Loss?

    I must be coding something wrong because the strategy produces correct entries but every trade ends with being stopped out at same price as ENTRY.

    #region Variables
    privatedouble stopLong1 = 0; // Default setting for StopLong

    protectedoverridevoid Initialize()
    {
    stopLong1 = ((double)ATR(atrlength)[0] * (double)atrmult * 10000);

    SetStopLoss("Entry Label",CalculationMode.Ticks,stopLong1, false);
    }


    #region Properties

    #2
    CRCatNinja,

    In Initialize() you will not be able to run that kind of calculation. No indicators exist in the context of Initialize(). If you want that stop loss you need to move all of that into OnBarUpdate().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks so much Josh...I am learning as quickly as possible, trying to follow the NT help guides.

      Can you confirm that the command, "SETSTOPLOSS" will get activated intrabar (even though CalculateOnBarClose = TRUE)?

      So, would you recommend that I place those 2 statements immediately after my ENTRY conditions?

      Thanks again.

      Comment


        #4
        I recommend you put them BEFORE your entry. They will be activated immediately right when your entry order is filled.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        573 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        575 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X