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

Entry Handling Problems

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

    Entry Handling Problems

    Hello,

    I am working on a strategy that has take profit 1 at 1:1 risk with 2:1 and b/e stop as a runner. However the code only seems to take on one contract per direction labeled "scalp", leaving the "runner" out. I have posted the relevant code for the task below. Any support here would be greatly appreciated.

    I have followed the examples NT has provided for working with multiple entries/exits to no avail.

    All entry conditions are working fine, just having issues with multiple contracts. Some entry logic was removed for simplicity.


    else if (State == State.DataLoaded)
    {
    SetProfitTarget("scalp", CalculationMode.Ticks, StopTicks);
    SetProfitTarget("runner", CalculationMode.Ticks, StopTicks * 2);

    SetStopLoss("scalp", CalculationMode.Ticks, StopTicks, false);
    }



    protected override void OnBarUpdate()
    {

    if (CurrentBar < BarsRequiredToTrade)
    return;

    MarketPosition macdBias = MacdBias();
    MarketPosition emaBias = EmaBias();

    if ((TriggerState >= 2)
    && (Position.MarketPosition == MarketPosition.Flat))
    {
    TriggerState = 0;
    }

    if (macdBias == MarketPosition.Long && emaBias == MarketPosition.Long && Position.MarketPosition == MarketPosition.Flat) {
    TriggerState = 1;
    EnterLong("scalp");
    EnterLong("runner");
    }
    else if (macdBias == MarketPosition.Short && emaBias == MarketPosition.Short && Position.MarketPosition == MarketPosition.Flat) {
    TriggerState = 1;
    EnterShort("scalp");
    EnterShort("runner");
    }


    if ((TriggerState == 1)
    && (Position.MarketPosition == MarketPosition.Long))
    {
    TriggerState = 2;
    StopPrice = (Position.AveragePrice + (StopTicks * TickSize)) ;
    TriggerPrice = (Position.AveragePrice + (StopTicks * TickSize)) ;

    }
    else if ((TriggerState == 1)
    && (Position.MarketPosition == MarketPosition.Short))
    {
    TriggerState = 2;
    StopPrice = (Position.AveragePrice + (StopTicks * TickSize)) ;
    TriggerPrice = (Position.AveragePrice - (StopTicks * TickSize)) ;
    }



    if ((TriggerState == 2)
    && (Close[0] >= TriggerPrice) && Position.MarketPosition == MarketPosition.Long)
    {
    TriggerState = 3;
    StopPrice = Position.AveragePrice + (beTicks * TickSize);
    }
    else if ((TriggerState == 2)
    && (Close[0] <= TriggerPrice) && Position.MarketPosition == MarketPosition.Short)
    {
    TriggerState = 3;
    StopPrice = Position.AveragePrice - (beTicks * TickSize);
    }



    if (TriggerState >= 2 && Position.MarketPosition == MarketPosition.Long)
    {
    SetStopLoss("runner", CalculationMode.Price, StopPrice, false);
    }
    else if (TriggerState >= 2 && Position.MarketPosition == MarketPosition.Short)
    {
    SetStopLoss("runner", CalculationMode.Price, StopPrice, false);
    }


    Thanks for taking the time to look at this!

    #2
    Hello cpbeamer,

    Have you set the entries per direction to 2 or the entry handling mode to UniqueEntries?




    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      So I enabled both and the problem still persists. The runner contract is immediately stopped out upon taking up the position. It seems like an issue with the B/E stop loss rather than anything else. However, this is exactly how the example code worked it so I am at a loss

      Comment


        #4
        Hello cpbeamer,

        Having the order submitted but immediately stopped out would be a different issue than you described in post 1. If the order is not submitted at all and only 1 order is submitted that would relate to the entries per direction. If the order is submitted by immediately stopped out then that would very likely be the price you had used. You could try using a Print here to output the prices that you calculated. Alternatively you could try using a different calculation mode to see if the order does not get immediately stopped out to confirm its related to the price used.


        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by chbruno, Today, 04:10 PM
        0 responses
        1 view
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        6 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by frslvr, 04-11-2024, 07:26 AM
        9 responses
        127 views
        1 like
        Last Post caryc123  
        Working...
        X