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

How can I put the percentage of profit in the construction?

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

    How can I put the percentage of profit in the construction?



    Hello everyone, the idea is that when the order enters the zero candle, the stop will be placed on the mentioned candle, but how can I set the profit to double the last candle? Any 1-1 ratio or the ratio that interests me.
    Thank you so much.​

    #2
    Hello zakari,

    By zero candle do you mean the current bar, 0 bars ago?

    By double the last candle, do you mean you want the close price of the previous bar (bars ago [1]) multiplied by 2?

    So if the close of the previous bar is 1500, you want to calculate this multiplied by 2 to get 3000?

    Code:
    if (CurrentBar > 1)
        Print(string.Format("{0} | Close[1]: {1} * 2 = {2}", Time[0], Close[1], (Close[1] * 2)));
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thanks for your reply
      well,
      I have this strategy here
      Depend on price break EMA 21
      I already have a stop loss order below the entry candle
      But what I need is a stop profit order that should be equal to the size of the entry candle
      Meaning 1 stop loss order to 1 take profit order.
      The text of the strategy is as follows:​

      Comment


        #4
        region Using declarations
        using System;
        using System.Collections.Generic;
        using System.ComponentModel;
        using System.ComponentModel.DataAnnotations;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Windows;
        using System.Windows.Input;
        using System.Windows.Media;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Gui;
        using NinjaTrader.Gui.Chart;
        using NinjaTrader.Gui.SuperDom;
        using NinjaTrader.Gui.Tools;
        using NinjaTrader.Data;
        using NinjaTrader.NinjaScript;
        using NinjaTrader.Core.FloatingPoint;
        using NinjaTrader.NinjaScript.Indicators;
        using NinjaTrader.NinjaScript.DrawingTools;
        #endregion

        //This namespace holds Strategies in this folder and is required. Do not change it.
        namespace NinjaTrader.NinjaScript.Strategies
        {
        public class PriceCrossEMA21 : Strategy
        {
        private EMA EMA1;

        private List<int> entryList = new List<int>();

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Strategy here.";
        Name = "PriceCrossEMA21";
        Calculate = Calculate.OnBarClose;
        EntriesPerDirection = 1;
        EntryHandling = EntryHandling.AllEntries;
        IsExitOnSessionCloseStrategy = true;
        ExitOnSessionCloseSeconds = 30;
        IsFillLimitOnTouch = false;
        MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
        OrderFillResolution = OrderFillResolution.Standard;
        Slippage = 0;
        StartBehavior = StartBehavior.WaitUntilFlat;
        TimeInForce = TimeInForce.Gtc;
        TraceOrders = false;
        RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
        StopTargetHandling = StopTargetHandling.PerEntryExecution;
        BarsRequiredToTrade = 20;
        // Disable this property for performance gains in Strategy Analyzer optimizations
        // See the Help Guide for additional information
        IsInstantiatedOnEachOptimizationIteration = true;
        }
        else if (State == State.Configure)
        {
        }
        else if (State == State.DataLoaded)
        {
        EMA1 = EMA(Close, 21);
        EMA1.Plots[0].Brush = Brushes.Red;
        AddChartIndicator(EMA1);
        }
        }

        protected override void OnBarUpdate()
        {
        if (BarsInProgress != 0)
        return;

        if (CurrentBars[0] < 1)
        return;

        // Set 1
        if (CrossBelow(Close, EMA1, 1))
        {
        Draw.RiskReward(this, @"EMA2150 Risk Reward_1 " + Convert.ToString(CurrentBars[0]), true, 1, Close[0], 1, (High[0] + (1 * TickSize)) , 1, true);
        EnterShort(Convert.ToInt32(DefaultQuantity), "MyShortEntry" + CurrentBar);
        entryList.Add(CurrentBar);
        SetStopLoss("MyShortEntry" + CurrentBar, CalculationMode.Price,(High [0] + 0.5), false);
        }

        // Set 2
        if (CrossAbove(Close, EMA1, 1))
        {
        Draw.RiskReward(this, @"EMA2150 Risk Reward_1 " + Convert.ToString(CurrentBars[0]), true, 1, Close[0], 1, (Low[0] + (1 * TickSize)) , 1, true);
        EnterLong(Convert.ToInt32(DefaultQuantity), "MyLongEntry" + CurrentBar);
        entryList.Add(CurrentBar);
        SetStopLoss("MyLongEntry" + CurrentBar, CalculationMode.Price,(Low [0] - 0.5), false);
        }

        }
        }
        }

        Comment


          #5
          Hello zakari,

          But what I need is a stop profit order that should be equal to the size of the entry candle
          May I have you clarify what this means?

          You want a stop price calculated to the current price minus the difference of the high to low of the most recently closed bar?

          Instead of using general words, what is the specific calculation you want?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Well, what I mean by that is:

            If it's a long order, I want the profit target to be equal to The body of the last closing candle plus the lower wick minus the upper wick.

            Comment


              #7
              Hello zakari,

              I want the profit target to be equal to The body of the last closing candle plus the lower wick minus the upper wick.
              I'm reading this as I want the limit price to be High[1] - Low[1] + Low[0] - High[0].

              To clarify, you want the Close[0] minus the difference of the High[1] minus Low[1] (the height of the previous bar) plus Low[0] - High[0] (the height of the current bar)?

              Close[0] - (High[1] - Low[1]) + ([Low[0] - High[0])
              Last edited by NinjaTrader_ChelseaB; 11-02-2022, 04:43 PM.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by carnitron, Today, 08:42 PM
              0 responses
              5 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Today, 07:51 PM
              0 responses
              6 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,974 views
              3 likes
              Last Post jhudas88  
              Started by rbeckmann05, Today, 06:48 PM
              0 responses
              8 views
              0 likes
              Last Post rbeckmann05  
              Started by rhyminkevin, Today, 04:58 PM
              4 responses
              58 views
              0 likes
              Last Post dp8282
              by dp8282
               
              Working...
              X