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

Help needed with a coding problem

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

    Help needed with a coding problem

    Hi, I am testing a strategy that only take one trade per candle stick color change in the same direction, i.e. if the first long signal appeared when the candle stick is green, don't take another long trade unless there is at least one red candle stick between the new long signal and the previous long signal .

    Here is the code:
    Code:
                int LongTradeCount =0;
                int ShortTradeCount =0;
    
                if(Close[0]>Open[0])
                {ShortTradeCount =0;}
                    
                else if(Close[0]<Open[0])
                {LongTradeCount =0;}
                
                else if(
                    SMA(Close,5)<Close[0]
                    &&LongTradeCount==0
                    )
                {
                 EnterLongLimit(DefaultQuantity, Close[0], "L");
                ++LongTradeCount;
                }
                
                else if(
                    SMA(Close,5)>Close[0]
                    &&ShortTradeCount==0
                    )
                {
                 EnterShortLimit(DefaultQuantity, Close[0], "S");
                ++ShortTradeCount;
                }
    However, the code does not work. Could anyone help me with this problem? Your help will be greatly appreciated.
    Last edited by kw123; 01-09-2010, 11:37 PM.

    #2
    Hello,

    I'm not sure. We don't really get into debugging or writing code for people, but we do give tips on specific issues.

    I suggest using a bool variable to check and track if it is time to trade or not. Also, use an int variable to track which bar your order was placed on exactly, then check that againsted CurrentBar:


    This link may help for debugging:


    Also, if you can narrow down the issue a bit I can assist you better.
    DenNinjaTrader Customer Service

    Comment


      #3
      Hi Ben,

      Thanks for your reply.

      I've tried the steps you've suggested and unfortunately because of my limited programming knowledge, I am still not able to make it work.

      Here is a more detailed example of what I want to do:

      Candle 1: Green, Signal: Long( Long signal #1), Action: Take the long trade ( Long trade #1)

      Candle 2: Green, Signal: None, Action: None

      Candle 3: Green, Signal: Long( Long signal #2), Action: None ( Do NOT take this long trade)
      Reason: because there is no color change between long signal #1 and #2

      Candle 4: Red, Signal: None, Action: None

      Candle 5: Green, Signal: Long( Long signal #3), Action: Take the long trade ( Long trade #2)
      Reason: because there is a color change between long signal #1 and #3

      Candle 6: Red, Signal: Short( Short signal #1), Action: Take the short trade ( Short trade #1)

      Candle 7: Red, Signal: Short( Short signal #2), Action: None ( Do NOT take this short trade)
      Reason: because there is no color change between short signal #1 and #2

      Candle 8: Green, Signal: None, Action: None

      Candle 9: Green, Signal: None, Action: None

      Candle 10: Red, Signal: Short( Short signal #3), Action: Take the short trade ( Short trade #2)
      Reason: because there is a color change between short signal #1 and #3

      I think it would be very easy for someone who has a programming background, so I would really appreciate if someone can help me solve this problem. Thank you.

      Comment


        #4
        kw123, unfortunately hard to tell with only a visual check of the snippet provided - I would suggest you print out all related variables and values to the output window and perhaps add a visual check for your conditions(s) to trigger to simplify debugging of your strategy. Normally it's best to break it up in simplest parts possible and then isolate out from there.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by helpwanted, Today, 03:06 AM
        1 response
        7 views
        0 likes
        Last Post sarafuenonly123  
        Started by Brevo, Today, 01:45 AM
        0 responses
        7 views
        0 likes
        Last Post Brevo
        by Brevo
         
        Started by aussugardefender, Today, 01:07 AM
        0 responses
        5 views
        0 likes
        Last Post aussugardefender  
        Started by pvincent, 06-23-2022, 12:53 PM
        14 responses
        242 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        385 views
        1 like
        Last Post Gavini
        by Gavini
         
        Working...
        X