Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Moving Exit by indicator works wrong

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

    Moving Exit by indicator works wrong

    Hello, I from Czech rep. and I need help. I wrote strategy with moving Exit by indicator SafeZone. My Entries are OK, but Exits are wrong. My Exit Long should be when Low[0] cross below the highest value of SafeZone indicator since Entry (green line). But when I backtested the strategy , Exit displayed on other side than the condition is written. The correct Exit should be inside red rectangle (Figure1.png, Figure2.png).

    Here is strategy code. Please help me where is error. Thank you

    Code:
    protected override void Initialize()
            {
            	Add(PeriodType.Tick, TSLOW);
    			Add(LicoSafeZone(TFAST_EMAFast,TFAST_EMASlow,0,true));
    			Add(LicoCCIBarStrategy(true, true, false, 0.6, TFAST_EMAFast, TFAST_CCIFast, TFAST_EMASlow, TFAST_CCISlow, false, 5));
    			Add(LicoCCI(TFAST_CCIFast, TFAST_CCISlow));
    			Add(LicoEMARibbon(TFAST_EMAFast, TFAST_EMASlow));
    			
    			CalculateOnBarClose = false;
    			ExitOnClose = false;
    			EntriesPerDirection = 1; 
    			TraceOrders = true;
    		}
    		
       
            protected override void OnBarUpdate()
            {
    			if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
    				return;
    			
    					
    			if (BarsInProgress == 0)
    			{
    							
    							
                #region GoLong
    				
    				//Enter
    				if (Position.MarketPosition == MarketPosition.Flat
    				&& CCI(TFAST_CCISlow)[0] > 0
                  	                && CCI(TFAST_CCIFast)[1] < -100
                   	                &&(ToTime(Time[0]) >= StartTime && ToTime(Time[0]) <= EndTime))	
    				{		
                		EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "LongEntry");
    					
    				}
    				
    				//Exit
    				if (Position.MarketPosition == MarketPosition.Long)
    				{	
    					//Count of bars since open entry to actual bar
    					int BarsFromEntryLong = BarsSinceEntry(0, "LongEntry", 0);   
    					//Number of highest LicoSafeZone.DnSafeZonePlot since open entry
    					int MaxSZLong = HighestBar(LicoSafeZone(TFAST_EMASlow, TFAST_EMAFast,0,true).DnSafeZonePlot, BarsFromEntryLong);  
    					//Price of highest LicoSafeZone.DnSafeZonePlot since open entry
    					double LongSL = LicoSafeZone(Close, TFAST_EMASlow, TFAST_EMAFast,0,true).DnSafeZonePlot[MaxSZLong] + -1 * TickSize;  
    					
    					if (Low[0] <= LongSL)
    					{
                 			ExitLongStop(LongSL, "LongExit", "LongEntry");
    					}
    				}	
    			#endregion
    Attached Files
    Last edited by licovata; 03-02-2012, 06:54 AM.

    #2
    Welcome to our forums here licovata - would the code work as you expect in realtime / Market Replay testing with your CalculateOnBarClose set to false as you show here?



    The reason I'm asking is, in backtesting you only have access to your primary series (200 tick here) OHLCV info and thus intrabar updates could not be used per default, in other words - CalculateOnBarClose would be true all the time here.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thank you for answer. It means, when I will test it on historical data, I will never get the exit stop price (LongSL)? I tried it on market replay data, but strategy did not work – entry condition was fullfilled, but not executed. Otherwise, is the code written correct?

      if (Position.MarketPosition == MarketPosition.Flat
      && CCI(TFAST_CCISlow)[0] > 0
      && CCI(TFAST_CCIFast)[1] < -100
      && CCI(TFAST_CCIFast)[0] > CCI(TFAST_CCIFast)[1]
      && EMA(TFAST_EMAFast)[0] > EMA(TFAST_EMASlow)[0]
      && Low[0] <= EMA(TFAST_EMAFast)[0]
      && EMA(CCI(BarsArray[1],TSLOW_CCI), TSLOW_EMAFast)[TSLOW_Bar] >
      EMA(CCI(BarsArray[1],TSLOW_CCI), TSLOW_EMASlow)[TSLOW_Bar]
      &&(ToTime(Time[0]) >= StartTime && ToTime(Time[0]) <= EndTime))
      {
      EnterLongStop(DefaultQuantity, High[0] + 1 * TickSize, "LongEntry");

      }

      Comment


        #4
        That's correct, it would not exit intrabar in backtesting then unless you created the conditions with a timeframe would that have more resolution, so for example a 20 tick one or comparable...the code snippet looks ok to me, were you seeing really no order placed in replay or did the order perhaps just expire at the end of the bar it was placed on?

        You would see this best with our TraceOrders debugging aid option -

        BertrandNinjaTrader Customer Service

        Comment


          #5
          Thank you for tip. I added other timeframe (1tick) and set condition: When Opens[1tick] <= LongSL then ExitLong. Now it works correct.
          Thank you for your help once again. :-)

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by fwendolynlpxz, Today, 05:19 AM
          0 responses
          3 views
          0 likes
          Last Post fwendolynlpxz  
          Started by traderqz, Yesterday, 12:06 AM
          11 responses
          28 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by PaulMohn, Today, 03:49 AM
          0 responses
          8 views
          0 likes
          Last Post PaulMohn  
          Started by inanazsocial, Today, 01:15 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by rocketman7, Today, 02:12 AM
          0 responses
          11 views
          0 likes
          Last Post rocketman7  
          Working...
          X