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

Strategy : Buy/Sell signal on Chart

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

    Strategy : Buy/Sell signal on Chart

    Hi,

    I am trying to understand NinjaScript and its working.
    I have written a very basic logic which should show arrow on chart whenever the condition matches.

    Code:
            protected override void OnBarUpdate()
            {
                if(High[2] > High[0] && High[1] > High[0]){
                    Draw.ArrowUp(this, "tag1", true, 0, Low[0] - TickSize, Brushes.White);
                }
            }
    I am following below steps.
    1) Compile NinjaScript
    2) Open Chart for a stock
    3) Open Strategy and add the Strategy which I just added and compiled.

    At this point I am expecting that the Arrow Up symbol should appear on all the historic bars where the condition is matching.
    But that's not happening.

    Am I missing something here ?
    Or is it that the Arrow Up would appear for all future bars once the strategy is applied and will not appear for past bars ?

    Please share your inputs..

    Thanks in advance!!

    #2
    Hello leo11,

    If a tag name is re-used the object is re-drawn in the new location at the new price. If the tag name is unique a new object is drawn using the provided price and time.

    Have you used a unique tag name or re-used a tag name?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello leo11,

      If a tag name is re-used the object is re-drawn in the new location at the new price. If the tag name is unique a new object is drawn using the provided price and time.

      Have you used a unique tag name or re-used a tag name?
      HI NinjaTrader_ChelseaB,

      Thanks for your response.
      I am not aware of concept of tags yet and simply used the Arrow Up logic that I found on some help forum.

      I have modified the tag name and it should now definitely be unique.
      Draw.ArrowUp(this, "tag1_657657", true, 0, Low[0] - TickSize, Brushes.White);

      Tried it and don't see any Arrow up on Price chart.
      You said new object will be drawn. Will it be drawn over candlestick/price chart ?

      I am not getting a clue here. Is there any good document or video I can refer to, which shows how to display strategy buy and sell signals over a price chart.

      Regards,

      Comment


        #4
        SampleMACrossOver

        Just had a look at SampleMACrossOver strategy which is supplied OOTB with NinjaTrader.
        Looking at below logic(AddChartIndicator) it looks like that smaFast and smaSlow lines would appear over the chart when this Strategy is added to a chart.

        Code:
                    else if (State == State.DataLoaded)
                    {
                        smaFast = SMA(Fast);
                        smaSlow = SMA(Slow);
        
                        smaFast.Plots[0].Brush = Brushes.Goldenrod;
                        smaSlow.Plots[0].Brush = Brushes.SeaGreen;
        
                        AddChartIndicator(smaFast);
                        AddChartIndicator(smaSlow);
                    }
        But again this is not happening. And I only see price bars on the chart and MA indicators are not added.
        Will really appreciate any help on this.

        Regards,
        Last edited by leo11; 08-12-2018, 03:37 AM.

        Comment


          #5
          Hello leo11,

          Thank you for the reply.

          In regard to the drawing object, can you right click on the chart and select Drawing Tools -> Drawing Objects to see if the object is listed? This will help determine if the arrow was drawn at all, or if it is missing.

          The tag you have used, while that is a unique tag is not what Chelsea had mentioned in regard to being unique. That would need to use a variable such as CurrentBar:

          Code:
          Draw.ArrowUp(this, "tag1" + CurrentBar, true, 0, Low[0] - TickSize, Brushes.White);
          This would mean on each new bar, a new tag is used and it is no longer a static value. This is how to have historical drawings in addition to the most recent bar. The code you have now is likely only drawing on the most recent bar to the very right of the chart.

          Below is a short video of how this would be added with the Strategy Builder.


          Regarding the SampleMACrossOver, are you applying the strategy directly to the chart and also enabling it with the Enabled checkbox? The SampleMACrossOver should show MA plots when applied directly to a chart. If you are applying items to the control center strategies tab, that would make them run in the background instead of on the chart directly.

          We do have a video that covers basic strategy development which you can find here: https://youtu.be/HCyt90GAs9k

          This does not contain drawings specifically but would be helpful to ensure you are following the necessary steps to enable a script and have it run.

          I look forward to being of further assistance.
          Last edited by NinjaTrader_ChelseaB; 09-19-2022, 08:30 AM.
          JesseNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by alifarahani, Today, 09:40 AM
          6 responses
          36 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          14 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X