Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can you correct this code? . Thank you.

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

    Can you correct this code? . Thank you.

    region Using declarations
    //This namespace holds Strategies in this folder and is required. Do not change it.
    public class GHARIBROBOTSCALP2
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Name = "GHARIBROBO1TSCALP2"; // اسم الاستراتيجية
    Calculate = Calculate.OnEachTick; // التنفيذ عند كل حركة سعر
    EntriesPerDirection = 1; // صفقة واحدة لكل اتجاه
    ExitOnSessionClose = false; // عدم الإغلاق عند نهاية الجلسة
    IsInstantiatedOnEachOptimizationIteration = false;

    SetStopLoss(CalculationMode.Ticks, 10); // وقف خسارة بمقدار 10 نقاط
    SetProfitTarget(CalculationMode.Ticks, 20); // هدف الربح 20 نقطة
    }
    }

    protected override void OnBarUpdate()
    {
    // تأكد من وجود بيانات كافية قبل التنفيذ
    if (CurrentBar < 20)
    return;

    // إذا كان مؤشر RSI أقل من 30 والسعر أعلى من SMA لفترة 10
    if (RSI(14, 3)[0] < 30 && Close[0] > SMA(10)[0])
    {
    EnterLong(); // دخول صفقة شراء
    }
    // إذا كان مؤشر RSI أكبر من 70 والسعر أقل من SMA لفترة 10
    else if (RSI(14, 3)[0] > 70 && Close[0] < SMA(10)[0])
    {
    EnterShort(); // دخول صفقة بيع
    }
    }
    }

    public class ReverseScalpBot
    {
    private double lastAnchorPoint = 0; // النقطة المرجعية للسعر
    private int priceMoveThreshold = 100; // الحد الأدنى للتحرك بمقدار 100 نقطة

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Name = "ReverseScalpBot"; // اسم الاستراتيجية
    Calculate = Calculate.OnEachTick; // التنفيذ عند كل حركة سعر
    EntriesPerDirection = 1; // صفقة واحدة لكل اتجاه
    ExitOnSessionClose = false; // عدم الإغلاق عند نهاية الجلسة
    IsInstantiatedOnEachOptimizationIteration = false;

    SetStopLoss(CalculationMode.Ticks, 10); // وقف خسارة 10 نقاط
    SetProfitTarget(CalculationMode.Ticks, 20); // هدف الربح 20 نقطة
    }
    }

    protected override void OnBarUpdate()
    {
    // التحقق من وجود بيانات كافية
    if (CurrentBar < 1)
    return;

    // تعيين النقطة المرجعية عند أول مرة
    if (lastAnchorPoint == 0)
    {
    lastAnchorPoint = Close[0];
    return;
    }

    // حساب الفرق بين السعر الحالي والنقطة المرجعية
    double priceDifference = Close[0] - lastAnchorPoint;

    // إذا ارتفع السعر بمقدار أكبر من أو يساوي 100 نقطة
    if (priceDifference >= priceMoveThreshold * TickSize)
    {
    EnterShort(); // دخول صفقة بيع
    lastAnchorPoint = Close[0]; // تحديث النقطة المرجعية
    }
    // إذا انخفض السعر بمقدار أكبر من أو يساوي 100 نقطة
    else if (priceDifference <= -priceMoveThreshold * TickSize)
    {
    EnterLong(); // دخول صفقة شراء
    lastAnchorPoint = Close[0]; // تحديث النقطة المرجعية
    }
    }
    }
    public class SupportResistanceBot
    {
    private double supportLevel = 0; // مستوى الدعم
    private double resistanceLevel = 0; // مستوى المقاومة
    private int lookbackPeriod = 20; // فترة المراقبة لتحديد القمم والقيعان

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Name = "SupportResistanceBot"; // اسم الاستراتيجية
    Calculate = Calculate.OnBarClose; // التنفيذ عند إغلاق كل شمعة
    EntriesPerDirection = 1; // صفقة واحدة لكل اتجاه
    ExitOnSessionClose = false; // عدم الإغلاق عند نهاية الجلسة
    IsInstantiatedOnEachOptimizationIteration = false;

    SetStopLoss(CalculationMode.Ticks, 10); // وقف الخسارة
    SetProfitTarget(CalculationMode.Ticks, 20); // هدف الربح
    }
    }

    protected override void OnBarUpdate()
    {
    // التحقق من وجود بيانات كافية
    if (CurrentBar < lookbackPeriod)
    return;

    // حساب مستويات الدعم والمقاومة
    supportLevel = MIN(Low, lookbackPeriod)[0];
    resistanceLevel = MAX(High, lookbackPeriod)[0];

    // إذا تجاوز السعر مستوى الدعم
    if (Close[0] > supportLevel && Close[1] <= supportLevel)
    {
    EnterLong(); // دخول صفقة شراء
    }
    // إذا تجاوز السعر مستوى المقاومة
    else if (Close[0] < resistanceLevel && Close[1] >= resistanceLevel)
    {
    EnterShort(); // دخول صفقة بيع
    }
    }
    }

    #2
    Hello Gharib,

    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 of our clients as well as our associates.

    That said, we are happy to answer any specific questions you may have about this code if you want to create this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

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

    Otherwise, if you have a specific question about how to accomplish something via NinjaScript please let us know. ​

    Comment


      #3
      region Using declarations using System;


      //This namespace holds Strategies in this folder and is required. Do not change it.
      public class GHARIBROBOTSCALP2
      {
      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Name = "GHARIBROBO1TSCALP2"; // اسم الاستراتيجية
      Calculate = Calculate.OnEachTick; // التنفيذ عند كل حركة سعر
      EntriesPerDirection = 1; // صفقة واحدة لكل اتجاه
      ExitOnSessionClose = false; // عدم الإغلاق عند نهاية الجلسة
      IsInstantiatedOnEachOptimizationIteration = false;

      SetStopLoss(CalculationMode.Ticks, 10); // وقف خسارة بمقدار 10 نقاط
      SetProfitTarget(CalculationMode.Ticks, 20); // هدف الربح 20 نقطة
      }
      }

      protected override void OnBarUpdate()
      {
      // تأكد من وجود بيانات كافية قبل التنفيذ
      if (CurrentBar < 20)
      return;

      // إذا كان مؤشر RSI أقل من 30 والسعر أعلى من SMA لفترة 10
      if (RSI(14, 3)[0] < 30 && Close[0] > SMA(10)[0])
      {
      EnterLong(); // دخول صفقة شراء
      }
      // إذا كان مؤشر RSI أكبر من 70 والسعر أقل من SMA لفترة 10
      else if (RSI(14, 3)[0] > 70 && Close[0] < SMA(10)[0])
      {
      EnterShort(); // دخول صفقة بيع
      }
      }
      }

      public class ReverseScalpBot
      {
      private double lastAnchorPoint = 0; // النقطة المرجعية للسعر
      private int priceMoveThreshold = 100; // الحد الأدنى للتحرك بمقدار 100 نقطة

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Name = "ReverseScalpBot"; // اسم الاستراتيجية
      Calculate = Calculate.OnEachTick; // التنفيذ عند كل حركة سعر
      EntriesPerDirection = 1; // صفقة واحدة لكل اتجاه
      ExitOnSessionClose = false; // عدم الإغلاق عند نهاية الجلسة
      IsInstantiatedOnEachOptimizationIteration = false;

      SetStopLoss(CalculationMode.Ticks, 10); // وقف خسارة 10 نقاط
      SetProfitTarget(CalculationMode.Ticks, 20); // هدف الربح 20 نقطة
      }
      }

      protected override void OnBarUpdate()
      {
      // التحقق من وجود بيانات كافية
      if (CurrentBar < 1)
      return;

      // تعيين النقطة المرجعية عند أول مرة
      if (lastAnchorPoint == 0)
      {
      lastAnchorPoint = Close[0];
      return;
      }

      // حساب الفرق بين السعر الحالي والنقطة المرجعية
      double priceDifference = Close[0] - lastAnchorPoint;

      // إذا ارتفع السعر بمقدار أكبر من أو يساوي 100 نقطة
      if (priceDifference >= priceMoveThreshold * TickSize)
      {
      EnterShort(); // دخول صفقة بيع
      lastAnchorPoint = Close[0]; // تحديث النقطة المرجعية
      }
      // إذا انخفض السعر بمقدار أكبر من أو يساوي 100 نقطة
      else if (priceDifference <= -priceMoveThreshold * TickSize)
      {
      EnterLong(); // دخول صفقة شراء
      lastAnchorPoint = Close[0]; // تحديث النقطة المرجعية
      }
      }
      }
      public class SupportResistanceBot
      {
      private double supportLevel = 0; // مستوى الدعم
      private double resistanceLevel = 0; // مستوى المقاومة
      private int lookbackPeriod = 20; // فترة المراقبة لتحديد القمم والقيعان

      protected override void OnStateChange()
      {
      if (State == State.SetDefaults)
      {
      Name = "SupportResistanceBot"; // اسم الاستراتيجية
      Calculate = Calculate.OnBarClose; // التنفيذ عند إغلاق كل شمعة
      EntriesPerDirection = 1; // صفقة واحدة لكل اتجاه
      ExitOnSessionClose = false; // عدم الإغلاق عند نهاية الجلسة
      IsInstantiatedOnEachOptimizationIteration = false;

      SetStopLoss(CalculationMode.Ticks, 10); // وقف الخسارة
      SetProfitTarget(CalculationMode.Ticks, 20); // هدف الربح
      }
      }

      protected override void OnBarUpdate()
      {
      // التحقق من وجود بيانات كافية
      if (CurrentBar < lookbackPeriod)
      return;

      // حساب مستويات الدعم والمقاومة
      supportLevel = MIN(Low, lookbackPeriod)[0];
      resistanceLevel = MAX(High, lookbackPeriod)[0];

      // إذا تجاوز السعر مستوى الدعم
      if (Close[0] > supportLevel && Close[1] <= supportLevel)
      {
      EnterLong(); // دخول صفقة شراء
      }
      // إذا تجاوز السعر مستوى المقاومة
      else if (Close[0] < resistanceLevel && Close[1] >= resistanceLevel)
      {
      EnterShort(); // دخول صفقة بيع
      }
      }
      }

      Comment


        #4
        Hello Gharib,

        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 of our clients as well as our associates.

        This thread will remain open for any community members that would like to debug or modify your script as a convenience to 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.

        You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more!
        Programming Services - https://ninjatraderecosystem.com/sea...mming-services
        Educators - https://ninjatraderecosystem.com/sea...ures=education

        You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third party services for NinjaTrader all pricing and support information will need to be obtained through the consultant.

        This NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.​
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        58 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        133 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X