Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Way to backtest with numbers from an outside source?

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

    Way to backtest with numbers from an outside source?

    Hello,

    Allow me to unpack my issue.

    I have exported data from NT. I then run some calculations in Matlab that give me numbers that would represent entry points, stops, targets, and possible trail stop numbers.

    THese numbers will change as the data changes.

    I would like to then test these numbers in NT using the strategy analyzer. I am familiar with the strategy analyzer and have used my scripts before the test ideas.

    I am using Matlab to create varying entries, stops and targets as it's much easier for me to prototype ideas in Matlab so that I can test it. I "can" build whatever I want in NT of course, but it just takes me a lot longer to do in NT than it does in Matlab (probably hours vs. days).

    So I am wondering if there is an obvious strategy to accomplish what I want? No code necessary, but just a general idea.

    I am wanting to test this over the course of thousands of bars, so I'd like to use the NT capability of backtesting so that I can do it somewhat effeciently, as I figure once i have the structure in place to do this, I can deploy it to many ideas or various periods of data pretty quickly.

    My initial thought was that on each bar I calculate my numbers for in Matlab, I can simply have Matlab print out a code snippet for that day period (Start and End Time) in a text file, and then simply PASTE that snippet into NT.

    I am wondering if this is the way to go or if there is some obvious better way that I am unaware of, like actually having NT read from a csv or text file with the numbers I want to test?

    #2
    Hi forrestang,

    With NinjaScript the code needs to be written in C#.

    If you want to be able to write Matlab code and have this translate to NinjaScript, you would need to create (or contract someone to create) a conversion script or a script that provides inputs and creates the code necessary.

    By this, I am indicating that there is not something that is already in existence that I am aware of that would provide this functionality but it sounds very plausible. You may be able to have this created at your request by a contractor.

    Please let me know if you would like our business development to follow up with you with a link to a list of professional NinjaScript consultants that would be happy to assist.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hi forrestang,

      With NinjaScript the code needs to be written in C#.

      If you want to be able to write Matlab code and have this translate to NinjaScript, you would need to create (or contract someone to create) a conversion script or a script that provides inputs and creates the code necessary.

      By this, I am indicating that there is not something that is already in existence that I am aware of that would provide this functionality but it sounds very plausible. You may be able to have this created at your request by a contractor.

      Please let me know if you would like our business development to follow up with you with a link to a list of professional NinjaScript consultants that would be happy to assist.
      Thanks Chelsea, but that's not what I mean. My idea is to simply take Matlab and have it print out the NT script.

      So for example, say that the numbers I calculate in Matlab tell me that I want to buy @ 12 o'clock, if the High of the current Bar is greater than the Daily Open + 10 tics, a stop below the low of the Current Day, and let it exit on close (simplified strategy to explain).

      The required NT script for such criteria would be:
      Code:
      					if (ToTime(Time[0].ToUniversalTime())==[COLOR="Magenta"][B]120000 [/B][/COLOR]&&High[0]>CurrentDayOHL().CurrentHigh[0]+[COLOR="magenta"][B]10[/B][/COLOR]*TickSize
      						&&Time[0]>=[COLOR="Magenta"][B]startDateTime [/B][/COLOR]&&Time[0]<=[B][COLOR="magenta"]endDateTime[/COLOR][/B])	
      					{
      						myStopLoss=Math.Round((Close[0]-CurrentDayOHL().CurrentLow[0]-(1*TickSize))/TickSize,0);
      						
      						EnterLong(DefaultQuantity, "myLong");
      						SetStopLoss("myLong", CalculationMode.Ticks, myStopLoss, true);
      					}
      I was literally going to have Matlab Print out the above( I would write a Matlab script to write this to a text file), and simply paste this code into my NT strategy. So it would be a line of code like this above for each bar, there would be thousands. I don't mind as this is just to use NT to backtest some ideas. The highlighted pink will be the variables calculated from Matlab. The startDateTime and endDateTime will simply be the start and and times of the bar I am testing.

      The above WILL work, I was just wondering if there was a simpler or more obvious way to do it, such as having NT read the values highlighted above from a text file or csv instead of me writing Matlab Code that writes NT script?
      Last edited by forrestang; 03-08-2016, 04:53 PM.

      Comment


        #4
        Hello forrestang,

        This would be a matter of personal preference.

        From my understanding you are wanting the least amount of steps to convert code or algorithms from MathLab to NinjaScript. Using a file that is read using a StreamReader would require that you export the file from MathLab and read the file from NinjaTrader.
        This may work, I would not be able to say for sure as I don't know MathLab and what would be necessary to save or convert.

        My suggestion was basically to say that you could probably write a script that does the conversion for you. Takes whatever you have written and converts it. I'm only saying that this is a possibility.

        However, what would be easier would depend on what values and / or logic you are trying to push into NinjaTrader.
        It might be easier to use text files. It might be possible to use sockets or web requests.

        What you are asking is outside of the realm of support, however, this thread will remain open for any community members that would like to assist.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        17 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        5 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Started by poplagelu, Today, 05:00 AM
        0 responses
        3 views
        0 likes
        Last Post poplagelu  
        Working...
        X