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

Entry issues

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

    Entry issues

    Hello Ninja Team,

    Please help! I cant figured it out where is the problem in my program, I tried to debug and print but could not find why my logic is not executing entries correctly.

    Here is the code:

    double highPrice = 12;
    double lowPrice = 8;
    private bool breakout;
    private bool breakdown;
    private bool TradingHours;

    //defaults here, did not change anything here


    protected override void OnBarUpdate()
    {

    if (CurrentBars[0] < 3)
    return;


    //Entry Conditions
    breakout = (Close[1] >= highPrice && Open[1] >= highPrice && Close[2] >= highPrice && Open[2] >= highPrice && Position.MarketPosition == MarketPosition.Flat);

    breakdown = (Close[1] <= lowPrice && Open[1] <= lowPrice && Close[2] <= lowPrice && Open[2] <= lowPrice && Position.MarketPosition == MarketPosition.Flat);


    TradingHours = ((ToTime(Time[0])>=000000 && ToTime(Time[0])<=160000) || (ToTime(Time[0])>=180100 && ToTime(Time[0])<=235959));

    if(TradingHours){

    // LongEntry
    if (breakout && Close[0] == highPrice) {
    EnterLongLimit(0, false, 1, highPrice, "LongEntry1");

    }

    // ShortEntry
    if (breakdown && Close[0] == lowPrice) {
    EnterShortLimit(0, false, 1, lowPrice, "ShortEntry1");

    }
    }


    Please see also attachment I visually draw what I want to achieve.
    Attached Files

    #2
    Hello Bobisam,

    Thanks for your post.

    Regarding the statement, "could not find why my logic is not executing entries correctly." Does this mean that it is making the entries at an incorrect price or at an incorrect time or both or no entries at all?

    Your code does not show any print statements so we cannot see what you are doing to debug your code.

    What I would recommend is to add a print statement just above the "if(TradingHours)" and print the value of TradingHours along with the time value of the current bar (Time[0]). This will let you compare the bar close time to the bool TradingHours and lets you see that the bool is or is not correct for the specified time.

    Inside of the TradingHours { } I would add another Print statement to print the Time[0] of the bar, the value of "breakout", the value of Close[0] and the value of "highPrice". In this way, on one line you can make your own observation that shows that on a particular bar the value of breakout and can compare the Close[0] to the target value of highPrice (or lowPrice for the other side).

    Once you print those values the picture should be clearer for you.

    Regarding print statements, one error we often run into is "assuming" that a value will be as expected and I would encourage you to print everything so there are no assumptions and you have proven what is actually happening. This is what makes debugging tedious but necessary to understand what is actually happening bar by bar.

    You also may want to review two points of your logic. The definition of breakout (or breakdown) being true depend on the close price of the 2 prior bars being above highPrice (or below lowPrice) and when breakout or breakdown are true, you then want close price to exactly equal highPrice (or lowPrice). When you print out the Close[0] value, pay attention to see if the value exactly matches highPrice or lowPrice.

    Finally, I do not see where you are resetting breakout or breakdown back to false for the next session. Keep in mind that when you apply the strategy to a chart, the strategy will begin processing on the first historical bar x days ago.

    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DJ888, Today, 10:57 PM
    0 responses
    1 view
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    158 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Today, 09:29 PM
    0 responses
    7 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Today, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    151 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Working...
    X