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 SalmaTrader, 07-07-2026, 10:26 PM
        0 responses
        50 views
        0 likes
        Last Post SalmaTrader  
        Started by CarlTrading, 07-05-2026, 01:16 PM
        0 responses
        22 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 06-17-2026, 10:32 AM
        0 responses
        16 views
        0 likes
        Last Post CaptainJack  
        Started by kinfxhk, 06-17-2026, 04:15 AM
        0 responses
        22 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Started by kinfxhk, 06-17-2026, 04:06 AM
        0 responses
        23 views
        0 likes
        Last Post kinfxhk
        by kinfxhk
         
        Working...
        X