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

Josh or any advanced c# programmer please please help

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

    Josh or any advanced c# programmer please please help

    I know that what I want do (will explain it bellow) is outside of what NT supports, but I hope that, you Josh, or some of the advanced c# programmers (I suppose there must be more than 1 on this forum) can help me out.

    As NT does not officially support multi timeframe indicators (not yet, but I need them) I found a rather complicated work around (programmed in ninja script) to create multi timeframe indicators and it works very well with the exception that I only can plot higher time frames on lower time frames but not lower time frames on higher timeframes (I can plot a 60min SMA for example on a 5min chart but not a 5min on a 60min).

    Now I am in need to also plot some indicators from lower to higher time frame and the unique possible simple solution I can think of is to plot signals from the lower to the higher time frame instead of plotting the whole indicator.
    I mean, for example, I crate a indicator based on a MA cross which does something like: if MA1 cross above MA2 plot0.set 1 ; if MA1 cross bellow MA2 plot0.set 2 else 0
    and then I use a function to write this to a file.
    Then I make a indicator on the 60min chart which reads the same file and according to what he reads plots a up arrow, a down arrow or nothing (something like: read file...., if output=1 up arrow, if output=2 down arrow).

    THIS IS THE ROW IDEA!

    HERE COMES MY PROBLEM:

    I had a look at the examples of StreamReader and StreamWriter and they cannot read and write the same file at the same time (only support synchronous reading writing), so using StreamReader/StreamWriter for this will not work.

    Then I searched MSDN and found that the FileStream Class supports asynchronous reading/writing, so it can be used to read a file and output whatever is appended to it in real time (at least I think so, correct me if I am wrong).

    So basically I need to have in the lower timeframe indicator something like FileStream fs = new FileStream("signal.txt", FileMode.Append, FileAccess.Write, FileShare.Read); and then the command to write the number 1 or 2 to the file. And the higher timeframe should have something like FileStream fs = new FileStream("signal.txt", FileMode.Open,
    FileAccess.Read); and then read what just was added to the file and compare it, if the comparison gives a true (1=1) plot something (up arrow for example).

    This is again a ROW concept but I am lost in implementing it in NT.

    Hope someone can help me with the implementation of this concept.

    Sorry for the long post and my bad English, hope it is more or less understandable.

    Thank you very much!

    #2
    Hint: It's a matter of how you access files to avoid locking issue. NT e.g. uses this code

    BinaryReader binaryReader = new BinaryReader(File.Open(filename, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite))

    You would need to research down this path, but code snippet above should provide you an idea on what to do.

    Comment


      #3
      Thanks for the replay Dierk,

      I know that it's a matter of how you access files to avoid locking issues and that both, SreamReader/Writer and BinaryReader/Writer also can be used for what I want but the file access management seems to me rather complicated and it would not be in real time (I could tick by tick check the current time for example, write each pair second and read each impair second this way I would avoid locking but my signals would appear with a 1second delay) so I thought that there must be something more appropriate for this job and it seems FileStream Class could be the perfect solution for doing it in real time and without need of using any file access management at all but I am a little bit lost implementing it in NT (like I told, I am a non programmer, never programmed anything before now (NT) and this is something complicated for me but I supose very easy for a c# programmer).
      Last edited by whitegun; 06-26-2008, 05:37 AM.

      Comment


        #4
        Which technique have you tried using prior to the FileStream idea? Have you seen this reference sample? http://www.ninjatrader-support.com/v...ead.php?t=6651

        The reference sample will work from both lower to higher and higher to lower. The issue that comes when using higher to lower is the order in which the different bar series is called upon. Since you are going from higher to lower the order in which things are called is already messed up so the values you are getting will be 1 bar behind. This is why when you make multi-time framed strategies we highly recommend you create them in order being the chart as the lowest time frame.
        Last edited by NinjaTrader_JoshP; 06-27-2008, 12:57 AM.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hello Josh,

          I had a look at the reference sample you suggested (I haven’t seen it before) but I cannot make it work I also do not exactly understand how it should work.
          Can I put the strategy on one chart and the plot on another chart and let the plot plot the strategy signals or must be both on one and the same chart?? In either case I cannot make it work at all (the indicator plots nothing) and I didn’t exactly understand how the code should work.
          Could you please elaborate a little bit more on it.

          Thanks

          Comment


            #6
            You want to simply use the exact format used in the reference. Basically you have a dummy indicator called StrategyPlot(). You add these to your strategy and use the strategy to set values to the plot. This way you can have multi-time framed indicator plots.

            You cannot put the strategy on a separate chart. The strategy will be on the same chart as the plotting. The strategy is the thing doing the plotting. Consider it a container for the indicator. Please take note that the indicator will only plot in real-time charts. It will not plot in the Strategy Analyzer.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Josh, like I thought, it has no use for me because I must have the strategy on an other window then the indicator.
              I use chart trader for trading and unfortunately NT does not allow to run the chart trader and a strategy at the same time (or am I wrong???).
              If it would be somehow possible to run 1 strategy and the charttrader on the same window (chart), at the same time, I would have no problems at all, I would simply program my signals in a MTF strategy.

              Is there some way or work arround to run a strategy and the chart trader on the same window

              Comment


                #8
                >> Is there some way or work arround to run a strategy and the chart trader on the same window
                Unfortunately this is not supported.

                Comment


                  #9
                  Than the unique option left for me would be the FileStream idea, using asynchronous reading writing to a file.

                  Or is there something else I could do

                  Comment


                    #10
                    Not that I'm aware of.

                    Comment


                      #11
                      Thanks,

                      will see if I am able to make the filestream idea work

                      Comment


                        #12
                        It occurs to me that it might be easier to synthesise the higher time frame bars rather than the indicator. For example if you want a 5 min MA on a 30 min chart start with a 5 minute bar with its MA and then plot synthetic 30 minute bars with a simple *5 countdown timer.

                        I am no Ninja expert but have done Multi timme frame stuff on other platforms it always seemed easier to start with the smallest unit and accumulate multiples than to have the higher one and divide it out. Ignore me if I am way of base

                        Comment


                          #13
                          It can work, but you may have the time frames firing out of order. Please check the reference sample posted above to see a description about the time sequencing of the bars.
                          Josh P.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by andrewtrades, Today, 04:57 PM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by chbruno, Today, 04:10 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post chbruno
                          by chbruno
                           
                          Started by josh18955, 03-25-2023, 11:16 AM
                          6 responses
                          436 views
                          0 likes
                          Last Post Delerium  
                          Started by FAQtrader, Today, 03:35 PM
                          0 responses
                          7 views
                          0 likes
                          Last Post FAQtrader  
                          Started by rocketman7, Today, 09:41 AM
                          5 responses
                          19 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Working...
                          X