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

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 WHICKED, Today, 12:45 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by samish18, Today, 01:01 PM
        0 responses
        5 views
        0 likes
        Last Post samish18  
        Started by WHICKED, Today, 12:56 PM
        0 responses
        7 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by Spiderbird, Today, 12:15 PM
        2 responses
        11 views
        0 likes
        Last Post Spiderbird  
        Started by FrazMann, Today, 11:21 AM
        2 responses
        8 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Working...
        X