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 zstheorist, Today, 07:52 PM
    0 responses
    5 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    150 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Started by mattbsea, Today, 05:44 PM
    0 responses
    6 views
    0 likes
    Last Post mattbsea  
    Started by RideMe, 04-07-2024, 04:54 PM
    6 responses
    33 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by tkaboris, Today, 05:13 PM
    0 responses
    6 views
    0 likes
    Last Post tkaboris  
    Working...
    X