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

Calling Stop Loss Value from Calculated Variable

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

    Calling Stop Loss Value from Calculated Variable

    Hello,

    I'm having trouble using data stored in a variable as a stop loss. As seen in the attached image, I've set the value of that variable (named StopVar) to be displayed under each bar to make sure it's correct. However, when my entry logic fires off, it is placing my stop 1 tick behind my entry, instead using StopVar as the offset. In the leftmost entry in the image, my stop loss should have been offset by 38 ticks.

    I apologize beforehand, this is my first attempt at using strategy builder and I have almost zero programming knowledge.
    Attached Files

    #2
    Hello clewis5,

    Thanks for writing in to our Support team.

    Can you please send me screenshots of how you are calculating your StopVar value? Do you get the same behavior when using a numeric value instead of a variable for your stop loss value?

    I look forward to your reply.
    Alan S.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply Alan,

      Please find the screenshot attached.

      I am trying to set the stop at the low of the bar that just closed whenever an entry is triggered. Using a set numerical value, or a user input for the stop works fine.

      Initially, I tried just calling out the low of the bar (price) on the stops and targets screen, but the strategy would immediately disable and throw an error on the log screen. I tried a few other routes with the same results and eventually wound up at this stage; calling the value for the offset from a variable. The code runs now, but not as I would like it.

      Thanks in advance,
      clewis5
      Attached Files

      Comment


        #4
        Hello clewis5,

        Thanks for your reply.

        When setting up the Stops and Targets from this window in the strategy builder, it sets the profit target/stop loss before any of your logic to calculate your StopVar variable is run, so it uses your default value of 1. You can see this if you select View code - SetProfitTarget() and SetStopLoss() are called in State.Configure before your calculation logic in OnBarUpdate() has a chance to run.

        To use your variable once the value has been calculated, you will need to unlock your code and copy and paste the SetStopLoss() method just after the line that the StopVar is caclulated, like so:
        Code:
        StopVar = Convert.ToInt32((Stop[0] * 10));
        SetStopLoss('', CaclulationMode.Ticks, StopVar, false);
        Please let me know if I may be of any further assistance.
        Alan S.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by junkone, Today, 11:37 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by frankthearm, Yesterday, 09:08 AM
        11 responses
        42 views
        0 likes
        Last Post frankthearm  
        Started by quantismo, 04-17-2024, 05:13 PM
        5 responses
        35 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by proptrade13, Today, 11:06 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        35 views
        0 likes
        Last Post love2code2trade  
        Working...
        X