Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy code ignored - takes wrong entry

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

    Strategy code ignored - takes wrong entry

    This happened this morning while testing a strategy live on FXCM data in simulation.
    The strategy entered too early. Entry needs to be when 10 minute (adapted) RSI(2) is closed above 70 and 1 minute (adapted) RSI(5) also closes above 70 in a downtrend defined by the 172 minute (adapted) RSI(2).

    Proper conditions occurred in the 172 minute RSI and 1 minute RSI however 10 minute RSI was about 56 when it took the short. I'm baffled. How is this possible?

    It took the same trade in AUD/JPY correctly but incorrect entry on EUR/USD. Entry condition code shown below. Image of trade is included. Any ideas? I'm baffled.

    Code:
                    if (orderId.Length == 0 && atmStrategyId.Length == 0 &&
                           Falling(CUMRSI(BarsArray[1],periodRsi,3)) &&
                        CUMRSI(BarsArray[2],periodRsi,3)[0] > upper &&
                        CUMRSI(BarsArray[0],rPeriod,3)[0] > upper)
                    {
                        atmStrategyId = GetAtmStrategyUniqueId();
                        orderId = GetAtmStrategyUniqueId();
                        
                        AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0,
                        TimeInForce.Day, orderId, "EURUSD ATM",atmStrategyId);
                    }
    Note: periodRsi = 2 and rPeriod = 5 in code
    I've confirmed all my variables are as they should be
    Attached Files
    Last edited by ShruggedAtlas; 06-09-2015, 08:37 AM.

    #2
    Are you using this in the strategy tab or attached to the chart?

    Is the session template "use instrument settings". Does the instrument setting = what your chart is using?

    Just a wild guess that you might have different templates...

    Comment


      #3
      Hello,

      Comparing your description of your condition to your actual code, I'm not certain if your code accomplishes the condition you are looking for. In your code, you are checking three things:

      1) if the periodRSI CUMRSI of the second data series is falling
      2) if the periodRSI CUMRSI of the third data series is greater than Upper
      3) if the rPeriod CUMRSI of the primary data series is greater than Upper

      Assuming that Upper is set to 70, you appear to only be checking to see if two different CUMRSI's are above 70, while one of those two is currently falling. Without knowing the values of periodRSI and rPeriod, it looks like you are missing one period altogether (either the 10, 1, or 172). Also, the BarsArray indexes that you are referencing may be causing some trouble. If all three data series are different instruments, or if they are all different intervals of the same instrument, then you will need to make sure that the indicators plotted on your chart are using the appropriate input series, as well, in order to see accurate signals on your chart.

      Please let me know if I can assist further.
      Dave I.NinjaTrader Product Management

      Comment


        #4
        The session templates on each data series on the chart are set to 'forex'
        I have applied the strategy directly to the chart. Is there a better way to do this?

        to test, I changed each data series to instrument defaults

        Comment


          #5
          Under variable:
          private int chartOne = 172; // Default setting for chart one
          private int chartTwo = 10; // Default setting for chart two
          Under Initialize:
          Add(PeriodType.Minute, chartOne); //BarsArray[1] - chart 1
          Add(PeriodType.Minute, chartTwo);

          BarsArray[1] is is the 172 minute price data and it is checking for rising and falling conditions. my code here is:
          Falling(CUMRSI(BarsArray[1],periodRsi,3))

          BarsArray[2] is the 10 minute price data and it should be checking for conditions above 70.
          my code here is:
          CUMRSI(BarsArray[2],periodRsi,3)[0] > upper

          BarsArray[0] is the one minute price data and it also should be checking for > 70 conditions.
          my code here is:
          CUMRSI(BarsArray[0],rPeriod,3)[0] > upper)

          Do I have the BarsArray numbers confused?

          Note: the strategy is still running and it took a correct entry! See image below!
          Attached Files

          Comment


            #6
            Are you using a BarsInProgress check?




            Print statements to the output window will help show what your code is seeing exactly.

            Comment


              #7
              yes, within the OnBarUpdate method I have all my conditions being checked within BarsInProgress == 0 if statement

              Code:
                      protected override void OnBarUpdate()
                      {
                          if (CurrentBars[1] < BarsRequired)
                              return;
                          
                          if( Historical ) //used for live trading only with atm strategy
                          {
                              return;
                          } // follow with AtmStrategyCreate() fuction on conditions
                                      
                          if( BarsInProgress == 0 )
                          {            
                              // Condition set 1
                              if (orderId.Length == 0 && atmStrategyId.Length == 0 &&
                                     Falling(CUMRSI(BarsArray[1],periodRsi,3)) &&
                                  CUMRSI(BarsArray[2],periodRsi,3)[0] > upper &&
                                  CUMRSI(BarsArray[0],rPeriod,3)[0] > upper)
                              {
                                  atmStrategyId = GetAtmStrategyUniqueId();
                                  orderId = GetAtmStrategyUniqueId();
                                  
                                  AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0,
                                  TimeInForce.Day, orderId, "EURUSD ATM",atmStrategyId);
                              }
              Also, my variables all seem to be in order. I'm applying this directly to a one minute chart with BA[1] being the 172 minute data and BA[2] being the 10 minute data.

              What i'm confused about is that this always work. This is a strange anomaly that i'm trying to understand.
              Last edited by ShruggedAtlas; 06-09-2015, 09:15 AM.

              Comment


                #8
                Code:
                 
                
                            if( BarsInProgress == 0 )
                            {            
                                // Condition set 1
                if (orderId.Length == 0 && atmStrategyId.Length == 0)
                {
                 if (Falling(CUMRSI(BarsArray[1],periodRsi,3)))
                  {
                    Print ("We are falling");
                       
                    Print ( "CUMRSI(BarsArray[2],periodRsi,3)[0] " +  CUMRSI(BarsArray[2],periodRsi,3)[0]  + " ?>? upper"+upper );
                
                    if( CUMRSI(BarsArray[2],periodRsi,3)[0] > upper )
                {
                
                Print ( "CUMRSI(BarsArray[2],periodRsi,3)[0]" +CUMRSI(BarsArray[2],periodRsi,3)[0]+" ?>? upper"+upper );
                
                  if CUMRSI(BarsArray[0],rPeriod,3)[0] > upper)
                                {
                                    atmStrategyId = GetAtmStrategyUniqueId();
                                    orderId = GetAtmStrategyUniqueId();
                                    
                                    AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0,
                                    TimeInForce.Day, orderId, "EURUSD ATM",atmStrategyId);
                                }
                  else
                Print ("CUMRSI(BarsArray[0],rPeriod,3)[0] > upper failed");
                
                }
                else
                Print ( "CUMRSI(BarsArray[2],periodRsi,3)[0] > upper failed");
                
                
                }
                 else
                    Print ("We are not falling. condition failed");

                Comment


                  #9
                  Thats a great idea. It never occured to me to use print statements as a way to check. I'll try it!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by usazencort, Today, 01:16 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post usazencort  
                  Started by kaywai, 09-01-2023, 08:44 PM
                  5 responses
                  603 views
                  0 likes
                  Last Post NinjaTrader_Jason  
                  Started by xiinteractive, 04-09-2024, 08:08 AM
                  6 responses
                  22 views
                  0 likes
                  Last Post xiinteractive  
                  Started by Pattontje, Yesterday, 02:10 PM
                  2 responses
                  21 views
                  0 likes
                  Last Post Pattontje  
                  Started by flybuzz, 04-21-2024, 04:07 PM
                  17 responses
                  230 views
                  0 likes
                  Last Post TradingLoss  
                  Working...
                  X