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