Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 sidlercom80, 10-28-2023, 08:49 AM
        172 responses
        2,279 views
        0 likes
        Last Post sidlercom80  
        Started by Irukandji, Yesterday, 02:53 AM
        2 responses
        17 views
        0 likes
        Last Post Irukandji  
        Started by adeelshahzad, Today, 03:54 AM
        0 responses
        4 views
        0 likes
        Last Post adeelshahzad  
        Started by Barry Milan, Yesterday, 10:35 PM
        3 responses
        13 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by WeyldFalcon, 12-10-2020, 06:48 PM
        14 responses
        1,431 views
        0 likes
        Last Post Handclap0241  
        Working...
        X