Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

strategy only plot the last 2 arrows

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

    strategy only plot the last 2 arrows

    attached the screenshot.


    this codes only plot two arrows. the logic look okay. but I want it to be able to plot on the chart across all trading hours. Why it only plots two arrows ?



    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;

    // Set 1
    if (MACD1.Diff[0] > 0)
    {
    Draw.Text(this, @"plotMACDBuySell Text_1", @"macd diff > 0", 0, (Close[0] + 30) );
    MacdAboveZero = true;
    }

    // Set 2
    if (MACD1.Diff[0] < 0)
    {
    Draw.Text(this, @"plotMACDBuySell Text_1", @"macd diff < 0", 0, (Close[0] + 30) );
    MacdBelowZero = true;
    }

    // Set 3
    if ((MacdBelowZero == true)
    && (CrossAbove(MACD2.Default, MACD2.Avg, 1)))
    {
    Draw.ArrowUp(this, @"plotMACDBuySell Arrow up_1", true, 0, (Low[0] + (-12 * TickSize)) , Brushes.Lime);
    MacdBuy = true;
    }

    // Set 4
    if ((CrossBelow(MACD2.Default, MACD2.Avg, 1))
    && (MacdAboveZero == true))
    {
    Draw.ArrowDown(this, @"plotMACDBuySell Arrow down_1", true, 0, High[0], Brushes.Red);
    MacdSell = true;
    }

    }​​
    Attached Files

    #2
    Hello sysmatrix,

    To have many drawing objects they need a unique name. You can do something like the following:

    Draw.ArrowUp(this, @"plotMACDBuySell Arrow up_1" + CurrentBar, true, 0, (Low[0] + (-12 * TickSize)) , Brushes.Lime);
    ​Draw.ArrowDown(this, @"plotMACDBuySell Arrow down_1" + CurrentBar, true, 0, High[0], Brushes.Red);

    Adding CurrentBar to the string will give you a unique name per bar so you can have multiple objects. When you re use a tag that just updates the existing object on the chart to the new values.
    ​​

    Comment


      #3
      Thank you Josse. It works perfectly.

      Comment

      Latest Posts

      Collapse

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