Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Duplication of order messages

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

    Duplication of order messages

    Hi All,

    I'm sure the answer is already there somewhere but despite looking for hours and trying several things I was not able to do it. So I hope one of you can be so kind to help this rookie. Thanks in advance!:

    I run below code on the 1 minute data. The problem is that once the buy/sell conditions are met for as example 15 bars after each other, I receive 15 emails while I would like to receive only one email. Basically my question is how can I make sure that if the order that is placed during the current bar update, is equal to the open order, I do not receive an email. Or even better not a new order is placed at all.

    Using the EntryOrderBuy.StopPrice function seems to not work when the code starts running and there's no order placed yet. if (EntryOrderBuy.StopPrice || EntryOrderBuy = null) also doesn't work as it also fails when there's no order placed yet.

    Code:
    protected override void Initialize()
    {
        CalculateOnBarClose = true;
    	SetStopLoss( CalculationMode.Ticks, (profitPips * RiskReward));
    	SetProfitTarget( CalculationMode.Ticks, profitPips );
    	ExitOnClose = false;
    }
    
    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>        		
    
    private IOrder EntryOrderBuy = null;
    private IOrder EntryOrderSell = null;
    
    protected override void OnBarUpdate()
    {
    	//CALCS
    	double HighOverPeriod = MAX(High, timeBack)[0];
    	double LowOverPeriod = MIN(Low, timeBack)[0];
    							
    	double EntryPriceBuy = (Math.Floor(HighOverPeriod / RoundingOn)) * RoundingOn;
    	double EntryPriceSell = (Math.Ceiling(LowOverPeriod / RoundingOn)) * RoundingOn;
    
    	//BUY CONDITION
    	if (Math.Abs(HighOverPeriod - EntryPriceBuy) < DiffRoundedAndReal)
    	{				
    		if (Math.Abs(EntryPriceBuy - Close[0]) > DiffEntryAndClose)						
    		{
    			string MailBody = ("Buy " + EntryPriceBuy);
    			SendMail("[email protected]", "[email protected]", Instrument.FullName, MailBody);
    			EntryOrderBuy = EnterLongStop(0, true, 10000, EntryPriceBuy, "BuyStop");
    		}
    	}			
    	
    	//SELL CONDITION
    	if (Math.Abs(LowOverPeriod - EntryPriceSell) < DiffRoundedAndReal)
    	{												
    		if (Math.Abs(EntryPriceSell - Close[0]) > DiffEntryAndClose)						
    		{
    			string MailBody = ("Sell " + EntryPriceSell);
    			SendMail("[email protected]", "[email protected]", Instrument.FullName, MailBody);
    			EntryOrderSell = EnterShortStop(0, true, 10000, EntryPriceSell, "SellStop");
    		}
    	}
    }

    #2
    Hello ADiTheMAN,

    The script is sending the email on each bar the condition is true. This means you would need to modify the condition so that this is not true on every bar where there is a working order.

    You could use a bool that flips when the entry order is placed, and flipped back when the exit order fills.



    You could use an IOrder variable to track the order and only allow a new order to be placed when the IOrder is in a working state.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    556 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X