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.

    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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      114 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      160 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      81 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      126 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      80 views
      0 likes
      Last Post PaulMohn  
      Working...
      X