Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Store the current time whenever there is an order and refer to it later on

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

    Store the current time whenever there is an order and refer to it later on

    Hi,
    I am developing a strategy that has multiple entries.

    At the same time the BarsSinceEntry feature is not working properly, because it only counts the barssincentry of the very first order.

    Since I am likely to have 20..and 30 orders at the same time, I is not feasible for me to name each different order...in order to be able to refer to each one individually with the BarsSinceEntry

    This is why I decided to store the current time as a variable whenever an order is placed, and then to add a switch that would turn on/off trading as a whole in case the live current time[x amount of bars ago] < than the stored current time.

    I am trying with the following code, but I am having difficulties.
    Whenever I make an order, I store it with the following:
    ToTime(Time[0]) = ToTime(LastHour, LastMinute, 0);


    and then I run onbarupdate

    if (ToTime(Time[MinBarsForBuy]) >= ToTime(LastHour, LastMinute, 0))

    ...turn on trading

    I think I am messing something up, because I can't compile and I get an error "Left hand side of an assignment needs to be a property, a variable or indexer"


    Please help!

    #2
    Hello nikolaalx,

    Thanks for your post.

    It is possible to have BarsSinceEntry()/BarsSinceExit() apply to a specific order when using unique signal names.

    My suggestion is, if you plan to have a lot of entries at the same time, use a variable that increments on each new order.

    for example:
    In Initialize():
    private int ordersCount = 0;

    In OnBarUpdate():
    if (/* entry conditions */)
    {
    ordersCount++;
    EnterLong(1, "entry"+ordersCount.ToString());
    }

    Then you can use "entry"+n where n is the order number you are looking for.


    Regarding the time and error you are getting, it is with the following code:
    ToTime(Time[0]) = ToTime(LastHour, LastMinute, 0);

    On the left, you call a function that returns the integer of Time[0]. In the center you are calling an assignment (a single '=' is how to assign a variable). You cannot assign a value to a function that returns a value.

    You need to create a variable and store the value to a variable.

    Or are you trying to make an comparison? If so, you need '==' for 'is equal to'.

    http://msdn.microsoft.com/en-us/library/6a71f45d.aspx
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    67 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    41 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    24 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    27 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    53 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X