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

calling indicator from a strategy

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

    calling indicator from a strategy

    Hi,

    I have written an indicator as follows -

    protected override void OnBarUpdate()
    {
    if (CurrentBar<2)return;

    if (FirstTickOfBar)
    {
    priorBarLongDIBS=false;
    priorBarShortDIBS=false;
    }
    if (High[1]<=High[2] && Low[1]>=Low[2]&& Close[0]>CurrentDayOHL().CurrentOpen[0] && Close[0]>High[1] && priorBarLongDIBS==false)
    {
    priorBarLongDIBS=true;
    DIBSLong[1]=Low[1]-10*TickSize;
    }

    if (High[1]<=High[2] && Low[1]>=Low[2] && Close[0]<CurrentDayOHL().CurrentOpen[0] && Close[0]<Low[1] && priorBarShortDIBS==false)
    {
    priorBarShortDIBS=true;
    DIBSShort[1]=High[1]+10*TickSize;
    }
    }

    I am trying to access the condition of break of the inside bar on the long side and trying to enter a long order as below..

    protected override void Initialize()
    {
    CalculateOnBarClose = false;
    SetTrailStop(CalculationMode.Ticks, 20);
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    bool orderPlaced=false;

    if (CurrentBar<2)return;

    if (FirstTickOfBar)
    {
    orderPlaced=false;
    }

    if (orderPlaced==false && DIBSBars(1).DIBSLong[1]<=Close[0])
    {
    orderPlaced=true;
    //enter order
    entryOrder=EnterLong(10000, "DIBSEntry");
    }
    }

    The value DIBSBars(1).DIBSLong[1] seems to be equal to Close[1]. Please help me with where I am messing up..

    #2
    Eklavya, your indicator will hold whatever value you tell it to. If DIBSLong is a plot, it should be set like this:
    Code:
    DIBSLong.Set(Low[1]-10*TickSize)
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      Eklavya, your indicator will hold whatever value you tell it to. If DIBSLong is a plot, it should be set like this:
      Code:
      DIBSLong.Set(Low[1]-10*TickSize)
      Hi Austin,

      Thanks. However my issue is that I want to set the plot only when I have an inside bar that breaks out in a particular direction during the subsequent bar. So the plot must be null for those bars that are not inside bars and are not broken to the upside during the subsequent bar. How can I do that with the set statement?

      So in the above statement, if Bar[1] is an inside bar, the plot must be set to (Low[1]-10*TickSize) only when the inside bar is broken on the upside during the current bar.

      Please advice.

      Comment


        #4
        If a plot is not set, NinjaTrader will automatically enter the close price of the current bar into the plot. This would explain why you see the close prices. If you want a plot to be "null", you must set it to 0 or some other value you can quickly identify. Not setting a plot actually results in that plot obtaining the close price, which seems to be the problem in your situation.

        When creating bool-ish type indicators, I was always a fan of setting the plot to 1 when something important happened (like a break out to the upside), and setting it to 0 for every other bar.
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Davidtowleii, Today, 12:15 AM
        0 responses
        1 view
        0 likes
        Last Post Davidtowleii  
        Started by guillembm, Yesterday, 11:25 AM
        2 responses
        9 views
        0 likes
        Last Post guillembm  
        Started by junkone, 04-21-2024, 07:17 AM
        9 responses
        68 views
        0 likes
        Last Post jeronymite  
        Started by trilliantrader, 04-18-2024, 08:16 AM
        4 responses
        20 views
        0 likes
        Last Post trilliantrader  
        Started by mgco4you, Yesterday, 09:46 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X