Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Scalability without ATM

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

    #16
    Alright.
    I have now removed the SetTrailStop().
    However, there are some more issues emerging in simulated trading.

    Pls look at the following part of the code extracted:

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (CrossAbove(EMA(Typical, X), EMA(Typical, Z), 1)
    && CrossAbove(CCI(Typical, C), -200, 100))
    {
    PN = Close[1];
    AX = GetCurrentAsk();

    if (Historical)
    return;

    if (MarketPosition.Flat == Position.MarketPosition
    && (AX-PN)/PN*100 <= SN)

    {
    entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, SOQ, GetCurrentAsk(), 0, "", "EnterLong");
    }
    }

    protected override void OnExecution(IExecution execution)
    {

    if (execution.Name == "EnterLong"
    && execution.Order == entryOrder && execution.Order.OrderState == OrderState.Filled)
    {
    Print("OnExecution PositionQuantity: "+Position.Quantity+" Total orders needed: "+TQ);

    AX = GetCurrentAsk();

    if( Position.Quantity < TQ
    && (AX-PN)/PN*100 <= SN)

    {

    // Send as many entries to get the total quantity filled.
    for(int i = TQ - Position.Quantity; i>0 ; i--)
    {
    entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, SOQ, GetCurrentAsk(), 0, "", "EnterLongAgain"+i);
    }
    }
    }

    -------------------

    Now here, what if, the Order is fired but is in State Working.
    In that case i want to fill the following logic:
    If
    execution.Order.OrderState == OrderState.Working

    AX = GetCurrentAsk();

    if (AX-PN)/PN*100 <= SN)

    {
    entryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, SOQ, GetCurrentAsk(), 0, "", "EnterLong");
    }

    --
    No, where do i put this for both Entry as well as Exit Conditions?

    The entire code in .cs is attached for reference.
    Attached Files

    Comment


      #17
      Hello piyushc,

      Thank you for your response.

      This should be fin to place within the OnExecution() method in your code.

      Comment


        #18
        i can't find enough Help on its Syntax.

        So Now under OnExecution(), i have added

        if (execution.Name == "EnterLong" || "EnterLongAgain"+i
        && execution.Order == entryOrder && execution.Order.OrderState == OrderState.Working)
        {
        AX = GetCurrentAsk();

        if ((AX-PN)/PN*100 <= SN)
        {
        ChangeOrder(entryOrder, SOQ, GetCurrentAsk(), 0);
        }
        }
        --
        But obviously, this is not correct:
        1. Marked in Red = Error = it can't read "i". i wanted to cover all orders of EnterLong and all the subsequent ones.
        2. Marked In Blue = Error = what exactly am i supposed to put at the place of IOrder?

        Comment


          #19
          Hey Patrick
          Can you pls help me on that??
          Thanks

          Comment


            #20
            Hello piyushc,

            Thank you for your response.

            Can you attach your most recently updated version of the strategy without changing the code to compile without errors? Please go to (My) Documents\NinjaTrader 7\bin\Custom\Strategy > then attach the .cs file.

            Comment


              #21
              .cs file attached.
              Attached Files

              Comment


                #22
                Hello piyushc,

                Thank you for your response.

                You will need to assign a value for these signalNames you are trying to call. 'i' is not defined as a value outside of the "// Send as many entries to get the total quantity filled." for loop you created. You would need to create another for loop to assign i to a valid value for the signalNames:
                Code:
                			for(int i = Position.Quantity; i > 0; i--)
                			{
                			if (execution.Name == "EnterLongAgain"+i
                				&& execution.Order == entryOrder && execution.Order.OrderState == OrderState.Working)
                			{
                				AX = GetCurrentAsk();
                				
                				if ((AX-PN)/PN*100 <= SN)
                				{
                					ChangeOrder(entryOrder, SOQ, GetCurrentAsk(), 0);
                				}
                			}
                			}

                Comment


                  #23
                  I have made the changes in the strategy & it did not show up any errors on debug.
                  The new .cs file has been attached.
                  However, the ChangeOrder is not happening at all.
                  Following are the issues:
                  1. All Orders after signal generation get fired together.
                  As per the Strategy, the orders should fire one by one. If at any point of time, one order is pending, it should modify only that one on an incoming tick & OnExecution should move to next order for the same instrument.
                  2. No ChangeOrder happening:
                  ChangeOrder should work for all pending orders, if it meets the criteria, on an incoming tick.
                  But the orders just sit there and wait to be executed.
                  ChangeOrder doesn't happen even after Bar Closes.
                  So what will instigate the ChangeOrder?

                  Attachments:
                  .cs file
                  log file
                  Attached Files

                  Comment


                    #24
                    Hi Patrick

                    Can't see you online still.
                    Anyways, i have made a slight change in the code, so now i'm attaching the fresh cs file
                    & the log file thereof.
                    Ignore the previous files but issues stand at that.

                    Thanks
                    Attached Files

                    Comment


                      #25
                      Instead of OnExecution(), what if we use OnMarketData() ??
                      CPU intensive yes, but will it solve the problem completely?
                      Moreover, how CPU/RAM intensive are we talking about for a Non-HFT strategy, provided there could be minimum 1 to max 100 orders pending, looking for best bid/ask?
                      An i7(2ndGen)+4GB RAM will serve the purpose?

                      Comment


                        #26
                        You are checking for the working status in OnExecution() which is not the most effective way to check OrderState.

                        OnOrderUpdate is going to be the best option for detecting those OrderStates.

                        http://www.ninjatrader.com/support/h...rderupdate.htm
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #27
                          Between OnOrderUpdate() & OnMarketData(), which one is a better choice?

                          Comment


                            #28
                            You will want to use OnOrderUpdate() as it is designed to track your Order States and gets called when an order is updated. OnExecution() will only get called when a fill has happened.

                            You can OnMarketData() but you will need to create an IOrder handling for that method.
                            Cal H.NinjaTrader Customer Service

                            Comment


                              #29
                              I have modified the strategy to OnOrderUpdate() & it doesn't show up any errors on Compile.
                              But when i run it on MarketReplayConnection, it hangs as soon as the first order initiates.

                              The Order reaches the State Working. NT then hangs and there is a pop-up showing either Debug or Close Program. NT then shuts down.

                              New cs file attached.
                              Attached Files
                              Last edited by piyushc; 03-02-2014, 04:29 AM.

                              Comment


                                #30
                                I just ran it Live on Simulation.
                                The Orders that went through were fine but some got stuck at OrderState.PendingChange.

                                Pls chk the log after 9.36 AM
                                Attached Files

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                671 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                379 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                111 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                575 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                582 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X