Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why this simple code doesn't work ?

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

    Why this simple code doesn't work ?

    Hi everybody !

    Okay I developed a signal indicator which work fine. I would like to code strategy based on this indicator. So I developed everything this morning, but when I lauch the strategy on my graph nothing happens. What's wrong ?

    (I simplify the code with "BuySignal" / "SellSignal" etc... The problem isn't here as my indicator works, I think the issue is linked to order operation.)

    Code:
    // Condition set 1
                if (BuySignal == 1)
                {
                    EnterLong(2, "Achat");
                }
    
                // Condition set 2
                if (SellSignal== 1)
                {
                    EnterShort(2, "Vente");
                }
    
                // Condition set 3
                if (StopSignal== 0.5)
                {
                    ExitLong("", "");
                    ExitShort("", "");
                }
    
                // Condition set 4
                if (TargetSignal== 0.75
                    && Position.MarketPosition == MarketPosition.Long)
                {
                   ExitLong(1, 1, "Exit Long Position", "Achat");
                }
    
                // Condition set 5
                if (TargetSignal== 0.75
                    && Position.MarketPosition == MarketPosition.Short)
                {
                    ExitShort(1, 1, "Exit Short Position", "Vente");
                }
    Thanks you very much !

    #2
    Hello After,

    Thank you for your post.

    What is generating the SellSignal, BuySignal, and TargetSignal and how are you setting these in the Strategy Analyzer?

    Are you enabling the strategy when applied to your chart? To enable the strategy right click in your chart > select Strategies > select the strategy applied to your chart in the lower left hand field of the strategies menu > set Enabled to True > OK.

    Comment


      #3
      Thanks for answering

      What is generating the SellSignal, BuySignal, and TargetSignal and how are you setting these in the Strategy Analyzer?

      These signals are generated by an indicator. (and the indicator works fine)
      Don't understand your last question ? I set nothing, just developed this and try to backtest or launch the strategy on the chart.

      "Are you enabling the strategy when applied to your chart?"

      Yes.......


      I noticed someting very strange : if I open a graph and launch my indicator, this one works fine. BUT, if a run the same indicator in the strategy analyzer (in Chart), I don't get any signals ! Very strange ?

      Comment


        #4
        Hello After,

        Thank you for your response.

        Would you mind if I tested the strategy and indicator on my end? You can export the files under File > Utilities > Export NinjaScript, make sure to select source files. And you can send these to platformsupport[at]ninjatrader[dot]com with this thread in the subject line: http://www.ninjatrader.com/support/f...ad.php?t=69356

        For information on exporting NinjaScript files please visit the following link: http://www.ninjatrader.com/support/h...nt7/export.htm

        Comment


          #5
          I tried another thing and it works better, but this line seems still doesn't work :

          Code:
          ExitLong(1, 1, "Exit Long Position", "Achat");
          I bought 2 contrat, and here I would like just exit 1 contrat, is it right ?

          Thanks !

          Comment


            #6
            Hello After,

            Thank you for your response.

            Specifying the quantity will mean the Exit method only exits the desired quantity. What is not working with this line of code?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            647 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X