Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Working with differents setstops..

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

    Working with differents setstops..

    I am merging two different strategies in one script/strategy.
    First srategy carries positions from day to day, second is a day trade strategy.
    Each has completely different stop losses and profit target levels.

    first use this:
    SetStopLoss("", CalculationMode.Percent, stopLevelMovel*3.0, false);
    SetProfitTarget("", CalculationMode.Percent, stopGainNumber*2.4);
    second this:
    SetStopLoss("", CalculationMode.Percent, stopLevelMovelI*1.4, false);
    SetProfitTarget("", CalculationMode.Percent, stopGainNumberI*1.3);

    How can I make the strategy understands which stops will be used?
    note: each strategy generates orders with differents names.

    #2
    Hello dafonseca,

    Thank you for writing in. You are already using the correct method definitions to accomplish this:
    Code:
    SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)
    SetProfitTarget(string fromEntrySignal, CalculationMode mode, double value)
    Rather than using a blank string ("") for the fromEntrySignal variable, you need to setup actual entry signal names which differ between the two strategies. Then you need to line up all your NinjaScript methods to the appropriate signal names.

    The signal name is defined in your entry or exit method call. A list of the different entry and exit methods is available here: http://ninjatrader.com/support/helpG...er_methods.htm

    So as an example you would have something like the following:
    Code:
    protected override void Initialize()
    {
    SetStopLoss([B]"LongTermTrade"[/B], CalculationMode.Percent, stopLevelMovel*3.0, false);
    SetProfitTarget([B]"LongTermTrade"[/B], CalculationMode.Percent, stopGainNumber*2.4);
    SetStopLoss([B]"ShortTermTrade"[/B], CalculationMode.Percent, stopLevelMovelI*1.4, false);
    SetProfitTarget([B]"ShortTermTrade"[/B], CalculationMode.Percent, stopGainNumberI*1.3);
    }
    protected override void OnBarUpdate()
    {
    if(CrossAbove(SMA(100), SMA(300), 0))
    {
    EnterLong([B]"LongTermTrade"[/B]); //Long Term Strategy Trade
    }
    if(CrossAbove(SMA(5), SMA(25), 0))
    {
    EnterLong([B]"ShortTermTrade"[/B]); //Short Term Strategy Trade
    }
    }
    Please let me know if you require further clarification or if I may be of further assistance.
    Michael M.NinjaTrader Quality Assurance

    Comment


      #3
      Great!
      But I have another situation here.
      each strategy must recognizes whether it is short or long anytime.
      Sometimes, position is flat since strat1 is short, and strat2 is long.
      in that way, so I can not use : if (Position.MarketPosition == MarketPosition.Long) to control new orders, since it makes no more sense.
      Instead, I am trying to set variables (below) to control all positions per strategies and directions.But it seems not working, Any clue or observation?

      . positionNowSYV = GetAtmStrategyPositionQuantity("InRangeSYV");
      positionNowLYV = GetAtmStrategyPositionQuantity("InRangeLYV");
      positionNowSYVDif = GetAtmStrategyPositionQuantity("InRangeSYVdif");
      positionNowLYVDif = GetAtmStrategyPositionQuantity("InRangeLYVdif");
      positionNowIntradayLI = GetAtmStrategyPositionQuantity("IntradayLI");
      positionNowIntradaySI = GetAtmStrategyPositionQuantity("IntradaySI");
      Last edited by dafonseca; 11-23-2015, 08:38 AM.

      Comment


        #4
        Hello dafonseca,

        Unless the names you have provided in your GetAtmStrategyPositionQuantity() method calls are AtmStrategyIds of orders submitted with the AtmStrategyCreate() method, GetAtmStrategyPositionQuantity() will not work.

        What you could do is create some sort of counter that will keep track of how much quantity you have over each side of the market.

        As an example, to keep track of long positions, you can increment the counter in the OnExecution() method (http://ninjatrader.com/support/helpG...xecution.htm):
        Code:
        private int longQuantity = 0;
        
        protected override OnExecution(IExecution execution)
        {
             if (execution.Order != null && execution.Order.OrderState == OrderState.Filled && execution.MarketPosition == MarketPosition.Long)
                  longQuantity += execution.Quantity; 
        }
        Anytime you exit a long position, you'll want to make sure you decrement the counter.

        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Interesting.
          But What about stop losses?How would strategy knows that a stop was from strat1 or strat2 (same for profit taking).
          As I understood the name of the order would be "Stop loss" and "Profit target". How can I distinguish between them?

          Comment


            #6
            Hello dafonseca,

            You can utilize the order's FromEntrySignal name to differentiate the different targets.

            Example:
            Code:
            protected override void OnExecution(IExecution execution)
            {
                 if (execution.Order != null && execution.Order.FromEntrySignal == "theEntry") // replace "theEntry" with your entry order signal name
                      // logic
            }
            Please, let us know if we may be of further assistance.
            Zachary G.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            638 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            569 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            572 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X