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

Create a Target and Stop variable according tho size candlestick on Strategy Builder

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

    Create a Target and Stop variable according tho size candlestick on Strategy Builder

    Hi Ninjas,
    How can I create a ProfitTarget and StopLoss according to the size of each candlestick (High and Low) when I just enter (Long and Short) using Strategy Builder?
    I have tried this but it doesn't work:

    Variable:
    TargetStopPoints Double
    TargetStopTicks Double

    Do the following:
    EnterLong(DefaultQuantity,"")
    TargetStopPoints = (High[0] - Low[0])
    TargetStopTicks= (TargetStopPoints * 4)

    Stop and Target:
    SetProfitTarget("",CalculationMode.Tick, TargetStopTicks)
    SetStopLoss("",CalculationMode.Tick, TargetStopTicks,false)



    I hope you can tell me what I'm doing wrong....

    Thank you!

    #2
    Hello MarcoNT29,

    Thanks for your post.

    In the Strategy Builder, the set methods (SetProfitTarget, SetStopLoss, etc.) are limited to static fixed values only. In other words, you can only set for example a 10 tick stop and a 20 tick profit and these would be employed on every entry of that strategy. The set methods automatically adjust their values based on the entry and direction and are immediately employed upon an entry.

    To accomplish your goal, in the Strategy Builder, you would not be able to use the stops and targets window and instead would need to use the order found under the "Order Management" section in the "do the follow" of each set. For example, assume a long entry, you would use "Exit long position by a limit order" as the profit target, and "Exit long position by a stop order" for the stop loss.

    There are a couple of critical considerations in doing this:

    1) These type of orders are automatically canceled if they are not filled in the bar they are submitted on. This means you would need to continue resubmitting the orders, on each bar, until one or the other fills.

    2) You might then imagine a set where you check to see that you are in a position and if so submitting these orders at previously calculated values (somewhat like what you show in your post). However, there is no calculation mode for the exit order methods and so your values need to be the actual price value to set these orders at. One way to do that is to use Strategy>Average Position Price as the entry price and add or subtract your ticks to that value as needed. This sounds easy but in the Strategy builder this can be difficult and I would suggest using Custom series to be able to perform the math needed. You would also need to subtract one set of ticks from the average price for the stop loss (when going long) and add ticks to the price for the profit target. In a short direction, you would need to reverse that.

    So while possible there is a lot that your Strategy Builder would need to do to provide a customized profit/stop based on a bar size. You would find it to be much easier using the Static values.




    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Ok, I think I understand...
      I'm going to give it a try a few days and then let you know...


      Thanks Paul!

      Comment


        #4
        Hi NinjaTrader_PaulH
        I have been working on the strategy and now it is running well with "Exit long position by a limit order" as the profit target, and "Exit long position by a stop order" for the stop loss and the two critical considerations, thank you!

        But tere is a problem, my strategy is working well just with playback connection but not with Strategy Analizer (here the strategy takes very bad the Target and Stop prices). Do you know if "Exit long position by a limit order" and "Exit long position by a stop order" have a limit for running well on Strategy Analizer?



        Regards,

        Comment


          #5
          Hello MarcoNT29,

          Thanks for your reply.

          Glad you were able to rework your strategy to use those type orders.

          The strategy analyzer does not use the same type of data as the playback connection does and as such it has to make certain assumptions, for example, if both a profit and a stop can be hit in the same bar, it will fill the stop first. It does this because it does not know the sequence of ticks that made the bar up/down, it only knows the OHLC values of the bar itself.

          Here is a link to the help guide that exaplins some differences you might expect: https://ninjatrader.com/support/help...ime_vs_bac.htm

          If the startegy is running well in playback, then I would suggest applying to a live chart and use the sim101 account for further testing.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Ok thank you very much Paul!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by r68cervera, Today, 05:29 AM
            0 responses
            2 views
            0 likes
            Last Post r68cervera  
            Started by geddyisodin, Today, 05:20 AM
            0 responses
            3 views
            0 likes
            Last Post geddyisodin  
            Started by JonesJoker, 04-22-2024, 12:23 PM
            6 responses
            34 views
            0 likes
            Last Post JonesJoker  
            Started by GussJ, 03-04-2020, 03:11 PM
            12 responses
            3,239 views
            0 likes
            Last Post Leafcutter  
            Started by AveryFlynn, Today, 04:57 AM
            0 responses
            6 views
            0 likes
            Last Post AveryFlynn  
            Working...
            X