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 charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    51 views
    0 likes
    Last Post charlesugo_1  
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    142 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    160 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    96 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    275 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Working...
    X