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.
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); } } }
Comment