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

converting eSignal (javascript) to NinjaScript

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

    converting eSignal (javascript) to NinjaScript

    In anticipation of NT6 chart trading being available in the next few weeks, I am converting my efs strategies over to NinjaScript.

    I strikes me that I am not the only one that will be doing this (from somenon-C# code)and that perhaps asking some very basic questions in this thread will save me and others many hours of searching for answers which are blatantly obvious to current NinjaScript users/experts.

    While javascript and ninjascript are bascially very similar, there are some simple differences which are annoying/time-consuming to research. For instance, some common efs code:

    Question 1:Printing a variable on a chart.

    efs code: drawText(Close(0), AboveBar2); prints the last closing price two ticksizes above the current bar....drawText("Sell"....prints the string "Sell"....

    nt code: DrawText("tag", Close[0], 0, High[0]+2*TickSize, Color.Yellow); results in errors including "can not convert from double to string"

    Question 2: Checking current bar state.

    efs code: prior to conditional.... nState = getBarState();....later in code if(nState == BARSTATE_NEWBAR).....is truefor first tick of new bar

    nt code: temporary solution thanks to Ray:



    [align=left]We have logic in an NT6 Strategy bool FirsTickOfBar, there is nothing in NT5.[/align]


    [align=left][/align]


    [align=left]What you could do, is calculate yourself.[/align]


    [align=left][/align]


    [align=left]For TickChart use the Bars.TickCount property[/align]


    [align=left][/align]


    [align=left]private bool firstTick = true;[/align]


    [align=left]private int lastCount = 0;[/align]


    [align=left][/align]


    [align=left]if (Bars.TickCount< lastCount)[/align]


    [align=left] firstTick = true;[/align]


    [align=left][/align]


    [align=left]lastCount = Bars.TickCount;[/align]


    [align=left][/align]


    [align=left]for time chart use[/align]


    [align=left][/align]


    [align=left]private bool firstTick = false;[/align]


    [align=left]private DateTime currentTime = DateTime.MinValue;[/align]


    [align=left][/align]


    [align=left][/align]


    [align=left]if (Time[0].Minute > currentTime.Minute)[/align]


    [align=left]{[/align]


    [align=left] firstTick = true;[/align]


    [align=left] currentTime = Time[0];[/align]


    [align=left]}[/align]


    [align=left]else[/align]


    [align=left] firstTick = false;[/align]


    [align=left][/align]


    [align=left][/align]


    [align=left]Hope this helps![/align]


    [align=left]
    Ray
    [/align]

    #2
    imported post

    ATI user wrote:
    Question 1:Printing a variable on a chart.

    efs code: drawText(Close(0), AboveBar2); prints the last closing price two ticksizes above the current bar....drawText("Sell"....prints the string "Sell"....

    nt code: DrawText("tag", Close[0], 0, High[0]+2*TickSize, Color.Yellow); results in errors including "can not convert from double to string"

    NinjaScript (C#) is a type safe language meaning, unlike some languages, type conversion is not handled for you. Therefore, when passing in parameters, you must ensure that they are of the correct type. The DrawText() method signature is:

    DrawText(string tag, string text, int barsAgo, double y, Color color)

    For the parameter "text" you passed in Close[0] which is a double value when it is looking for a text value. All C# objects have an object.ToString() method. Therefore, you can do the following to convert the Close[0] to a string value.

    DrawText("myTag", Close[0].ToString(), 0, High[0] + 2 * TickSize, Color.Yellow)

    Ray
    RayNinjaTrader Customer Service

    Comment


      #3
      imported post

      Thanks Ray.

      ToString works great.

      So does Bars.TickCount. I hope NT6 will have Bars.VolCount for volume bars?


      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ghoul, Today, 06:02 PM
      3 responses
      14 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by jeronymite, 04-12-2024, 04:26 PM
      3 responses
      44 views
      0 likes
      Last Post jeronymite  
      Started by Barry Milan, Yesterday, 10:35 PM
      7 responses
      20 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by AttiM, 02-14-2024, 05:20 PM
      10 responses
      180 views
      0 likes
      Last Post jeronymite  
      Started by DanielSanMartin, Yesterday, 02:37 PM
      2 responses
      13 views
      0 likes
      Last Post DanielSanMartin  
      Working...
      X