Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How CrossAbove

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

    How CrossAbove

    Click image for larger version  Name:	cross.JPG Views:	0 Size:	41.4 KB ID:	1197894
    Hello
    this photo is the result of these lines of code in an indicator
    State.SetDefaults)
    AddPlot(Brushes.Red, "OpenPlot");
    AddPlot(Brushes.Orange, "ClosePlot");

    OnBarUpdate()

    //OpenPlot[0]=Open[0]; // error in this line
    //ClosePlot[0]=Close[0]; // error in this line why not work?


    Values[0][0]=Open[0];
    Values[1][0]=Close[0];

    Unfortunately I cant create an alert when there is a crossing

    this line give me all chart red!
    if ( (CrossAbove( Open,Close,0))) -> Can you help me= Brushes.Red;

    So i want a alert when there is across betwwen these two lines
    Can you help me Can you help me
    Thanks
    Last edited by aekzof; 04-18-2022, 06:55 AM.

    #2
    Hello aekzof,

    Thank you for your note.

    I'm not quite sure what the errors are that you're seeing, but I do see an issue with your CrossAbove statement. You have to put at least 1 bar as the lookback, since we are comparing what has happened since the prior bar closed. Also, since we'll be looking back to prior bar values, you'll want to check that at least one bar has been processed before the CrossAbove. The following code works for me, plots the open and close, and changes the chart background to red if the Open price crosses above the Close:

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1)
    return;

    OpenPlot[0] = Open[0];
    ClosePlot[0] = Close[0];

    if(CrossAbove(OpenPlot, ClosePlot, 1))
    {
    BackBrush = Brushes.Red;
    }
    }

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Merci it works
      you are right, it takes at least a bar for it to work

      Comment

      Latest Posts

      Collapse

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