extern int boxp = 5; extern double tpMultiplier = 2.0; extern color slCol = Red; extern color tpCol = Lime; extern int slW = 3; extern int tpW = 3; double TopBoxBuffer[]; double BottomBoxBuffer[]; double SL_BuyBuffer[]; double SL_SellBuffer[]; double TP_BuyBuffer[]; double TP_SellBuffer[]; bool buyActive = false; bool sellActive = false; int OnInit() { IndicatorBuffers(4); SetIndexStyle(0, DRAW_LINE); SetIndexBuffer(0, TopBoxBuffer); SetIndexLabel(0, "TBbox"); SetIndexStyle(1, DRAW_LINE); SetIndexBuffer(1, BottomBoxBuffer); SetIndexLabel(1, "BBbox"); SetIndexStyle(2, DRAW_ARROW); SetIndexBuffer(2, SL_BuyBuffer); SetIndexLabel(2, "Long SL"); SetIndexStyle(3, DRAW_ARROW); SetIndexBuffer(3, TP_BuyBuffer); SetIndexLabel(3, "Long TP"); return INIT_SUCCEEDED; } int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double& price[]) { int limit = rates_total - prev_calculated; for (int i = 0; i < limit && i < boxp; i++) { double LL = Low[iLowest(NULL, 0, MODE_LOW, boxp, i)]; double k1 = High[iHighest(NULL, 0, MODE_HIGH, boxp, i)]; double k2 = High[iHighest(NULL, 0, MODE_HIGH, boxp - 1, i)]; double k3 = High[iHighest(NULL, 0, MODE_HIGH, boxp - 2, i)]; double NH = 0.0; for (int j = i; j < MathMin(i + boxp, rates_total); j++) { if (price[j] > k1) { NH = price[j]; } } bool box1 = k3 < k2; TopBoxBuffer[i] = box1 && iHighest(NULL, 0, MODE_HIGH, 2, i) == k1 ? NH : EMPTY_VALUE; BottomBoxBuffer[i] = box1 && iHighest(NULL, 0, MODE_HIGH, 2, i) == k1 ? LL : EMPTY_VALUE; if (i > 0) { bool Buy = price[i - 1] > TopBoxBuffer[i - 1] && !buyActive && !sellActive; bool Sell = price[i - 1] < BottomBoxBuffer[i - 1] && !sellActive && !buyActive; if (Buy) { buyActive = true; sellActive = false; SL_BuyBuffer[i - 1] = price[i - 1]; TP_BuyBuffer[i - 1] = price[i - 1] + (price[i - 1] - price[i - 2]) * tpMultiplier; ObjectCreate(ChartID(), "SL_BuyArrow", OBJ_ARROW, 0, i - 1, price[i - 1]); ObjectSetInteger(ChartID(), "SL_BuyArrow", OBJPROP_ARROWCODE, 233); ObjectSetInteger(ChartID(), "SL_BuyArrow", OBJPROP_COLOR, slCol); ObjectSetInteger(ChartID(), "SL_BuyArrow", OBJPROP_WIDTH, slW); ObjectCreate(ChartID(), "TP_BuyArrow", OBJ_ARROW, 0, i - 1, TP_BuyBuffer[i - 1]); ObjectSetInteger(ChartID(), "TP_BuyArrow", OBJPROP_ARROWCODE, 234); ObjectSetInteger(ChartID(), "TP_BuyArrow", OBJPROP_COLOR, tpCol); ObjectSetInteger(ChartID(), "TP_BuyArrow", OBJPROP_WIDTH, tpW); } else if (Sell) { sellActive = true; buyActive = false; SL_BuyBuffer[i - 1] = price[i - 1]; TP_BuyBuffer[i - 1] = price[i - 1] - (price[i - 2] - price[i - 1]) * tpMultiplier; ObjectCreate(ChartID(), "SL_SellArrow", OBJ_ARROW, 0, i - 1, price[i - 1]); ObjectSetInteger(ChartID(), "SL_SellArrow", OBJPROP_ARROWCODE, 234); ObjectSetInteger(ChartID(), "SL_SellArrow", OBJPROP_COLOR, slCol); ObjectSetInteger(ChartID(), "SL_SellArrow", OBJPROP_WIDTH, slW); ObjectCreate(ChartID(), "TP_SellArrow", OBJ_ARROW, 0, i - 1, TP_BuyBuffer[i - 1]); ObjectSetInteger(ChartID(), "TP_SellArrow", OBJPROP_ARROWCODE, 233); ObjectSetInteger(ChartID(), "TP_SellArrow", OBJPROP_COLOR, tpCol); ObjectSetInteger(ChartID(), "TP_SellArrow", OBJPROP_WIDTH, tpW); } } } return rates_total; }