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

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.
    Test the bool type, which holds true or false. A bool occupies 1 byte of memory.



    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 rocketman7, Today, 01:00 AM
    0 responses
    1 view
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    27 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 04-23-2024, 09:53 PM
    2 responses
    74 views
    0 likes
    Last Post wzgy0920  
    Started by Kensonprib, 04-28-2021, 10:11 AM
    5 responses
    193 views
    0 likes
    Last Post Hasadafa  
    Working...
    X