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 NullPointStrategies, Today, 05:17 AM
    0 responses
    50 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    126 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    69 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X