Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order NOT filled

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

    Order NOT filled

    I have a simple strategy doing the following:
    1. If the current close price is lower than the current lowest value, set the new lowest value to the close price.
    2. If the current close price is 100 ticks higher than the lowest value, enter a long order with a StopLoss and ProfitTarget.
    3. If the SL or PT is hit, reset the lowest value.
    Below is the code snippet:

    Code:
    public class myStrategy : Stragety
    {
            private double Lowest=double.MaxValue;
            private inOrder=false;
    
            //Blah blah blah...
    
    }
    
    protected override void OnBarUpdate()
    {
            if(!inOrder)
            {
                    if(Close[0]<Lowest) Lowest=Close[0];
                    else if(Close[0]-Lowest>100*TickSize)
                    {
                            SetProfitTarget("Long1",CalculationMode.Price, Close[0]+10*TickSize);
    			SetStopLoss("Long1",CalculationMode.Price, Close[0]-10*TickSize,false);
    			EnterLong(Convert.ToInt32(DefaultQuantity), "Long1");
                            inOrder=true;
                    }
            }
    }
    
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
            if(Position.MarketPosition==MarketPosition.Flat)
            {
                    Lowest=double.MaxValue;
                    inOrder=false;
            }
    }
    So according to this strategy, if I exit the order and the market is still going up, it would place another order once the closing price is 100 ticks higher the lowest value again! And it would place another order if the market hit the bottom and come back up again!
    BUT it didn't happen that way!!! The strategy only place an order EVERY ONCE IN A LONG WHILE!!! And it's NOT from the lowest value where I want it to be!!!
    PLEASE tell me where did I do wrong and how to fix it!!!
    Thank you very VERY much! God bless you!!!
    Last edited by YoutingChu; 07-16-2018, 01:39 AM.

    #2
    Hello YoutingChu,

    Thanks for your post.

    In the If statement, you are showing a ";" at the end which terminates the if statement meaning it does not have any influence on the subsequent use the of the actions:

    if(Close[0]<Lowest) Lowest=Close[0];
    else if(Close[0]-Lowest>100*TickSize)

    typically an if-else structure would look more like:

    if (condition(s))
    {
    action 1 ;
    action 2 ;
    etc;
    }
    else if (condition(s))
    {
    action 3 ;
    action 4;
    etc;
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I had moved Lowest=Close[0]; inside the {} and it still produce the same result! So I think it's the algorithm that went wrong! Please help me out! Thank you very much!!!

      Comment


        #4
        Hello YoutingChu,

        Thanks for your reply.

        I misread your code, the line if(Close[0]<Lowest) Lowest=Close[0]; is formatted correctly

        Can you provide a charted example of where "...it I exit the order and the market is still going up, it would place another order once the closing price is 100 ticks higher the lowest value again! And it would place another order if the market hit the bottom and come back up again!" ?
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by pjsmith, Today, 01:00 AM
        1 response
        8 views
        0 likes
        Last Post NT-Roland  
        Started by alejandro888, Yesterday, 08:41 PM
        0 responses
        8 views
        0 likes
        Last Post alejandro888  
        Started by UltraNIX, Today, 02:14 AM
        0 responses
        4 views
        0 likes
        Last Post UltraNIX  
        Started by augustfay, Yesterday, 12:06 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by klaus w, Yesterday, 12:13 PM
        2 responses
        24 views
        0 likes
        Last Post klaus w
        by klaus w
         
        Working...
        X