Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

seeing the result of a math method

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

    seeing the result of a math method

    I'm making a filter for a strategy to keep it from taking trades don't meet a minum risk to reward threshold. Here is the method:

    if((htfbullretouchline - bullpbclose) / (bullpbclose - bullstop) <= 3)
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    }

    2 questions. Is this syntax correct for dividing the result of the first variable minus the second by the 3rd variable minus the 4th? All 4 of those variables are doubles containing closing prices. Also, how do I see this number from the ninjascript editor. I'm assuming there has to be a way to do this. Please assist.

    #2
    Hello gordongekko,

    Thanks for your post.

    The subtractions would occur first because they are contained with () and then would be divided by the results of () / (). To further isolate that side of the logic you can add another set of () to surround the math (((htfbullretouchline - bullpbclose) / (bullpbclose - bullstop)) <= 3). This ensures that the math is completed before the logic is evaluated.

    To see the number being used, I would advise creating another line that puts the result into another variable and then use Print statements to see the value:

    double myRatio = (htfbullretouchline - bullpbclose) / (bullpbclose - bullstop);
    Print ("R/R = "+myRatio);

    Comment


      #3
      One more question. Is this correct syntax:

      bullstop = MIN(Low, 5)[0] -2*TickSize;

      Comment


        #4
        Hello gordongekko,

        Thanks for your reply.

        MIN(Low, 5)[0] -2*TickSize;

        Will provide the minimum value of the last 5 bars (including current bar) and then subtract 2 ticks.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        46 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        28 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        163 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        158 views
        2 likes
        Last Post CaptainJack  
        Working...
        X