Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Builder - Do not enter long if previous bar is greater than current

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

    Strategy Builder - Do not enter long if previous bar is greater than current

    Hi,

    I'm trying to build a strategy based on SMA cross over. For calculations I'm using OnBarClose. I read from a previous post that you would use (Close[0] > Close[1])).
    I tried using the condition but still, an order still gets placed and filled.

    This is my condition for entry:
    ---------------------
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if ((CrossAbove(SMA1, SMA2, 1))
    && (Close[0] > Bollinger1.Middle[0])
    && (CurrentBars[0] != SavedBar)
    && (Position.MarketPosition == MarketPosition.Flat)
    && (Close[0] > Close[1]))
    {
    EnterLong(Convert.ToInt32(DefaultQuantity), goldenentry);
    SavedBar = Convert.ToInt32(CurrentBars[0]);
    }
    ​--------------------------------------

    Attached is the snapshot of the entry...

    Possible to add some guidance where to look?

    #2
    Hello, thanks for writing in. This is happening because the strategy runs OnBarClose, so its submitting the entry order on the first tick of the next bar where the conditions were true, in the image, the Close of the green bar is above the previous bar. To adjust this you would need to run the strategy OnEachTick to enter the market on the first tick of the entry bar. This will bring a new level of complexity to the script because now OnBarUpdate will be running much more frequently. I have an example of an OnEach Tick strategy here that controls trades to one trade per bar:

    Hi!, I have a problem that I thought it was a simple one but I can't manage to find a solution. With the strategy builder I made a strategy that basically has to go long when the price goes over the EMA envelope, then comes back, touches the EMA and closes above of the previous candle close.. Those are the conditions. I also

    Comment


      #3
      Thanks Chris,

      I will take a look

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      80 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X