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 algospoke, Yesterday, 06:40 PM
      2 responses
      23 views
      0 likes
      Last Post algospoke  
      Started by ghoul, Today, 06:02 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      45 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      22 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      181 views
      0 likes
      Last Post jeronymite  
      Working...
      X