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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    45 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    22 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 06-17-2026, 10:32 AM
    0 responses
    14 views
    0 likes
    Last Post CaptainJack  
    Started by kinfxhk, 06-17-2026, 04:15 AM
    0 responses
    20 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 06-17-2026, 04:06 AM
    0 responses
    22 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Working...
    X