Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

When an order entry to the market really?

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

    When an order entry to the market really?

    Hi everyone,

    i've a very strange problem in my strategy:

    i build a multifaces strategy, that use a different methods to entry to the market.For this reason i need a semaphores method for manage all of the different kind of conditions... that not run!

    here the sample code:

    Code:
    if (MarketPosition.Flat){ //i'm not in market
    
    reset running vars 
    ( method1IsRunning=false; method2IsRunning=false;   globals  variables)
     
    if (conditionToEntryOnMarket)  {
          entryOrder = entry long 
          set my running variable at true ( method1IsRunning=true; )
    }
    
    
    }
    
    else { //i'm in market
    
    if (method1IsRunning){
         manageChangeDynamicallyStopLossForMethod1
         manageChangeDynamicallyProfitTargetForMethod1
    }
    
    if (method2IsRunning){
         manageChangeDynamicallyStopLossForMethod2
         manageChangeDynamicallyProfitTargetForMethod2
    }
    
    
    }

    the trouble:
    when i enter long (the condition is true , enter in if statement, enter long and set the var at true), the next onBarUpdate REENTER ON "NOT IN MARKET" (MarketPosition is Flat and not Long!!) instead enter on other part of if (in MArket), and for this reason all og my isRunning variable reset to false.

    Result: when i enter long, when really enter into the market my runnning variables is all set on false (and there isn't anyone set at true) , and i don't have the stopLoss and Profit target
    managed in personalized manner (what i want)..

    There is another method to detect me if i enter an order or not??

    Hope in a reply, and sorry for my basic english

    wyatt

    #2
    a clarification: posted code stay in "onBarUpdate"method...

    Comment


      #3
      Hi Wyatt, thanks for the post - so the issue is that method1 is being run but method2, not, correct? If that's true then I don't see any statement setting your bool method2Running to true.

      Also: the position update can take on bar update to show up, if you would like to get to the exact order execution event that would be possible via IOrders in the OnExecution() method -

      Comment


        #4
        no,the number of method is random in this topic... in my own strategy i've 5 method, but i don't want to write all... it's only an example for explain the problem... i'have different isRunningVariables for every method (isRunningVariableForMethod1,isRunningVariableForM ethod2...isRunningVariableForMethod_n)...

        referred to prior logic in 2 topics ago:

        when i EnterLong (i'm not in market yet), i set my running var (referred to one method, such as method1,method2.. method_n) at true value.In this mode, when i enter in the section "InMarket" i can choose what's strategy use for change stoploss and profittarget dynamically (with if statement if(isMethod1Running) or the if statement if(isMethod2Running)) ...


        there is a schema for view the lifecycle of the methods of ninjatrader's strategy?
        Such as:

        1st) Initialize
        2nd) OnBarUpdate
        2rd) OnExecution

        ....

        Comment


          #5
          Thanks for the clarification - you can see an overview over all event driven methods here - http://www.ninjatrader.com/support/h...n_program2.htm

          I would suggest to simplify your code as much as possible and then add a unique print for method you want to get called and observe the timing from (also include the variable state for your bools), then run the strategy for example in Market Replay and watch the output window - this would give you the best idea then hopefully where you would need to apply changes.

          Comment


            #6
            ok,

            but..
            when i execute EnterLong() or EnterlongLimit(), in the next cycle of onBarUpdate i can be not in market yet (marketposition != Long) , is it right?
            and when is called onExceution on my order i'm sure that the my initial call at EnterLong() is really excuted?

            thanks bertrand!

            Comment


              #7
              That's correct - if you need to access the very moment the order executes, then OnExecution() is your method.

              Comment


                #8
                ok thanks!!
                last questions,
                so, how I can check if an order arrive in market?

                Code:
                protected override void OnExecution(IExecution execution)
                {
                    if (entryOrder != null && entryOrder == execution.Order){
                         Print(execution.ToString());
                         isRunningWithMethod1 = true; 
                     }
                }
                where entryOrder is my order returned by EnterLong()?

                I'm not very "studied" on financial order/market, where i find the meaning of filled order, or others state (the life cycle of an order to market) ?

                thanks!

                Comment


                  #9
                  Hi Wyatt, this would be the best sample here to look into - http://www.ninjatrader.com/support/f...ead.php?t=7499

                  You would do then something if the execution.Order.OrderState reports filled in this method -

                  if (execution.Order.OrderState == OrderState.Filled)
                  {
                  start your custom exit order handling here...
                  }

                  Comment


                    #10
                    Fantastic!

                    thanks Bertrand!

                    wy

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    647 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    368 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    108 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    572 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    573 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X