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

CALL indicator from strategy to pullscreenshots

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

    CALL indicator from strategy to pullscreenshots

    i updated the sample indicator to take screenshots every 4 hours. its event driven. i run my strategies on my chart. how can i call this indicator from my strategy to take screenshots at open and close of trades?
    Attached Files

    #2
    Hello junkone,

    Thank you for the post.

    Normally you would need to make the private void into public void however because this is being Hosted the ChartControl should be null when used from a strategy. This would be best moved into the strategy where you can use the ChartControl from the strategy where it is applied. An alternate could be to make an overload for the method which takes ChartControl and pass that from your strategy to the method so it can be used/not null. It may be just as easy to include this in the strategy and surround it in a region to hide it once complete.


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

    Comment


      #3
      is there a way to detect if its called from strategy or indicator as i like the overload idea better. i can check if its called from strategy and pass it on or if its called from indicator

      Comment


        #4
        Hello junkone,

        Before we work toward detecting if it is being hosted, can you clarify, do you also want the timed images from the timer in the indicator or are you trying to call the screenshot code from the strategy to take a screenshot at specific times?

        The indicator is programmed to start the timer when used, so it may need modified more depending on what the overall goal is. The code your strategy needs to take the image is in the indicator, however to call it you will also start the timer and you are not doing any error checking in that area. If that is not the goal to also start the timer, it would be easiest to copy the screenshot code so you don't have to make the indicator more complex. you can of course make the indicator more complex, but that will again depend on the goal with the timer.




        I look forward to being of further assistance.

        JesseNinjaTrader Customer Service

        Comment


          #5
          good point. i want to have the timed screenshots in place. i also want to able to trigger screenshots from the strategy. this will allow me to publish the screenshots from strategy to my blog with automated stats printed on it.
          the only reason why i was thinking of keeping code in indicator was to keep it in one place. i want to be able to call the screenshots code from multiple strategies.

          Comment


            #6
            Hello junkone,

            In that case you would likely need to modify a few parts of the indicator. You can use AddChartIndicator here to add the indicator which will get the buttons and start the timer. Here are some items I can note about what might need to change:
            1. Add checks in your timers code to make sure that does not have errors for cases if ChartControl is null.
            2. Picking a better way to start the timer, such as a button would be suggested. Starting in DataLoaded does not work well for calling from another script use case.
            3. In the timers event code you also used a CurrentBar check, however that is outside the trigger custom event so that will not work, that should be removed or moved into the screenshot code.
            If you are applying the strategy from a chart, you could use AddChartIndcaitor to resume the existing indicator functions. This would allow the buttons to be added to the chart/screenshot functions to work.

            When called from code, you need to avoid starting the timer and also pass in the ChartControl. To expose the method you just need to make it public:

            Code:
            private void triggerScreenshot(object price)
            to
            Code:
            public void triggerScreenshot(object price)
            To pass in the ChartControl you could modify the overload to:

            Code:
            public void triggerScreenshot(ChartControl cc, object price)
            Then in the method code, use cc instead:

            Code:
            cc.Dispatcher.InvokeAsync((Action)(() =>
            
            chart = Window.GetWindow(cc) as Chart; //you will need to add this part into your method to get the chart when requested
            In your indicator you would pass in the ChartControl object from the indicator or calling it from a strategy:

            Code:
            ScreenshotTakerExample().triggerScreenshot(ChartControl, Close[0]);
            I look forward to being of further assistance.



            JesseNinjaTrader Customer Service

            Comment


              #7
              what you proposed is wonderful. Now i have a different issue. I am calling the screenshot from 2 differnet strategies and i find that the trades plotted by both strategies are on the same chart as you can see in the attached image.
              in this case, i have 2 charts for eurusd. i have 1 strategy on each of the chart but the trades are printed for both of them on both the charts. is there a way, i can show only trades belonging to the strategy running on first chart not to show up on the second chart?

              Comment


                #8
                Hello junkone,

                Can you provide the script as you have it now for me to review?

                As a test, can you check if this is related to the selected account in the chart? In the control center accounts tab, create a new sim account by right clicking -> add simulation account. Click OK then apply the second strategy to the second sim account, so one on each account. In each chart, open the chart trader and select the sim account that the strategy will be applied to.

                After the orders happen where you see the combined image normally, does it still happen when using separate accounts? As a guess this may relate to the Chart and its selected account.

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

                Comment


                  #9
                  when i use bar replay, i can access only 1 a/c
                  Last edited by junkone; 09-08-2019, 12:48 PM.

                  Comment


                    #10
                    Hello junkone,

                    Can you test this when connected to a datafeed instead of using playback? I would otherwise still need to see the script to test the situation myself.

                    Please let me know if I may be of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by funk10101, Today, 09:43 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post funk10101  
                    Started by pkefal, 04-11-2024, 07:39 AM
                    11 responses
                    37 views
                    0 likes
                    Last Post jeronymite  
                    Started by bill2023, Yesterday, 08:51 AM
                    8 responses
                    44 views
                    0 likes
                    Last Post bill2023  
                    Started by yertle, Today, 08:38 AM
                    6 responses
                    26 views
                    0 likes
                    Last Post ryjoga
                    by ryjoga
                     
                    Started by algospoke, Yesterday, 06:40 PM
                    2 responses
                    24 views
                    0 likes
                    Last Post algospoke  
                    Working...
                    X