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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    81 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    64 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    68 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    55 views
    0 likes
    Last Post CarlTrading  
    Working...
    X