Profile Picture

PositionSettings

Posted By ywlee 3 Years Ago
Message
Posted Friday July 25 2014
Hi

1/ Where do i put the PositionSettings object in the code? Is it under "public override void NewBar()" or "public override void Startup()". My PositionManager object is under the latter so I'm a bit confused.

2/ Can there be different PositionSettings in the code (eg. different PositionSettings applied to different Symbols).

Apologies if this question seems obvious to everyone.


Posted Friday July 25 2014
PositionSettings are used to create positions so technically they can be anywhere. You act on these settings via PositionManager outside of Startup. While it is typical to create PositionSettings just before placing an order, they can also be used in other ways. For example, on a system that executes against the SP500, you can go through each symbol and create a PositionSetting for each symbol where conditions for a trade are possible the next day. These can be stored in a list and certain parameters can be saved in the Tag of the PositionSetting to determine each Symbol’s priority in the system. The list can then then sorted in System.NewBar and only the top X number of Symbols can have orders placed.

Yes, you can create as many different PositionSettings as you want. The example in the 1st paragraph gives a good example of this.

The api is very flexible and you can pretty much do whatever you want. Although, I’m still waiting for RightEdge/Daniel to come out with a method to definitively determine the price on the following day. Maybe something like DefinitivePriceNextDay(Symbol) would be a good method signature. I’m just throwing out a feature idea.

Duane

Edited: Friday July 25 2014 by alpha23
Posted Monday July 28 2014
HI

I've edited the positionsettings code as follows with a time condition but nothing happens when the time condition is satisfied. I'm not sure if its my positionsettings() arguments thats wrong or the time condition format or something else.....

public override void Startup()
{
// Initialize
SystemParameters param = SystemData.SystemParameters;

//Datetime
datetimenow = DateTime.Now; // current date and time
datetimetrade = new DateTime(2014, 07, 20, 8, 35, 0); //date and time to execute trade

}
public override void NewBar()
{
PositionSettings ps = new PositionSettings();
ps.PositionType = PositionType.Long;
ps.OrderType = OrderType.Market;
ps.Size = 1000;
ps.BarsValid = 1;

// Process each new bar
if (!SystemData.InLeadBars)

{//Check for sufficient bars
IList pos = SystemData.PositionManager.GetOpenPositions(Symbol);
if (Bars.Count < 0)
return;

       {//
   if (datetimenow == datetimetrade)
   {//
   OpenPosition(ps);
   }
       }
}
}
}
Posted Monday July 28 2014
Check the time condition and open the position in public override NewTick. I assumed the above is only for a live system based on the comparison.

Edited: Monday July 28 2014 by alpha23
Posted Monday July 28 2014
I've changed it to NewTick as follows and tested the time condition against the current time but there are no trades executed nor errors.

public override void Startup()
{
// Initialize
SystemParameters param = SystemData.SystemParameters;

//Datetime
datetimenow = DateTime.Now; // current date and time
datetimetrade = new DateTime(2014, 07, 20, 8, 35, 0); //date and time to execute trade

}
public override void NewTick(BarData bar, TickData tick)
{
   PositionSettings ps = new PositionSettings();
   ps.PositionType = PositionType.Long;
   ps.OrderType = OrderType.Market;
   ps.Size = 1000;
   ps.BarsValid = 1;

// Process each new bar
if (!SystemData.InLeadBars)
   
      {//
      if (datetimenow == datetimetrade)
         {//
            OpenPosition(ps);
         }
      }   
}
Posted Tuesday July 29 2014
Is the above code for a live system or for backtesting?

You need to use the Visual Studio debugger and put a breakpoint at the comparison and the variable assignments to see how each are working. The if statement will probably never result in true for 2 reasons - DateTime.Now will never equal be equal to the past (unless your system clock is off by 9 days) and even if it was July 20th your code would require that the system be executed and the datetimenow assignment be at exactly 8:35:00.0000 (or whatever the system clock resolution is).
Posted Tuesday July 29 2014
Sorry forgot to mention that it is for a live system and not for backtesting.

The datetimetrade is adjusted to the correct time in the future.

Posted Friday August 01 2014
You really don't want to use DateTime.Now in your system.

You definitely don't want to have an exact comparison with the time from DateTime.Now. The resolution of the time is about 10 milliseconds, so unless your system is starting up in the window of about 10 milliseconds around the time you've specified, the condition will never be true.

Thanks,
Daniel


Similar Topics


Reading This Topic


2005-2017 © RightEdge Systems