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

using multiple entry and exits

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

    using multiple entry and exits

    Hi,

    NT has a reference example here (http://ninjatrader.com/support/forum...ead.php?t=3225) about a strategy that uses multiple entry and exits. I am coding a strategy that also has multiple entry and exits and I am using

    EntryHandling = EntryHandling.UniqueEntries;

    as I want each entry/exit to generate its own orders.

    I have a question for which I will use the example that NT gave (in that link above) :

    This is a part of the NT reference code:

    protected override void OnBarUpdate()
    {
    // Entry Signal 1: If RSI value crosses above 20
    if (CrossAbove(RSI(RSI_Period, RSI_Smooth), 20, 1))
    {
    // Placing a string between the parenthesis allows you to give unique identifiers to your entries.
    EnterLong("RSI Entry");
    }
    // Exit Signal 1: If RSI value crosses below 80
    if (CrossBelow(RSI(RSI_Period, RSI_Smooth), 80, 1))
    ExitLong("RSI Entry");
    // Entry Signal 2: If SMA crosses above the current close
    if (CrossAbove(SMA(SMA_Period), Close, 1))
    EnterLong("SMA Entry");
    // Exit Signal 2: If SMA crosses below the current close
    if (CrossBelow(SMA(SMA_Period), Close, 1))
    ExitLong("SMA Entry");
    }
    Now in my own indicator, the EnterLong() / ExitLong() and EnterShort() / ExitShort() signals can take a while to occur initially when the strategy starts from CurrentBar = 0. So, instead of using CrossAbove() / CrossBelow() in my signals, I want to use a ">" or "<" operator, i.e.

    I want to use something along the lines of this (using NT's code as an example):

    if (Position.MarketPosition != MarketPosition.Long && RSI(RSI_Period, RSI_Smooth)[0] > 20)
    EnterLong("RSI Entry");
    if (Position.MarketPosition != MarketPosition.Long && SMA(SMA_Period)[0] > Close[0])
    EnterLong("SMA Entry");
    ....
    My question is:

    Since I am using multiple entry / exit signals (along with EntryHandling = EntryHandling.UniqueEntries;), it is not clear if Position.MarketPosition refers to the the RSI Entry or the SMA Entry .

    Would the correct approach be Positions[0] and Positions[1] like this?

    if (Positions[0].MarketPosition != MarketPosition.Long && RSI(RSI_Period, RSI_Smooth)[0] > 20)
    EnterLong("RSI Entry");
    if (Positions[1].MarketPosition != MarketPosition.Long && SMA(SMA_Period)[0] > Close[0])
    EnterLong("SMA Entry");
    ....
    But, the NT7 documentation https://ninjatrader.com/support/help...?positions.htm mentions that Positions should ONLY be used for executing orders against multiple instruments.

    How can I implement multiple entry/exit signals where each entry/exit need to check whether its Position is long / short / flat?
    Last edited by uday12; 02-18-2016, 03:16 PM.

    #2
    Hello uday12,

    Thank you for writing in.

    Position.MarketPosition would refer to the entire strategy position.

    If you wish to track multiple positions, you would need to add an additional data series and submit your other orders to that data series.

    You would then be able to utilize the Positions collection to keep track of each position.

    For more information about working with multiple timeframes or instruments, please take a look at this help guide link: https://ninjatrader.com/support/help...nstruments.htm
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kaywai, Today, 06:26 AM
    1 response
    6 views
    0 likes
    Last Post kaywai
    by kaywai
     
    Started by ct, 05-07-2023, 12:31 PM
    6 responses
    203 views
    0 likes
    Last Post wisconsinpat  
    Started by kevinenergy, 02-17-2023, 12:42 PM
    118 responses
    2,780 views
    1 like
    Last Post kevinenergy  
    Started by briansaul, Today, 05:31 AM
    0 responses
    10 views
    0 likes
    Last Post briansaul  
    Started by traderqz, Yesterday, 12:06 AM
    11 responses
    28 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X