Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss/SetProfitTarget

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

    SetStopLoss/SetProfitTarget

    I am using these 2 calls in the code below, where I take a position using an explicit name in the appropriate overload of EnterLong and on occasions exit that position using the corresponding overload of Exitlong. Somehow the Stop and ProfitTaget calls are not activating. For example, for the below code, my stop is 045% and profit is 0.70%. This is yielding traces that have a PnL > 2% and in MFE > ProfitTarget and MAE > StopLoss, that should not happen right?


    Code:
    				bool flowCondition = flowStats.Score[0] > avgFlowstats.UpperbandScore[0];
    
                    // SELL
                    if ( flowCondition && !upcandleCondition)
                    {
                        Print("$SELL signal ");
                        Print(flowStats.Score[0] + " score > " + avgFlowstats.LowerbandScore[0]);
                        Print(Volume[0] + " VOl > " + avgFlowstats.UpperbandVolume[0]);
                        Print(flowStats.NumTrades[0] + " # > " + avgFlowstats.UpperbandNumTrades[0]);
                        string entryName = "";
                        if (Position.MarketPosition != MarketPosition.Long)
                        {
                            entryName = "short" + (Position.Quantity + 1).ToString();
                            PrintA("issuing " + entryName);
                            IOrder order = EnterShort(DefaultQuantity, entryName);
                            if (order != null)
                            {
                                Print("SELL:" + order.ToString());
                                ht.Add(entryName, DefaultQuantity);
                            }
                            else
                                Print(Time[0].ToString() + "--EnterShort: NULL Order");
    
                            Print("setting stop and target for " + entryName);
                            SetStopLoss(entryName, CalculationMode.Percent, 0.45, false);
                            SetProfitTarget(entryName, CalculationMode.Percent, 0.70);
    
    
                        }
                        else // long
                        {
                            entryName = "long" + Position.Quantity.ToString();
                            if (ht.ContainsKey(entryName))
                            {
                                PrintA("issuing " + "exit-" + entryName);
                                IOrder order = ExitLong(DefaultQuantity, "exit-" + entryName, entryName);
                                if (order != null)
                                {
                                    //PrintA(order.ToString());
                                    ht.Add("exit-" + entryName, DefaultQuantity);
    
                                }
                                else
                                    PrintA(Time[0].ToString() + "--ExitLong: NULL Order");
    
                            }
                            else
                                Print(entryName + "  doesn't exist");
                        }
    					
                    }
    				
    				flowCondition = flowStats.Score[0] < avgFlowstats.LowerbandScore[0];
    
    
                    // BUY
                    if ( flowCondition && upcandleCondition)
                    {
                        Print("$BUY signal ");
                        Print(flowStats.Score[0] + " score < " + avgFlowstats.LowerbandScore[0]);
                        Print(Volume[0] + " VOl > " + avgFlowstats.UpperbandVolume[0]);
                        Print(flowStats.NumTrades[0] + " # > " + avgFlowstats.UpperbandNumTrades[0]);
    					
    					string entryName = "";
    
                        if (Position.MarketPosition != MarketPosition.Short)
                        {
                            entryName = "long" + (Position.Quantity + 1).ToString();
                            Print("issuing " + entryName);
                            IOrder order = EnterLong(DefaultQuantity, entryName);
                            if (order != null)
                            {
                                Print("BUY:" + order.ToString());
                                ht.Add(entryName, DefaultQuantity);
                            }
                            else
                                Print(Time[0].ToString() + "--EnterLong: NULL Order");
    
                            Print("setting stop and target for " + entryName);
                            SetStopLoss(entryName, CalculationMode.Percent, 0.45, false);
                            SetProfitTarget(entryName, CalculationMode.Percent, 0.70);
    
                        }
                        else // short
                        {
                            entryName = "short" + Position.Quantity.ToString();
                            if (ht.ContainsKey(entryName))
                            {
                                PrintA("issuing " + "exit-" + entryName);
                                IOrder order = ExitShort(DefaultQuantity, "exit-" + entryName, entryName);
                                if (order != null)
                                {
                                    Print("Adding exit-"  + entryName);
                                    ht.Add("exit-" + entryName, DefaultQuantity);
                                }
                                else
                                    PrintA(Time[0].ToString() + "--ExitShort: NULL Order");
    
                            }
                            else
                                Print(entryName + "  doesn't exist");
                        }

    #2
    Newworldguy,

    Thank you for your post.

    Are you looking to do .4% or 40% as the Profit Target?
    Is this logic true for the Stop Loss as well?
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      I am looking for 0.45% stop loss and 0.7% profit target.

      Please sen me an example of how exactly I can specify the various calculation modes, the help section and documentation is insufficient. I appreciate your effort.
      Last edited by newworldguy; 05-29-2014, 03:55 AM.

      Comment


        #4
        Newworldguy,

        The percent for the Set() Orders is on 0 - 1 setting.

        Example -
        50% = .5

        0.45% = .0045
        0.7% = .007
        Cal H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        66 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        149 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        99 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        286 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X