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

on price change second series condition within on bar close entry strategy

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

    on price change second series condition within on bar close entry strategy

    Hi, I'm working on a strategy that enters trades on a 1 minute time frame based on the 1 minute current bar's closing condition, paired with a 60 minute prior bar's closing condition. I'd like to try the strategy with the 1 minute's close paired with the current 60 minute's condition (e.g. the 60 minute bar that my 1 minute bar is within, is currently a green 60 minute candle. How might i write that inside the onbar update code?

    Here's the version with the prior 60 minute bar

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 60);
    AddDataSeries(Data.BarsPeriodType.Minute, 30);
    }
    else if (State == State.DataLoaded)
    {
    SMA1 = SMA(Close, Convert.ToInt32(StopSma));
    SMA1.Plots[0].Brush = Brushes.Goldenrod;
    AddChartIndicator(SMA1);
    SetProfitTarget("", CalculationMode.Ticks, 200);
    SetStopLoss("", CalculationMode.Ticks, 50, false);
    }
    }

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

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

    // Set 1
    if ((Close[0] > Open[0])
    && (Closes[1][1] > Opens[1][1])
    && (Close[1] < Open[1]))
    {
    EnterLongLimit(Convert.ToInt32(DefaultQuantity), Median[0], "");
    }

    thanks,
    David

    #2
    Hello trader3000a,

    I see that you are using both series in your condition, using Closes[BarsInProgress][BarsAgo] is the way you could pick which data series you are using data from.

    Are you seeing a problem with the code or what specific question did you have surrounding the condition you provided?

    One suggestion that I could make here would be to use Market orders by using EnterLong, that could be used for testing to ensure you are seeing entries. Limit orders have the chance to expire if not filled within 1 bar.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by algospoke, 04-17-2024, 06:40 PM
    6 responses
    49 views
    0 likes
    Last Post algospoke  
    Started by arvidvanstaey, Today, 02:19 PM
    4 responses
    11 views
    0 likes
    Last Post arvidvanstaey  
    Started by samish18, 04-17-2024, 08:57 AM
    16 responses
    61 views
    0 likes
    Last Post samish18  
    Started by jordanq2, Today, 03:10 PM
    2 responses
    9 views
    0 likes
    Last Post jordanq2  
    Started by traderqz, Today, 12:06 AM
    10 responses
    21 views
    0 likes
    Last Post traderqz  
    Working...
    X