Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple Script for Scaling in/out

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

    Simple Script for Scaling in/out

    Hi Ninjas,

    I've coded this simple script that seems to do the job of scaling in/out positions with managed orders. I've tried in a couple backtest and it seems to work fine. Anyway it'd be great if anybody of support team checks it out in case of some kind of potential error.

    Having in mind that with this code, the property EntriesPerDirection must set accordingly. A note: Z in the code is an integer number that it goes from - 5 to +5.

    Code:
    if (Position.MarketPosition == MarketPosition.Flat) 					
    {					
    	if(z>0 )				
    	{				
    		EnterLong(z*20000); 			
    	}				
    	if(z<0 )				
    	{				
    		EnterShort(-z*20000); 			
    	}				
    }					
    if (Position.MarketPosition == MarketPosition.Long) 					
    {					
    	if(z>0 )				
    	{				
    		if(z*20000>Position.Quantity )			
    		{			
    			EnterLong(z*20000-Position.Quantity); 		
    		}			
    		if(z*20000<Position.Quantity )			
    		{			
    			ExitLong(Position.Quantity-z*20000); 		
    		}			
    	}				
    	if(z==0 )				
    	{				
    		ExitLong(Position.Quantity); 			
    	}				
    	if(z<0 )				
    	{				
    		EnterShort(-z*20000); 			
    	}				
    }					
    if (Position.MarketPosition == MarketPosition.Short) 					
    {					
    	if(z>0 )				
    	{				
    		EnterLong(z*20000); 			
    	}				
    	if(z==0 )				
    	{				
    		ExitShort(Position.Quantity); 			
    	}				
    	if(z<0 )				
    	{				
    		if(-z*20000>Position.Quantity )			
    		{			
    			EnterShort(-z*20000-Position.Quantity); 		
    		}			
    		if(-z*20000<Position.Quantity )			
    		{			
    			ExitShort(Position.Quantity+z*20000); 		
    		}			
    	}				
    }
    Thanks
    Last edited by pstrusi; 11-14-2013, 06:44 PM.

    #2
    pstrusi, this is unfortunately nothing we could deny or confirm working as you would expect, if it backtests correct for you the next would be Market Replay and live simulated trading to further verify your custom code.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      It should work, but its a risky piece of code.
      In managed orders, its always suggested to give signal names to each order, and exit the orders using those signal names.
      In fast market, this code may fail and generate errors, IMHO.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      3 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      6 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X