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 NullPointStrategies, Today, 05:17 AM
0 responses
50 views
0 likes
Last Post NullPointStrategies  
Started by argusthome, 03-08-2026, 10:06 AM
0 responses
126 views
0 likes
Last Post argusthome  
Started by NabilKhattabi, 03-06-2026, 11:18 AM
0 responses
69 views
0 likes
Last Post NabilKhattabi  
Started by Deep42, 03-06-2026, 12:28 AM
0 responses
42 views
0 likes
Last Post Deep42
by Deep42
 
Started by TheRealMorford, 03-05-2026, 06:15 PM
0 responses
46 views
0 likes
Last Post TheRealMorford  
Working...
X