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.

    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 -

        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 argusthome, 03-08-2026, 10:06 AM
          0 responses
          95 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          50 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          31 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          36 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          72 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X