Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can someone fix this code that I can use it ?

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

    Can someone fix this code that I can use it ?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Drawing;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Gui.Chart;

    namespace NinjaTrader.NinjaScript.Indicators
    {
    public class ReversalIndicator : Indicator
    {
    // Set up variables to track the high and low of the current range
    double rangeHigh = 0;
    double rangeLow = 0;

    // Set up variables to track the reversal direction
    bool reversalUp = false;
    bool reversalDown = false;

    // This method is called at the beginning of each bar
    protected override void OnBarUpdate()
    {
    // Check if we are at the start of a new range
    if (BarsInProgress == 0)
    {
    // Set the high and low of the range to the current open price
    rangeHigh = Open[0];
    rangeLow = Open[0];
    }

    // Update the range high and low if the current high or low is higher/lower than the current range
    rangeHigh = Math.Max(rangeHigh, High[0]);
    rangeLow = Math.Min(rangeLow, Low[0]);

    // Check if the current close is outside the range
    if (Close[0] > rangeHigh || Close[0] < rangeLow)
    {
    // Set the reversal direction
    if (Close[0] > rangeHigh)
    {
    reversalUp = true;
    reversalDown = false;
    }
    else
    {
    reversalDown = true;
    reversalUp = false;
    }

    // Reset the range high and low
    rangeHigh = Open[0];
    rangeLow = Open[0];
    }
    else
    {
    // No reversal
    reversalUp = false;
    reversalDown = false;
    }
    }

    // This method is called to draw the indicator on the chart
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    // Draw an up arrow if the reversalUp variable is true
    if (reversalUp)
    {
    chartControl.ChartPanel.Add(new Gui.Chart.ChartArrow(
    new Pen(Color.Green, 2),
    new Pen(Color.Green, 2),
    0,
    0,
    50,
    50,
    -45,
    chartControl.GetXByTime(Time[0]),
    chartControl.GetYByValue(High[0]),


    #2
    Hello Uregon,

    Thank you for your post.

    Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one-on-one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all our clients and associates.

    That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples. We are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior. A member of the forum community may also decide to take a look at this and assist you with getting it to work for you.

    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.

    Please let me know if one of these options interests you and I will gladly respond accordingly.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      First I am not a Professional coder, but a lot of your logic does not seem to make since to me (but I am not aware of exactly what you are hoping to find)

      // Set the high and low of the range to the current open price
      rangeHigh = Open[0]; << why not just use Open[0] for Open[0] ?
      rangeLow = Open[0];
      }

      // Update the range high and low if the current high or low is higher/lower than the current range
      rangeHigh = Math.Max(rangeHigh, High[0]); << you are updating rangeHigh from Open[0] to High[0] (IF SO SEE BELOW)
      rangeLow = Math.Min(rangeLow, Low[0]);

      // Check if the current close is outside the range
      if (Close[0] > rangeHigh || Close[0] < rangeLow << IF rangeHigh is NOW updated to High[0], then Close[0] will NEVER be > than High[0]

      Just food for thought​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by fx.practic, 10-15-2013, 12:53 AM
      5 responses
      5,403 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by Shai Samuel, 07-02-2022, 02:46 PM
      4 responses
      94 views
      0 likes
      Last Post Bidder
      by Bidder
       
      Started by DJ888, Yesterday, 10:57 PM
      0 responses
      6 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by MacDad, 02-25-2024, 11:48 PM
      7 responses
      158 views
      0 likes
      Last Post loganjarosz123  
      Started by Belfortbucks, Yesterday, 09:29 PM
      0 responses
      8 views
      0 likes
      Last Post Belfortbucks  
      Working...
      X