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

crossover strategy no trader

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

    crossover strategy no trader

    Hi ninjatraders, I made an indicator plot, and when price crosses below it and it's an up bar I go long, when price crosses above it and it's a down bar I go short. I made another indicator that draws arrows on these signals. The picture shows this on a 4 range chart. The problem is that live the arrow indicator stops plotting and the prints no longer show the condition is being met. However, historically on the chart you can see the condition being made, and it also works in backtest. Could the solution be something simple I'm missing? Also I'm using cobc= true
    Attached Files
    Last edited by sampras010; 01-29-2018, 09:12 AM.

    #2
    Hello sampras010,

    Thanks for opening the thread.

    Without the code and testing on my end, I am only left to guess at what the issue may be. I would expect COBC=true to work consistently between historical and realtime data.

    Are you saying that there are arrows that aren't plotting in realtime, but if you reload the NinjaScript with F5, the arrows appear?

    If you have identified that the arrow is not drawing because conditions are not becoming true, we would have to take a closer look at what is going into the condition so it results as false. When you add prints for the values going into the condition, do you get any hints as to how the condition may need to be changed?

    Please provide a reduced example of the condition and the prints you have made if you have been unable to resolve your inquiry.

    I look forward to being of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      I tried this...

      Code:
      if (CrossAbove(Close, PLOT(), 1) 
      && Close[0]<= Close[1])
      { 
                                     Print(Time[0]);
                                     EnterShort(1,"Short");
                                     SetStopLoss(330);
      				
      			}
       if (CrossBelow(Close, PLOT(), 1)
      && Close[0]>= Close[1])
                              { 
      				Print(Time[0]);
                                      SetStopLoss(330);
      				EnterLong(1,"Long");
      				
      			}
      and also tried this...

      Code:
                    
      if(Close[0] < PLOT()[0] && Close[0] >= Close[1]
      && Close[1]>= PLOT()[1]
      								)
      			{
      				Print(Time[0]);
      				EnterLong();
      				SetStopLoss(330);
      			}
      if(Close[0] > PLOT()[0] && Close[0] <= Close[1]
      && Close[1]<= PLOT()[1]
      								)
      			{
      				Print(Time[0]);
      				EnterShort();
      				SetStopLoss(330);
      			}
      I used the same conditions for the arrow indicator, and yes, in realtime the arrows are no longer drawn, and if I press f5 they appear. I'm having a little trouble figuring out the syntax to print values for the comparison between price and the plot. I can try to figure that out and let you know if that worked if you don't spot something already.

      Comment


        #4
        Hello sampras010,

        Thanks for your reply.

        When you print out the values that create the condition, what do you see? For example, Close[0], PLOT()[0], Close[1], PLOT()[1].

        This may give hint to look further into the indicator that creates the plot value. I may also suggest testing with a system indicator like an SMA to verify the issue has to do with an underlying indicator's logic.

        I'm happy to be of any additional help.
        JimNinjaTrader Customer Service

        Comment


          #5
          ok, so I used this print in realtime

          Code:
          Print(Time[0]+" - Close[1]: "+Close[1]+" > PLOT()[1]:"+PLOT()[1]+" - Close[0]: "+Close[0]+" < PLOT()[0]:"+PLOT()[0] );
          In realtime it appears it's using Plot()[1] instead of Plot()[0] for the comparison with Close[0] for example I got this

          9:02:54 AM - Close[1]: 65.26 > PLOT()[1]:65.225 - Close[0]: 65.29 < PLOT()[0]:65.225

          historically I got this

          9:02:54 AM - Close[1]: 65.26 > PLOT()[1]:65.225 - Close[0]: 65.29 < PLOT()[0]:65.3

          Could it be that the plot isn't fast enough in realtime to be registered in time? Just watching the chart, it seems to plot at each close of a bar on time. Would I need to use cobc = false for a portion of the strategy?

          Comment


            #6
            Hello sampras010,

            If the indicator is using the same data series as the input series, and is not calculating off another data series, I would expect the output to be the same for COBC=true.

            Can you confirm if you are seeing the same behavior using a system indicator like an SMA?

            Are you also seeing this behavior with other instruments?

            This will tell us if we need to try an instrument reset or look further into the PLOT() indicator to see why its output is different.

            I look forward to being of further assistance.
            JimNinjaTrader Customer Service

            Comment


              #7
              I'm not sure what you mean. The Plot() indicator is just another instruments price. I added range bars and plotted them with Plot0.Set(Closes[1][0]).

              So correct me if I'm wrong, with COBC= true on every close of the instrument I'm charting, the last closed bar of the instrument comprising the plot() indicator should be known, plotted, and should be available for comparison at that time? This is what I'm seeing watching the Plot() indicator.

              I tried with an SMA (wasn't able to make the same exact conditions possible) but for a simple crossover an indicator in realtime works.

              As for other instruments, I'm not sure if the condition is ever true for them so I'm not sure.

              Comment


                #8
                Hello sampras010,

                So correct me if I'm wrong, with COBC= true on every close of the instrument I'm charting, the last closed bar of the instrument comprising the plot() indicator should be known, plotted, and should be available for comparison at that time? This is what I'm seeing watching the Plot() indicator.
                This would be true when the indicator we are calling is using the primary data series. If plot values are set on the secondary series, there is not a guarantee that there we will assign a plot value that is synchronized to the primary data series.

                With the indicator's plot using the the value of the previous bar, I am suspicious that the plot value is being set on a different BarsInProgress than the primary series. BarsInProgress checks to make sure that the plot value is set on the primary data should make sure that the results are consistent.

                If this information does not resolve your inquiry, could you export the indicator with a calling NinjaScript (strategy or indicator) so we may see the full scope of the issue on our end to give further advise?

                Exporting - https://ninjatrader.com/support/help...nt7/export.htm

                I've also linked the Multi Series NinjaScript documentation for reference when using BarsInProgress and working with Multi Series NinjaScripts in general - https://ninjatrader.com/support/help...nstruments.htm

                I'm happy to be of further assistance.
                JimNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by swestendorf, Today, 11:14 AM
                2 responses
                5 views
                0 likes
                Last Post NinjaTrader_Kimberly  
                Started by xiinteractive, 04-09-2024, 08:08 AM
                4 responses
                12 views
                0 likes
                Last Post xiinteractive  
                Started by Mupulen, Today, 11:26 AM
                0 responses
                1 view
                0 likes
                Last Post Mupulen
                by Mupulen
                 
                Started by Sparkyboy, Today, 10:57 AM
                1 response
                5 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by TheMarlin801, 10-13-2020, 01:40 AM
                21 responses
                3,917 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Working...
                X