Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Ichimoku Cloud Backtest issue

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

    Ichimoku Cloud Backtest issue

    I would like to backtest a strategy:

    Entering Long Position at next bar open when ChikouSpan (today close back shift 26 days) cross above the SenkouSpanA and SenkouSpanB (26 days ago);
    Close Long Position when ChikouSpan cross below SenkouSpanA and SenkouSpanB.

    Below is my strategy code:
    {
    // Condition set 1
    if (CrossAbove(IchiLines(9, 26, 52).ChikouSpan, IchiCloud(9, 26, 52).SenkouSpanA[26], 1)
    && CrossAbove(IchiLines(9, 26, 52).ChikouSpan, IchiCloud(9, 26, 52).SenkouSpanB[26], 1))
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (CrossBelow(IchiLines(9, 26, 52).ChikouSpan, IchiCloud(9, 26, 52).SenkouSpanA[26], 1)
    && CrossBelow(IchiLines(9, 26, 52).ChikouSpan, IchiCloud(9, 26, 52).SenkouSpanB[26], 1))
    {
    ExitLong("", "");
    }
    }

    But it shows no positions taken in backtesting. Any idea how to solve it?

    #2
    Hello,

    Thank you for the inquiry.

    First I wanted to confirm, is the indicator being used able to work historically? I have not seen this item myself, if it is able to work historically you would likely need to debug the values being used.

    I see the // Condition set 1 comment, to confirm is this strategy being created in the wizard or are you manually coding it currently?

    If you are manually coding this, I would suggest using a Print outside the condition to see what values are being compared (you can also duplicate you strategy, and unlock it to use prints for debugging):

    Code:
    Print("IchiLines(9, 26, 52).ChikouSpan: " + IchiLines(9, 26, 52).ChikouSpan[0] + " IchiCloud(9, 26, 52).SenkouSpanB[26]: " + IchiCloud(9, 26, 52).SenkouSpanB[26]);
    This would let you see the values being compared for you to determine if the cross should work as expected.

    If you are instead using the wizard, are you currently using the Plot on chart option to see the indicator visually? If so, are you able to visually compare this cross for the indicators plots?


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

    Comment


      #3
      I tried to build the indicator with the code below, but it did't work out. Any idea what went wrong?


      if(
      Crossabove(IchiLines(9,26,52).ChikouSpan[0],IchiCloud(9,26,52).SenkouSpanA[26],1)&& Crossabove(IchiLines(9,26,52).ChikouSpan[0],IchiCloud(9,26,52).SenkouSpanB[26],1)
      )

      {
      DrawDot("dot" + CurrentBar,false,0,Low[0],Color.Blue);
      Print("IchiLines(9, 26, 52).ChikouSpan: " + IchiLines(9, 26, 52).ChikouSpan[0] + " IchiCloud(9, 26, 52).SenkouSpanA[26]: " + IchiCloud(9, 26, 52).SenkouSpanA[26]);
      }

      Comment


        #4
        Hello,

        Thank you for the reply.

        I couldnt say as I am unable to run the code you are using.

        Placing the Drawing and Prints inside of the condition will likely not be helpful in this case, I could suggest instead putting the print Outside of the condition so you can see the values you are using.

        Code:
        Print("IchiLines(9, 26, 52).ChikouSpan: " + IchiLines(9, 26, 52).ChikouSpan[0] + " IchiCloud(9, 26, 52).SenkouSpanA[26]: " + IchiCloud(9, 26, 52).SenkouSpanA[26]);	
        
        if(	
        Crossabove(IchiLines(9,26,52).ChikouSpan[0],IchiCloud(9,26,52).SenkouSpanA[26],1)&& Crossabove(IchiLines(9,26,52).ChikouSpan[0],IchiCloud(9,26,52).SenkouSpanB[26],1)
        )
        
        {
        DrawDot("dot" + CurrentBar,false,0,Low[0],Color.Blue);
        
        }
        You would need to see why the condition is not happening by printing the values you are using.

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

        Comment


          #5
          Hi Jesse,

          I have tried the code you just sent but it didn't workout. I tried to compile it, but the error shown out as below in the attachment. Could you please help me out.
          Attached Files

          Comment


            #6
            Hello edricoon,

            I don't think the issue is with the print that jesse suggested.

            I think the issue is with the if statement.

            The error indicates that cross above requires a series, however, in your you are passing in two double values.

            The [0] is an index that picks a specifc value.

            IchiLines(9,26,52).ChikouSpan[0] <-- this is a double

            IchiLines(9,26,52).ChikouSpan <-- this is a series

            Try:
            Code:
            if(Crossabove(IchiLines(9,26,52).ChikouSpan, IchiCloud(9,26,52).SenkouSpanA[26], 1) &&
            Crossabove(IchiLines(9,26,52).ChikouSpan, IchiCloud(9,26,52).SenkouSpanB[26], 1))
            CrossAbove(IDataSeries series1, double value, int lookBackPeriod)

            Below is a publicly available link to the help guide.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello edricoon,

              I don't think the issue is with the print that jesse suggested.

              I think the issue is with the if statement.

              The error indicates that cross above requires a series, however, in your you are passing in two double values.

              The [0] is an index that picks a specifc value.

              IchiLines(9,26,52).ChikouSpan[0] <-- this is a double

              IchiLines(9,26,52).ChikouSpan <-- this is a series

              Try:
              Code:
              if(Crossabove(IchiLines(9,26,52).ChikouSpan, IchiCloud(9,26,52).SenkouSpanA[26], 1) &&
              Crossabove(IchiLines(9,26,52).ChikouSpan, IchiCloud(9,26,52).SenkouSpanB[26], 1))
              CrossAbove(IDataSeries series1, double value, int lookBackPeriod)

              Below is a publicly available link to the help guide.
              https://ninjatrader.com/support/help...crossabove.htm
              I have tried your code as below:

              if(CrossAbove(IchiLines(9,26,52).ChikouSpan, IchiCloud(9,26,52).SenkouSpanA[26], 26) &&
              CrossAbove(IchiLines(9,26,52).ChikouSpan, IchiCloud(9,26,52).SenkouSpanB[26], 26))

              {DrawDot("dot" + CurrentBar,false,0,Low[0],Color.Blue);}

              And it can be compiled. However, nothing show up in the chart when I plug in the indicator.

              It supposed to insert a dot below current bar if the CLOSE of the 26th bar ago cross above the SenkouSpanA and SenkouSpanB of the 26th bar ago.

              Comment


                #8
                Hello,

                Thank you for the reply.

                If nothing is showing up, that would likely indicate the condition had not become true. Are you currently using any Prints to check the values of the indicator? It appears you had a syntax problem with the indicator that was corrected, now I would suggest using Prints to ensure the condition is becoming true.

                In post #2 there is one example print you could try but you can really form the print however is best for you to understand the values being used. We have a short guide on debugging here: https://ninjatrader.com/support/foru...58&postcount=1

                Because the dot is not being drawn, you would likely need to add the print outside of the condition so it prints for every bar. You could then compare the raw data to see if the condition should have been true anywhere on the chart.

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

                Comment


                  #9
                  Originally posted by NinjaTrader_Jesse View Post
                  Hello,

                  Thank you for the reply.

                  If nothing is showing up, that would likely indicate the condition had not become true. Are you currently using any Prints to check the values of the indicator? It appears you had a syntax problem with the indicator that was corrected, now I would suggest using Prints to ensure the condition is becoming true.

                  In post #2 there is one example print you could try but you can really form the print however is best for you to understand the values being used. We have a short guide on debugging here: https://ninjatrader.com/support/foru...58&postcount=1

                  Because the dot is not being drawn, you would likely need to add the print outside of the condition so it prints for every bar. You could then compare the raw data to see if the condition should have been true anywhere on the chart.

                  I look forward to being of further assistance.
                  Thank You for your help Jesse, I have solved the issue and got what I want with the code below:

                  {if(CurrentBar<52)
                  return;
                  Print("ChikouSpan: " + IchimokuCloud(9, 26, 52).ChikouSpan[0] + " SpanA: " + IchimokuCloud(9, 26, 52)._SenkouSpanA[52] + " SpanB: " + IchimokuCloud(9,26,52)._SenkouSpanB[52]);

                  if(IchimokuCloud(9,26,52)._SenkouSpanA[52] > IchimokuCloud(9,26,52)._SenkouSpanB[52] &&
                  CrossAbove(IchimokuCloud(9,26,52).ChikouSpan,
                  IchimokuCloud(9,26,52)._SenkouSpanA[52], 1))

                  {DrawDot("dot" + CurrentBar,false,0,Low[0]-50*TickSize,Color.Blue);}

                  else if (IchimokuCloud(9,26,52)._SenkouSpanB[52] >
                  IchimokuCloud(9,26,52)._SenkouSpanA[52] &&
                  CrossAbove(IchimokuCloud(9,26,52).ChikouSpan,
                  IchimokuCloud(9,26,52)._SenkouSpanB[52], 1))

                  {DrawDot("dot" + CurrentBar,false,0,Low[0]-50*TickSize,Color.Red);}


                  However, some dot were not plotted when the ChikouSpan crosses above the SenkouSpanA[52] when it supposed to. So I went back and check with the code and modified the lookback period to 2, and surprisingly it worked out.

                  Now I would like to modify it a bit to overcome the issue of double dotting since for every dot plotted with the lookback period of 2, there would be another dot plotted in the next bar. (as the condition of lookback period 1 is harder to fulfil then using lookback period of 2)

                  Here are some thoughts about the code:

                  IF the condition set with lookback period of 2 is true,
                  THEN check whether if the condition set with lookback period of 1 is true,
                  IF both conditions above with lookback peiod of 2 and 1 are true,
                  THEN plot the condition set with lookback period of 1.

                  HOWEVER IF the condition set with lookback period of 2 is true,
                  But it shows nothing with the lookback period of 1 (untrue),
                  THEN plot the condition set with lookback period of 2.

                  Could you please help me out with it? Multiple if?

                  Comment


                    #10
                    Originally posted by edricoon View Post
                    Thank You for your help Jesse, I have solved the issue and got what I want with the code below:

                    {if(CurrentBar<52)
                    return;
                    Print("ChikouSpan: " + IchimokuCloud(9, 26, 52).ChikouSpan[0] + " SpanA: " + IchimokuCloud(9, 26, 52)._SenkouSpanA[52] + " SpanB: " + IchimokuCloud(9,26,52)._SenkouSpanB[52]);

                    if(IchimokuCloud(9,26,52)._SenkouSpanA[52] > IchimokuCloud(9,26,52)._SenkouSpanB[52] &&
                    CrossAbove(IchimokuCloud(9,26,52).ChikouSpan,
                    IchimokuCloud(9,26,52)._SenkouSpanA[52], 1))

                    {DrawDot("dot" + CurrentBar,false,0,Low[0]-50*TickSize,Color.Blue);}

                    else if (IchimokuCloud(9,26,52)._SenkouSpanB[52] >
                    IchimokuCloud(9,26,52)._SenkouSpanA[52] &&
                    CrossAbove(IchimokuCloud(9,26,52).ChikouSpan,
                    IchimokuCloud(9,26,52)._SenkouSpanB[52], 1))

                    {DrawDot("dot" + CurrentBar,false,0,Low[0]-50*TickSize,Color.Red);}


                    However, some dot were not plotted when the ChikouSpan crosses above the SenkouSpanA[52] when it supposed to. So I went back and check with the code and modified the lookback period to 2, and surprisingly it worked out.

                    Now I would like to modify it a bit to overcome the issue of double dotting since for every dot plotted with the lookback period of 2, there would be another dot plotted in the next bar. (as the condition of lookback period 1 is harder to fulfil then using lookback period of 2)

                    Here are some thoughts about the code:

                    IF the condition set with lookback period of 2 is true,
                    THEN check whether if the condition set with lookback period of 1 is true,
                    IF both conditions above with lookback peiod of 2 and 1 are true,
                    THEN plot the condition set with lookback period of 1.

                    HOWEVER IF the condition set with lookback period of 2 is true,
                    But it shows nothing with the lookback period of 1 (untrue),
                    THEN plot the condition set with lookback period of 2.

                    Could you please help me out with it? Multiple if?
                    The data is streaming in, so simply process it as it streams in.

                    Pseudocode:
                    Code:
                    IF the condition set with lookback period of 2 is true, plot the condition set relative to the bar
                    IF the condition set with lookback period of 1 is true, 
                    {
                    delete the previous plotted mark
                    plot the condition set relative to the bar 
                    }

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by jclose, Today, 09:37 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post jclose
                    by jclose
                     
                    Started by WeyldFalcon, 08-07-2020, 06:13 AM
                    10 responses
                    1,413 views
                    0 likes
                    Last Post Traderontheroad  
                    Started by firefoxforum12, Today, 08:53 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post firefoxforum12  
                    Started by stafe, Today, 08:34 PM
                    0 responses
                    10 views
                    0 likes
                    Last Post stafe
                    by stafe
                     
                    Started by sastrades, 01-31-2024, 10:19 PM
                    11 responses
                    169 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Working...
                    X