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;
    }

    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!" ?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        46 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        126 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        66 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X