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

How to simply choose from and define many entry conditions in one strategy

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

    How to simply choose from and define many entry conditions in one strategy

    Hello, in strategy, I am having variable input:

    #region Variables
    private int entryoption= 1; //I can choose between 1 and 2 (or more )which will be choosing between 2 entry conditions (or more)

    I also have

    private int entrycondition1 = 0;
    private int entrycondition2 = 0;
    private double entrypoint = 0;


    and my condition in protected override void OnBarUpdate():

    if (entryoption==1) { entrycondition1 =1; entrycondition2 =0;}
    if (entryoption==2) { entrycondition1 =0; entrycondition2 =1;}

    (in firts case, strategy will work with entrycondition1, in second case with entryconditon2)

    now when I know which entrycondition it will use, I need to define entrypoint:

    if (entrycondition1==1) { entrypoint =High[0]}
    if (entrycondition2==1) { entrypoint =Low[0]}

    (both of them define entrypoint, but it does not matter, because these conditions can not work at the same time, always only one of them).
    finaly:
    if ((entrycondition1==1)
    && (Close[0]> entrypoint))
    {
    EnterLong(DefaultQuantity, "long");
    }

    (or second option)

    if ((entrycondition2==1)
    && (Close[0]> entrypoint))
    {
    EnterLong(DefaultQuantity, "long");
    }


    However, it gives me not right results....In first case entry should be above High[0], in second case above Low[0].Problem must be somewhere in entrypoint, because if I do not use entrypoint and write :
    if ((entrycondition1==1)
    && (Close[0]> High[0]))
    {
    EnterLong(DefaultQuantity, "long");
    }

    it works. However I am planning to have about 10 different variable entries(entrycondition1,entrycondition2, entrycondition3 etc.), so I need this entrypoint. Lets say that logic for entry order is still the same for every entrycondition.
    if ((entryconditionX==1)
    && (Close[0]> entrypoint))
    {
    EnterLong(DefaultQuantity, "long");
    }

    but only what will be defined and different for every entrycondition, will be entrypoint...How to achieve that? In my opinion, if I choose, entryoption==1, it will trigger entrycondition1==1, which will leads to entrypoint= High[0]. In otherwords - I want to achieve, that my entry logic is always same (Close[0]> entrypoint)), only entrypoint has many definitions and I will choose one of them from variables (entryoption)...What I am doing wrong?

    #2
    Hello Tomass,

    Thank you for your note.

    I'm not sure how the following could ever be true, since the highest a close of a bar could be is the high of that bar. So (Close[0]> High[0])) could not be true, but (Close[0]>=High[0])) could.

    I would suggest adding prints to understand your behavior.

    I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


    I’ve provided a link covering debugging which you may find helpful.
    Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kujista, Today, 05:44 AM
    0 responses
    5 views
    0 likes
    Last Post kujista
    by kujista
     
    Started by ZenCortexCLICK, Today, 04:58 AM
    0 responses
    5 views
    0 likes
    Last Post ZenCortexCLICK  
    Started by sidlercom80, 10-28-2023, 08:49 AM
    172 responses
    2,281 views
    0 likes
    Last Post sidlercom80  
    Started by Irukandji, Yesterday, 02:53 AM
    2 responses
    18 views
    0 likes
    Last Post Irukandji  
    Started by adeelshahzad, Today, 03:54 AM
    0 responses
    8 views
    0 likes
    Last Post adeelshahzad  
    Working...
    X