• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with order entry logic

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

    Problem with order entry logic

    Building a strategy with the Strategy Builder with three unique orders.
    The default parameters as follows:
    Entry1 (E1) = default 0 minimum 0
    Entry2 (E2) = default 0 minimum 0
    Entry3 (E3) = default 0 minimum 0

    With trailing stops and profit levels for each.
    .
    All works well with various amounts of values from 1+ in each entry

    The issue is when "0" is used as the position size in any of the entries an order of "1" still occurs for EACH individual entry whether in the backtest OR live.

    Would really appreciate some insight.
    Thanks

    Below is the code:

    if (State == State.SetDefaults)
    {
    Description = @"Trying to find reason for additional entries";
    Name = "Three3entry";
    Calculate = Calculate.OnEachTick;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.UniqueEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = true;
    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;
    Stop1 = 25;
    Profit1 = 100;
    Stop2 = 25;
    Profit2 = 30;
    E1 = 0;
    E2 = 0;
    E3 = 0;
    Profit3 = 60;
    Stop3 = 25;

    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 60);
    }
    else if (State == State.DataLoaded)
    {
    RSI1 = RSI(Close, x, x);
    MACD1 = MACD(Closes[x],x, x, x);
    RSI1.Plots[0].Brush = Brushes.DodgerBlue;
    RSI1.Plots[1].Brush = Brushes.Goldenrod;
    AddChartIndicator(RSI1);
    SetProfitTarget(@"E1", CalculationMode.Ticks, Profit1);
    SetTrailStop(@"E1", CalculationMode.Ticks, Stop1, false);
    SetProfitTarget(@"E2", CalculationMode.Ticks, Profit2);
    SetTrailStop(@"E2", CalculationMode.Ticks, Stop2, false);
    SetProfitTarget(@"E3", CalculationMode.Ticks, Profit3);
    SetTrailStop(@"E3", CalculationMode.Ticks, Stop3, false);
    }
    }

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

    if (CurrentBars[0] < 3
    || CurrentBars[1] < 0)
    return;

    // Set 1
    if ((CrossAbove(RSI1.Default, RSI1.Avg, 3))
    && (MACD1.Default[0] > MACD1.Avg[0])
    && (Position.MarketPosition == MarketPosition.Flat))
    {
    Draw.ArrowUp(this, @"UP. " + Convert.ToString(CurrentBars[0]), false, 0, (Low[0] + (-4 * TickSize)) , Brushes.Lime);
    EnterLong(Convert.ToInt32(E1), @"E1");
    EnterLong(Convert.ToInt32(E2), @"E2");
    EnterLong(Convert.ToInt32(E3), @"E3");
    }

    // Set 2
    if ((CrossBelow(RSI1.Default, RSI1.Avg, 3))
    && (MACD1.Default[0] < MACD1.Avg[0])
    && (Position.MarketPosition == MarketPosition.Flat))
    {
    Draw.ArrowDown(this, @"DN. " + Convert.ToString(CurrentBars[0]), false, 0, (High[0] + (4 * TickSize)) , Brushes.Red);
    EnterShort(Convert.ToInt32(E1), @"E1");
    EnterShort(Convert.ToInt32(E2), @"E2");
    EnterShort(Convert.ToInt32(E3), @"E3");
    }

    Here are the Region Properties
    }
    #region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Stop1", Description="Stop1", Order=1, GroupName="Parameters")]
    public int Stop1
    { get; set; }

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

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

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

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="E2", Description="E2", Order=5, GroupName="Parameters")]
    public int E2
    { get; set; }

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="E3", Description="E3", Order=6, GroupName="Parameters")]
    public int E3
    { get; set; }

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="Profit3", Description="Profit3", Order=7, GroupName="Parameters")]
    public int Profit3
    { get; set; }

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

    [NinjaScriptProperty]
    [Range(0, int.MaxValue)]
    [Display(Name="E1", Description="E1", Order=9, GroupName="Parameters")]
    public int E1
    { get; set; }
    #endregion

    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by aviat72, 04-26-2020, 09:41 PM
10 responses
89 views
0 likes
Last Post kissandfly  
Started by healthooa, Today, 01:28 AM
0 responses
7 views
0 likes
Last Post healthooa  
Started by superkolleech, Today, 12:46 AM
0 responses
8 views
0 likes
Last Post superkolleech  
Started by harjinderjit, Yesterday, 08:24 PM
0 responses
20 views
0 likes
Last Post harjinderjit  
Started by Againmain1, Yesterday, 03:04 AM
1 response
26 views
1 like
Last Post NinjaTrader_ShawnB  
Working...
X