Category Trend  Published on 17/08/2024

AGNES 2.0

Description

// Parameters
input int K_period = 21;
input int D_period = 3;
input int Slowing = 3;
input int ATR_period = 21;
input double ATR_multiplier = 2.0;

// Indicator Handles
int K_handle, D_handle;
double K_value[], D_value[];
double ATR_value[];

// OnInit - Initialize indicators
int OnInit() {
  K_handle = iStochastic(NULL, 0, K_period, D_period, Slowing, MODE_SMA, 0, MODE_MAIN);
  D_handle = iStochastic(NULL, 0, K_period, D_period, Slowing, MODE_SMA, 0, MODE_SIGNAL);
  ArraySetAsSeries(K_value, true);
  ArraySetAsSeries(D_value, true);
  
  return(INIT_SUCCEEDED);
}

// OnCalculate - Main calculation loop
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[],
               const double &open[], const double &high[], const double &low[],
               const double &close[], const long &tick_volume[], const long &volume[],
               const int &spread[]) {

  // Calculate Stochastic Oscillator
  CopyBuffer(K_handle, 0, 0, rates_total, K_value);
  CopyBuffer(D_handle, 1, 0, rates_total, D_value);

  // Calculate ATR
  double atr = iATR(NULL, 0, ATR_period, 0);
  double upper_band = close[0] + ATR_multiplier * atr;
  double lower_band = close[0] - ATR_multiplier * atr;

  // Generate signals
  for(int i = rates_total - 1; i >= 0; i--) {
     bool longBuySignal = K_value[i] < 20 && K_value[i] > D_value[i] && close[i] > lower_band;
     bool longSellSignal = K_value[i] > 80 && K_value[i] < D_value[i] && close[i] < upper_band;
     bool scalpBuySignal = K_value[i] < 80 && K_value[i] > D_value[i] && close[i] > lower_band;
     bool scalpSellSignal = K_value[i] > 20 && K_value[i] < D_value[i] && close[i] < upper_band;

     if (longBuySignal) {
        // Draw a blue sun for a long buy signal
        ObjectCreate("LongBuy" + i, OBJ_ARROW, 0, time[i], close[i]);
        ObjectSetInteger(0, "LongBuy" + i, OBJPROP_COLOR, clrBlue);
        ObjectSetInteger(0, "LongBuy" + i, OBJPROP_ARROWCODE, SYMBOL_CIRCLE);
     } 
     if (longSellSignal) {
        // Draw a red sun for a long sell signal
        ObjectCreate("LongSell" + i, OBJ_ARROW, 0, time[i], close[i]);
        ObjectSetInteger(0, "LongSell" + i, OBJPROP_COLOR, clrRed);
        ObjectSetInteger(0, "LongSell" + i, OBJPROP_ARROWCODE, SYMBOL_CIRCLE);
     } 
     if (scalpBuySignal) {
        // Draw a blue arrow for a scalp buy signal
        ObjectCreate("ScalpBuy" + i, OBJ_ARROW, 0, time[i], close[i]);
        ObjectSetInteger(0, "ScalpBuy" + i, OBJPROP_COLOR, clrBlue);
        ObjectSetInteger(0, "ScalpBuy" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
     }
     if (scalpSellSignal) {
        // Draw a red arrow for a scalp sell signal
        ObjectCreate("ScalpSell" + i, OBJ_ARROW, 0, time[i], close[i]);
        ObjectSetInteger(0, "ScalpSell" + i, OBJPROP_COLOR, clrRed);
        ObjectSetInteger(0, "ScalpSell" + i, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
     }
  }

  return(rates_total);
}


The author decided to hide the source code.
MA
mantsiandile4

Joined on 17.08.2024

  • Distribution: Paid
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: New cBot (7).algo.txt
  • Rating: 5
  • Installs: 0
  • Modified: 17/08/2024 04:05
Comments
Log in to add a comment.
No comments found.