Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trading a PIN bar logic not working

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

    Trading a PIN bar logic not working

    Hello: I have this code that not working and only prints a log when I am not in Trade. What is missing so at least I get one trade.
    Logic to check the current bar open, close, high and low and see if high of the bar have formed Wick and place a trade long or short.
    Any syntax error causing it or something missing in the code. I build this using some Youtube videos but something is not right.
    Any help would be appreciated.
    Thanks,

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    Print("I am in NO trade.");


    if ((Close[0] == Low[0] && Open[0] > Close[0] && High[0] > Open[0] && CrossAbove(Close, MY_EMA, 1)))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), @"Buy");
    Print("I am in LONG trade.");

    }

    if ((Close[0] == High[0] && Open[0] < Close[0] && High[0] > Open[0] && CrossBelow(Close, MY_EMA, 1)))
    {
    EnterShort(Convert.ToInt32(DefaultQuantity), @"Sell");
    Print("I am in SHORT trade.");
    }



    // Set 6
    // if (BarsSinceExitExecution(0, "", 0) == 1)
    // {
    // Draw.Text(this, Convert.ToString(CurrentBars[0]), Convert.ToString(SystemPerformance.AllTrades.Trade sPerformance.Currency.CumProfit) + @" $", 0, (Low[0] + (25 * TickSize)) );
    // }

    }

    #2
    Hello mtamaku,

    The print "Print("I am in NO trade.");" should be appearing for every bar update.

    The entry order is only going to be submitted if the condition is evaluating as true.

    One line above the condition print the time of the bar and print each value being compared in the condition. Include labels for each value and comparison operator.

    We should be able to see in the output how each value is being compared.

    Below is a link to a forum post with videos that demonstrate how to use prints to understand behavior.


    Save the output to a text file and include this with your reply.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X