Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder two instruments not work always

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

  • NinjaTrader_Jesse
    replied
    Hello walter739,

    If you are trying to have the strategies submit at exactly the same time that would be a situation where using a single strategy would be better for that use case. A multi series strategy can submit to a specific instruments so you could submit two orders at the same time without having to deal with differences in processing by adding additional series. You may still see the fill with some spacing depending on the current market and when the order is filled. As these are separate instruments we should not in general expect identical fills except for in historical data where processing is a guaranteed order. There is information about this concept in the following link: https://ninjatrader.com/support/help...ionInformation

    I look forward to being of further assistance.

    Leave a comment:


  • walter739
    replied
    Hello Jesse.

    Are you specifically expecting that the entry will happen on both instruments at the exact same time, one entry per script? Yes Jesse i wish in both strategys entrys in the same time with conditions in SPY.in both,

    In realtime you may see that one instrument has slower or faster data which could result in different fills.The fills is no my problem, The time for the fill yes. In ExitEs entry one bar late

    can you tell me what primary series is being used for each strategy? One minute in both Strategys

    I annex two charts

    Chart SPY with Strategy ExitSPY, you can see entry bar 9.32

    Chart ES with Strategy ExitES you can see entry bar 9.33. I wish entry in 9.32

    Please i must wrong my code in ExitES but i try differents ways and can not solved.

    Regards
    Attached Files

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello walter739,

    I tried the script you provided however I was unable to see what I believe you had described here. Are you specifically expecting that the entry will happen on both instruments at the exact same time, one entry per script? If so I believe we would really only expect that in historical where the data is already known and everything is being processed in a fixed way. In realtime you may see that one instrument has slower or faster data which could result in different fills.

    If I have not understood correctly can you tell me what primary series is being used for each strategy? Also if you have an image comparing one of the late fills vs your expectation that may help.

    I look forward to being of further assistance.

    Leave a comment:


  • walter739
    replied
    Hello Jesse

    This code work fine in realt time with SPY

    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Day, 1);
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Close, Convert.ToInt32(Emaperiod1));
    RSI1 = RSI(Closes[1], 14, 3);
    ADX1 = ADX(Close, Convert.ToInt32(ADXperiod1));
    EMA1.Plots[0].Brush = Brushes.Goldenrod;
    ADX1.Plots[0].Brush = Brushes.DarkCyan;
    AddChartIndicator(EMA1);
    AddChartIndicator(ADX1);
    SetProfitTarget(@"long1", CalculationMode.Percent, Profit1);
    SetStopLoss(@"long1", CalculationMode.Percent, Loss1, false);
    SetProfitTarget(@"long2", CalculationMode.Currency, Profit1);
    SetStopLoss(@"long2", CalculationMode.Percent, Loss1, false);
    SetProfitTarget(@"short1", CalculationMode.Percent, Profit1);
    SetStopLoss(@"short1", CalculationMode.Percent, Loss1, false);
    }
    }

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

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

    // Set 1
    if ((CrossAbove(Close, EMA1, 1))
    && (Times[0][0].TimeOfDay >= Timeopen.TimeOfDay)
    && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
    && (RSI1.Default[0] < RSIshort1)
    && (ADX1[0] < Adxup))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"long1");
    Print(Convert.ToString(Times[0][0]) + @" ADX " + Convert.ToString(ADX1[0]) + @" RSI " + Convert.ToString(RSI1.Avg[0]) + @" EMA " + Convert.ToString(EMA1[0]) + @" Price " + Convert.ToString(Close[0]) + " " + Convert.ToString(Position.MarketPosition));
    }




    And this code work fine in market replay and historical, but not in real time Is the same but i use to entry in ES with conditions of SPY, in real time entry one bar late. Please do you see my mistake in the code.

    }
    else if (State == State.Configure)
    {
    AddDataSeries("SPY", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
    AddDataSeries("SPY", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Closes[2], Convert.ToInt32(Emaperiod1));
    RSI1 = RSI(Closes[1], 14, 3);
    ADX1 = ADX(Closes[2], Convert.ToInt32(ADXperiod1));
    SetProfitTarget(@"long1", CalculationMode.Percent, Profit1);
    SetStopLoss(@"long1", CalculationMode.Percent, Loss1, false);
    SetProfitTarget(@"long2", CalculationMode.Percent, Profit1);
    SetStopLoss(@"long2", CalculationMode.Percent, Loss1, false);
    SetProfitTarget(@"short1", CalculationMode.Percent, Profit1);
    SetStopLoss(@"short1", CalculationMode.Percent, Loss1, false);
    }
    }

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

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

    // Set 1
    if ((CrossAbove(Closes[2], EMA1, 1))
    && (Times[0][0].TimeOfDay >= Timeopen.TimeOfDay)
    && (Times[0][0].TimeOfDay <= Timeclose.TimeOfDay)
    && (RSI1.Default[0] < RSIshort1)
    && (ADX1[0] < Adxup))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"long1");
    Print(Convert.ToString(Times[0][0]) + @" ADX " + Convert.ToString(ADX1[0]) + @" RSI " + Convert.ToString(RSI1.Avg[0]) + @" EMA " + Convert.ToString(EMA1[0]) + @" Price " + Convert.ToString(Close[0]) + " " + Convert.ToString(Position.MarketPosition));
    }

    Leave a comment:


  • walter739
    replied
    Hello Jesse, i add Print to see the ouput, and open one chart with SPY and ES 0920 below, Add both strategies to each symbol, and work perfect both, the ouput is the same in boths strategys. The same quantity of buy and sell in 200 days. All this in historical.

    I dont understand why in real time the ExitES is late one bar sometimes.

    I annex two strategys with Print command, you can see both work same bar in historical..

    Please what is wrong in my code?

    Regards
    Attached Files

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello walter739,

    Yes for the ExitES that uses multiple series so you would not be able to plot the indicators on the chart. You could instead use a set with a Print to output the indicator value to confirm when it becomes true or not. Comparing against a manually added indicator can have differences so it may not truly represent what the strategy is doing. The other strategy is using AddChartIndicator so that would represent what the strategy is seeing.

    I look forward to being of further assistance.



    Leave a comment:


  • walter739
    replied
    Hello Jesse, i cannot enable plot on chart in 2 Strategy ExitES. i think because have two instruments.

    I annex both strategys, please help me why reason the Strategy ExitES entry in the position one bar late, it is the most frequently error. In the strategy ExitSPY entry in the right moment always. Both strategys have the same conditions in reference to SPY.

    Regards
    Attached Files

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello walter739,

    If you are using the builder you can check the "Plot on chart" option when configuring the indicator in your conditions, that will automatically add the AddChartIndicator. It sounds like you are doing a manually added indicator comparison here so making sure the strategy instead adds its own indicator would be a good starting point.

    You can see an example of adding an indicator in the help guide, I would suggest just make a simple condition in the builder and enable plot on chart, then click View Code. That will be a little more complete and easier to see what was added. https://ninjatrader.com/support/help...htsub=addchart

    I look forward to being of further assistance.

    Leave a comment:


  • walter739
    replied
    Hello Jesse, I build my strategy in builder, i write my strategy 2 unlocked in the first post, but i dont see AddChartindicator, do you think this can be the problem?

    I run strategys in playback mode and work fine boths. But i dont find why reason the strategy 2 not work good in real time.


    Regards

    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello walter739,

    It sounds like the problem is that the logic is working differently in realtime or that what you are comparing against is different. Are you using AddChartIndicator from the strategy to add the indicators it used or are you comparing manually applied indicators? That may be one area where you can see a difference. Otherwise it sounds like the strategy evaluated differently in realtime than historical, to know why you would need to debug the strategy to find what value was different for the condition to change.

    I look forward to being of further assistance.

    Leave a comment:


  • walter739
    replied
    Helle Jesse thanks for answer.

    I have two strategys with same conditions.and both start wait until flat.

    The 1 strategy in SPY work good all day

    The 2 strategy in ES with conditions SPY not work fine, some times no entry the orders or entry one bar late.

    The 2 strategy when fail and not entry, i uncheck and check again int he control center and the position change and write the correct price of entry in past.

    For some reason not entry in the correct moment.

    Please help me with that error, maybe i this cannot work with that conditions in strategy builder.


    Regards


    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello walter739,


    I intend the strategy wait until flat, but when conditions in SPY are correct, begin in real time.
    These are conflicting ways to start. If you use historical data and wait until flat there is a chance the strategy will enter a historical position and then it will not start live. It will wait to exit that position and then start live after that. If the intention is to start immediately in live when you enable it you could use other start behaviors like immediately submit as you have selected. That also would generally entail your strategy either does not execute historical trades or if it does then it works with the start behavior being used so you can start in realtime. You generally need to read the start behavior descriptions to pair it with your strategy logic to see what would work best with what you made.
    https://ninjatrader.com/support/help...hlightsub=sync

    The picture you provided is not using WaitUntilFlat so I am unsure how that would be related. Sorry only i wish you see this parameters. I always use wait until flat.
    Thanks for clarifying that, in the future please take the screenshot with the settings you used to avoid any confusion.


    -Trading hours :US RTH equities ( i need this for EMA, all day in ES is different to SPY)
    -Bars required to trade: 47700 ( I need this for the RSI SPY daily, if i have less bars in minutes the RSI is not correct)
    These items are not necessarily relevant here. The amount of data will control the amount of times the straetgy can trade historically when you apply it, outside of that this does not affect the start behaviors.


    I look forward to being of further assistance.


    Leave a comment:


  • walter739
    replied
    Hello Jesse:

    Did you intend for the strategy to work only in realtime as soon as you enable it? I intend the strategy wait until flat, but when conditions in SPY are correct, begin in real time. That not happens in my stretegy with ES, only sometimes.. I dont understand why.

    The picture you provided is not using WaitUntilFlat so I am unsure how that would be related. Sorry only i wish you see this paramethers. I always use wait until flat.
    -Trading hours :US RTH equities ( i need this for EMA, all day in ES is different to SPY)
    -Bars requerid to trade: 47700 ( I need this for the RSI SPY daily, if i have less bars in minutes the RSI is not correct)

    Maybe this paramethers affect my strategy and i dont see how.

    I wish trade ES with conditions of the SPY, but only work sometimes, i have wrong something in my strategy.

    Regards


    Leave a comment:


  • NinjaTrader_Jesse
    replied
    Hello walter739,

    If the strategy is waiting until flat that is specifically caused with WaitUntilFlat being the start behavior. That would be because it placed a historical order and it is waiting to exit that order. Did you intend for the strategy to work only in realtime as soon as you enable it?

    The picture you provided is not using WaitUntilFlat so I am unsure how that would be related. Are you seeing that the strategy is yellow after enabling it?

    I look forward to being of further assistance.

    Leave a comment:


  • walter739
    replied
    Hello Jesse thanks for answer, sorry i not explain well.

    My strategy is buy and sell ES 09-20 with all conditions and indicators of the SPY (days and minutes)

    But for some reason when the condition apply in the SPY, dont work in my strategy with ES. stay in wait until flat or activate one bar forward. Other times in the day work well, .

    The same strategy only with buy and sell SPY work correclty all day.

    I annex my Strategy parameters, i dont know is this affect:

    -Trading hours :US RTH equities ( i need this for EMA, all day in ES is different to SPY)
    -Bars requerid to trade: 47700 ( I need this for the RSI SPY daily, if i have less bars in minutes the RSI is not correct)
    -Maybe the code in strategy builder is not correct. I use the strategy builder


    Please if you can help me to find my error, i appreciated.

    Regards
    Attached Files

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by forrestang, Yesterday, 02:18 PM
1 response
23 views
0 likes
Last Post NinjaTrader_Jason  
Started by bdelorm, Yesterday, 11:13 AM
1 response
38 views
0 likes
Last Post NinjaTrader_Jason  
Started by markyb0y, Yesterday, 10:04 AM
1 response
14 views
0 likes
Last Post NinjaTrader_Jason  
Started by pjptrading, Yesterday, 08:17 AM
1 response
15 views
0 likes
Last Post NinjaTrader_Jason  
Started by robertparlsa, Today, 12:03 AM
0 responses
5 views
0 likes
Last Post robertparlsa  
Working...
X