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

Offset not working in strategy builder

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

    Offset not working in strategy builder

    Hi, I'm trying to add an offset to a EMA, but it won't offset the line in the strategy tester or show anything in the code stating the offset. Could I do it manually, for example by using this code in line 62 ?
    EMA(Close, 200)+0.0001;
    Thanks

    (Attaching screenshots of builder and code)
    Attached Files

    #2
    Hi voltation,
    It can be done with the StrategyBuilder.
    It is helpful to start with a BIG offset when checking, if the strategy executes trades as expected.
    The attached works with a 25 tick offset. For illustration purposes, I added the EMA, EMA+25Ticks and EMA-25Ticks to the chart.
    The trades were triggered by the cross of the EMA +/- Offset of 25 Ticks, not (already) by a cross of the EMA itself.
    I suggest to add two custom series EMA+Ticks and EMA-Ticks and set them on each bar update. Then refer to these custom series in your entry/exit logic and add draws as you like.
    NT-Roland
    Attached Files

    Comment


      #3
      Originally posted by NT-Roland View Post
      Hi voltation,
      It can be done with the StrategyBuilder.
      It is helpful to start with a BIG offset when checking, if the strategy executes trades as expected.
      The attached works with a 25 tick offset. For illustration purposes, I added the EMA, EMA+25Ticks and EMA-25Ticks to the chart.
      The trades were triggered by the cross of the EMA +/- Offset of 25 Ticks, not (already) by a cross of the EMA itself.
      I suggest to add two custom series EMA+Ticks and EMA-Ticks and set them on each bar update. Then refer to these custom series in your entry/exit logic and add draws as you like.
      NT-Roland
      The issue is that it is drawing without any offset, and also the code wont state any offset. That's why I would like to do it from the unlocked code but don't know how to code it. Did you see my pdf attachement?

      Comment


        #4
        Hi voltation,
        Sure. I saw it. How do you know that the EMA is plotting without offset? Did you compare the values of the EMA with and without offset?
        Did you try to add the custom series (see screenshot) in StrategyBuilder, set them on each bar update to the current value of the EMA +/- a BIG offset, and print ALL values on each bar update to the output window (EMA, EMA+Ticks, EMA-Ticks)?
        NT-Roland
        Attached Files

        Comment


          #5
          Originally posted by NT-Roland View Post
          Hi voltation,
          Sure. I saw it. How do you know that the EMA is plotting without offset? Did you compare the values of the EMA with and without offset?
          Did you try to add the custom series (see screenshot) in StrategyBuilder, set them on each bar update to the current value of the EMA +/- a BIG offset, and print ALL values on each bar update to the output window (EMA, EMA+Ticks, EMA-Ticks)?
          NT-Roland
          Hi Roland, yep, I compared it. About the custom series I don't know how to apply it to this case. Could you send me a screenshot or copy text from your source code of the strategy example you did, to see if I can see how it is stated?

          Thanks!

          Comment


            #6
            Hi voltation,
            I like to use extensive logging when in doubt. This is one possible solution.
            Step 1: In StrategyBuilder, under "Additional Data", in the lower part "Customs Series", add two variables of type double.
            Step 2: In "Conditions and Actions", add a "Set" and check in the upper part "If all" if you have enough bars (Misc -> CurrentBars >= your EMAPeriod),
            If Yes, continue with Step 3.
            Step 3: Under "Do the following" set the customs variables:
            3a Under "Misc", pick the first custom variable you added (e.g. "EMATicksUp) then click on "set", then pick the standard EMA indicator you have in mind, then under "Properties" apply the offset in positive Ticks.
            3b Under "Misc" pick the 2nd custom variable, you added (e.g. "EMATicksDown"), then repeat the above procedure, but under "Properties" apply a negative offset in Ticks.
            With that, you have all you need to check in detail, if your EMA offset (up/down) is being calculated correctly. You can print and draw everything as you like and refer straight to your customs series in your code. All this can be accomplished much easier in NinjaScript, but the StrategyBuilder also does the trick.
            Have fun.
            NT-Roland
            Attached Files

            Comment


              #7
              Awesome Roland, will try it!

              Comment


                #8
                Hello voltation,

                I wanted to address a previous inquiry. Are you wanting the plot that is added with 'Plot on chart' to also have the offset applied, and not just the values used for the conditions, is this correct?

                Unfortunately, the rendered plot on the chart does not have the offset applied and would require creating a custom indicator to achieve this.

                The indicator would have a custom internal series to save the actual ma values and then the plot series would have an offset input in the indicator applied.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Roland and Chelsea,

                  It worked very nice with the custom variable, thanks!! It would be great that it could plot with the offset, maybe will try a custom indicator at a later time!

                  Thanks

                  Comment


                    #10
                    Hi voltation,
                    I'm so glad you figured it out. You can of course visualize this. Look at the very first screenshot provided. It had three nice lines :-).
                    Again, much easier in NinjaScript, but it can be done with the StrategyBuilder, too.
                    The trick in StrategyBuilder is to give each custom series draw line (from one bar ago to respective current) an individual name (currentbar + Flag, e.g. Up or Down) to make it unique.
                    Otherwise, Ninja only draws the very last piece line at the right end of the chart (current -1 to current).
                    The attached screenshots are hopefully again self explaining.
                    Have fun.
                    NT-Roland
                    Attached Files
                    Last edited by NT-Roland; 07-20-2020, 02:19 AM. Reason: Again, to do this in the strategy itself is only one possible solution. You can of course also create a custom indicator and apply it to several different strategies

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by cre8able, 02-11-2023, 05:43 PM
                    3 responses
                    236 views
                    0 likes
                    Last Post rhubear
                    by rhubear
                     
                    Started by frslvr, 04-11-2024, 07:26 AM
                    8 responses
                    113 views
                    1 like
                    Last Post NinjaTrader_BrandonH  
                    Started by stafe, 04-15-2024, 08:34 PM
                    10 responses
                    46 views
                    0 likes
                    Last Post stafe
                    by stafe
                     
                    Started by rocketman7, Today, 09:41 AM
                    3 responses
                    11 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by traderqz, Today, 09:44 AM
                    2 responses
                    10 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X