EA-nsnd on mt4

EA-nsnd on mt4

Loibustian

// Expert initialization function

int OnInit()

{

  // Initialize variables or indicators if needed

  return(INIT_SUCCEEDED);

}


// Expert deinitialization function

void OnDeinit(const int reason)

{

  // Clean up

}


// Main function for the Expert Advisor

void OnTick()

{

  int lookback = 10; // Number of bars to look back for analysis

  double lotSize = 0.01; // Lot size for the orders

  double takeProfit = 10 * Point; // Take profit in points (10 pips)

  double stopLoss = 20 * Point; // Stop loss in points (20 pips)


  for (int i = 0; i < lookback; i++)

  {

    double volCurrent = iVolume(NULL, 0, i); // Current bar volume

    double volPrevious1 = iVolume(NULL, 0, i + 1); // Previous bar volume

    double volPrevious2 = iVolume(NULL, 0, i + 2); // Two bars ago volume


    // Check if current volume is less than the previous two

    if (volCurrent < volPrevious1 && volCurrent < volPrevious2)

    {

      double price = Close[i]; // Current price level


      // Check for No Demand (uptrend and current candle is bullish)

      if (Close[i] > Open[i])

      {

        // Draw "ND" label on the chart

        string ndLabel = "ND" + IntegerToString(i);

        ObjectCreate(0, ndLabel, OBJ_TEXT, 0, Time[i], High[i] + (Point * 10));

        ObjectSetText(ndLabel, "ND", 12, "Arial", clrGreen);

        ObjectSetInteger(0, ndLabel, OBJPROP_COLOR, clrGreen);


        // Open a sell order (expecting price to drop)

        OrderSend(Symbol(), OP_SELL, lotSize, Bid, 3, Bid + stopLoss, Bid - takeProfit, "No Demand Sell", 0, 0, clrRed);

      }


      // Check for No Supply (downtrend and current candle is bearish)

      if (Close[i] < Open[i])

      {

        // Draw "NS" label on the chart

        string nsLabel = "NS" + IntegerToString(i);

        ObjectCreate(0, nsLabel, OBJ_TEXT, 0, Time[i], Low[i] - (Point * 10));

        ObjectSetText(nsLabel, "NS", 12, "Arial", clrRed);

        ObjectSetInteger(0, nsLabel, OBJPROP_COLOR, clrRed);


        // Open a buy order (expecting price to rise)

        OrderSend(Symbol(), OP_BUY, lotSize, Ask, 3, Ask - stopLoss, Ask + takeProfit, "No Supply Buy", 0, 0, clrGreen);

      }

    }

  }

}


Report Page