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 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