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

Arrow up/down not rendering on true condition

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

    Arrow up/down not rendering on true condition

    Hi all, I am fairly new to Ninjascripting and indicator development, but I've been reading over the docs and some other indicators for examples and I am a bit stuck. Basically I am trying to create an indicator that will notifiy me of entries based on a certain criteria. So far my code just looks like this:

    string goshort;
    string golong;
    protected override void OnBarUpdate()
    {
    // if condition to determine short
    // if previous bar is green and if current bar has a higher high than previous bar, and a higher low than previous bar, and it's close < open (red bar) mark for short entry
    bool sellEntry = Close[1] > Open[1] && Close[0] < Open[0] && High[1] < High[0] && Low[0] < High[1] && Low[0] > Low[1];
    if (sellEntry) // && Close[0] < Open[0]
    goshort = "short " + CurrentBar.ToString();
    //Draw.TextFixed(this, "entrytext", "Enter Short", TextPosition.TopRight, ChartControl.Properties.ChartText,new SimpleFont("Arial", 10),Brushes.Transparent,Brushes.Transparent,0);
    Draw.ArrowDown(this, goshort,true, 0, High[0] + TickSize, Brushes.Red);
    // if condition to determine long
    // if previous bar was red
    // if current bar has a lower high than previous bar, and a lower low than previous bar, and it's open < close (green bar) mark for long entry
    bool buyEntry = Close[1] < Open[1] && Close[0] > Open[0] && High[1] > High[0] && Low[1] > Low[0] && High[0] < High[1];
    if (buyEntry) // && Close[0] > Open[0]
    golong = "long " + CurrentBar.ToString();
    //Draw.TextFixed(this, "entrytext", "Enter Long", TextPosition.TopRight, ChartControl.Properties.ChartText,new SimpleFont("Arial", 10),Brushes.Transparent,Brushes.Transparent,0);
    Draw.ArrowUp(this, golong, true, 0, Low[0] + TickSize, Brushes.Green);

    }​

    A more visual example of what I want to do (where left image is criteria for shorting, and right is criteria for going long):
    Click image for larger version

Name:	NTscripting.png
Views:	79
Size:	31.3 KB
ID:	1280458

    Update: I found somebody that was able to write nearly the exact same logic for a tradingview indicator, but still no luck on my end for converting their code into ninjascript/C#.
    Strategy: 15min timeframe Trading hours: 9:30 EST - 2:15 EST Buy/Long- Down bar Up bar Has lower low than down bar Closes within the body of the down bar Closes above the 8 EMA Entry - 1 tick above the up bar Target - 35 points or 1:1 (take the lesser value) Stop loss - 20-35 points ( use preceding bar as guide) Sell/Short- Up bar Down bar Has higher high than up bar Closes within the body of the upbar Closes below the 8 EMA Entry - 1 tick below the down bar Target - 35 points or 1:1 &#8230;



    Any tips or guidance?

    #2
    Hello aamin6,

    Thanks for your notes.

    Are 'goshort' and 'golong' class-level variables in the script?

    If so, they should be "private string goshort;" and "private string golong;" in the script.

    Your if statements should have opening and closing curly braces with the Draw method being called within them

    For example:

    Code:
    if (sellEntry)
    {
        goshort = "short " + CurrentBar.ToString();
    
        //Draw.TextFixed(this, "entrytext", "Enter Short", TextPosition.TopRight, ChartControl.Properties.ChartText,new SimpleFont("Arial", 10),Brushes.Transparent,Brushes.Transparent,0);
    
        Draw.ArrowDown(this, goshort,true, 0, High[0] + TickSize, Brushes.Red);​
    }​
    Ultimately, if the script is not behaving as expected then debugging prints should be added to the script to understand how your logic is evaluating.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Also, note the Log tab of the Control Center when running the script to see if any error messages are appearing.​
    Brandon H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DJ888, Today, 10:57 PM
    0 responses
    6 views
    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