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

Queries on a setting up a strategy

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

    Queries on a setting up a strategy

    Hi,

    this is my first post in here. I have few questions.

    1. I need the strategy to run on a 5 minute candles with 10EMA. Where can I mention the TF in the script. It is running on 1min TF.

    I have added this line Add(PeriodType.Minute, 5); inside the initialize. It seems to be not working. Is there any other location, where I need to specify the TF?

    2. Does the Now function needs any conversion? I have used the below code to exit the position at 3.15IST, but it did not exit.

    TimeSpan Exittime=new TimeSpan(15,15,00);

    (Position.MarketPosition == MarketPosition.Long && (now > Exittime))

    3. How can I capture the entry price for my order and set a target of 0.05% on the entry price.

    Thanks,
    Vamsi.

    #2
    Hello thenvk,

    Thanks for your post and welcome to the NinjaTrader forums!

    If I understand correctly, you have a 1 minute bars chart and are adding a 5 minute data series. In the script, you want to reference a 10 period EMA based on the 5 minute candles.

    The statement in Initialize() of Add(PeriodType.Minute, 5); is correct and will make a 5 minute data series of the same instrument available.

    Please note that you will need to make references in the OnbarUpdate to access the 5 minute data. Also an important concept is that both the 1 minute data series of the chart AND the 5 minute added data series will both call the OnBarUpdate seperately. This means, for example, that when the 1 minute bars calls OnBarBarUpdate() that High[0] will refer to the High of the just closed 1 minute bar, when the 5 minute bar calls OnBarUpdate High[0] would now refer to the 5 minute bar High. There are a number of other considerations and answers to most of your questions in this section of the helpguide which we highly recommend you review: https://ninjatrader.com/support/help...nstruments.htm

    Here is a short example of coding you might use in the OnbarUpdate():

    if (CurrentBars[0] < 10 || CurrentBars[1] < 2) return; // do not process until enough bars loaded

    if (BarsInProgress !=0) return; // only process the chart bars

    if (Close[0] > EMA(Closes[1], 10)[0]) // if the close is greater than the 10 period ema on the 5 minute series
    {
    //do something
    }


    Please see the previous link as it contains an explanation of these references.


    Regarding time, you might use DateTime.Now.

    Alternatively, for example:

    if (Position.MarketPosition == MarketPosition.Long && ToTime(Time[0]) >= ToTime(15, 15, 0))
    where Time[0] is the close time of the 1 minute bar

    References:
    Time: https://ninjatrader.com/support/help.../nt7/?time.htm
    ToTime: https://ninjatrader.com/support/help...t7/?totime.htm

    After the order has been filled, you can get the entry price from Position.AvgPrice: Reference: https://ninjatrader.com/support/help.../?avgprice.htm
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mestor, 03-10-2023, 01:50 AM
    16 responses
    388 views
    0 likes
    Last Post z.franck  
    Started by rtwave, 04-12-2024, 09:30 AM
    4 responses
    31 views
    0 likes
    Last Post rtwave
    by rtwave
     
    Started by yertle, Yesterday, 08:38 AM
    7 responses
    29 views
    0 likes
    Last Post yertle
    by yertle
     
    Started by bmartz, 03-12-2024, 06:12 AM
    2 responses
    22 views
    0 likes
    Last Post bmartz
    by bmartz
     
    Started by funk10101, Today, 12:02 AM
    0 responses
    7 views
    0 likes
    Last Post funk10101  
    Working...
    X