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

Multi entry (scale in)

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

    Multi entry (scale in)

    Hi friends.

    hope someone can help me .

    i want for each entry signal 1 contract to add on my opsition.
    i have try some thing but i haved find any working solution.

    i work with ninjatrader strategy builder .

    if someone now how to add for each signal a contract more that would be very nice.


    public class BBBands : Strategy
    {
    private NinjaTrader.NinjaScript.Indicators.new.BBbands BBBands1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "BBBands";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlatSynchronizeAccount;
    TimeInForce = TimeInForce.Day;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Target = 30;
    Stop = 15;
    BBHalf = 66;
    BBDevi = 2.8;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    BBbands = BBbands(Close, Convert.ToInt32(BBHalf), NinjaTrader.Data.PriceType.close, BBdevi, true);
    BBbands1.Plots[0].Brush = Brushes.Red;
    BBbands1.Plots[1].Brush = Brushes.DarkGray;
    BBbands1.Plots[2].Brush = Brushes.Lime;
    BBbands1.Plots[3].Brush = Brushes.Red;
    BBbands1.Plots[4].Brush = Brushes.Lime;
    AddChartIndicator(BBbands1);
    SetStopLoss(CalculationMode.Ticks, Stop);
    SetProfitTarget("", CalculationMode.Ticks, Target);
    }
    }

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

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((Position.MarketPosition == MarketPosition.Flat)
    && (BBbands1.BullishMarker[0] != 0))
    {
    ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
    BackBrush = Brushes.Lime;
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 2
    if ((Position.MarketPosition == MarketPosition.Flat)
    && (BBbands1.BearishMarker[0] != 0))
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    BackBrush = Brushes.Crimson;
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 3
    if ((Position.MarketPosition == MarketPosition.Short)
    && (BBbands1.BullishMarker[0] != 0))
    {
    ExitShort(Convert.ToInt32(DefaultQuantity), "", "");
    BackBrush = Brushes.Lime;
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    // Set 4
    if ((Position.MarketPosition == MarketPosition.Long)
    && (BBbands1.BearishMarker[0] != 0))
    {
    ExitLong(Convert.ToInt32(DefaultQuantity), "", "");
    BackBrush = Brushes.Crimson;
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    }

    }

    region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Target", Order=1, GroupName="Parameters")]
    public int Target
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Stop", Order=2, GroupName="Parameters")]
    public int Stop
    { get; set; }

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="BBHalf", Description="BBbands Einstellung 1", Order=3, GroupName="Parameters")]
    public int BBHalf
    { get; set; }

    [NinjaScriptProperty]
    [Range(0, double.MaxValue)]
    [Display(Name="BBdevi", Description="BBbands Einstellung 2", Order=4, GroupName="Parameters")]
    public double BBdevi
    { get; set; }
    #endregion

    }
    }​​

    #2
    Hello nadire.sadiki60,

    Thanks for your post.

    I see that you are calling Entry methods and Exit methods in the same Set in your strategy. Entry and Exit methods should not be called in the same Set as this could cause issues to occur.

    To reverse the position of a strategy, simply call the Entry order method in the opposite direction as mentioned in the Managed Approach help guide page linked below.

    "Entry() methods will reverse the position automatically. For example if you are in a 1 contract long position and now call EnterShort() -> you will see 2 executions, one to close the prior long position and the other to get you into the desired 1 contract short position."

    Managed Approach: https://ninjatrader.com/support/help...d_approach.htm

    Scaling into a position is controlled with the signal names of your strategy, and properties EntryHandling and EntriesPerDirection.

    See this help guide page about Signal Names: https://ninjatrader.com/support/help...m#EntryMethods

    And, see this help guide page about FromSignalName used for Exit methods: https://ninjatrader.com/support/help...CloseAPosition

    This reference sample can help with scaling in and out of a strategy.
    https://ninjatrader.com/suppport/helpGuides/nt8/en-us/scaling_out_of_a_position.htm

    This sample can assist further with managing multiple exit/entry signals:
    https://ninjatrader.com/support/helpGuides/nt8/en-us/using_multiple_entry_exit_sign.htm

    Please let us know if we may be of further assistance to you.​
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      thank u very much i wil try it

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by swestendorf, Today, 11:14 AM
      2 responses
      5 views
      0 likes
      Last Post NinjaTrader_Kimberly  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      4 responses
      12 views
      0 likes
      Last Post xiinteractive  
      Started by Mupulen, Today, 11:26 AM
      0 responses
      1 view
      0 likes
      Last Post Mupulen
      by Mupulen
       
      Started by Sparkyboy, Today, 10:57 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Started by TheMarlin801, 10-13-2020, 01:40 AM
      21 responses
      3,917 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Working...
      X