-
SetIndexBuffer(0, GreenBuffer); SetIndexBuffer(1, RedBuffer);
How many plots and buffers did you declare your indicator uses?
-
#include <Trade\Trade.mqh>
Indicators can not trade. EAs do not have buffers.
William Roeder #:
-
How many plots and buffers did you declare your indicator uses?
-
Indicators can not trade. EAs do not have buffers.
#property indicator_chart_window #property indicator_buffers 2 #property indicator_color1 clrGreen #property indicator_color2 clrRed double GreenBuffer[]; double RedBuffer[]; int OnInit() { SetIndexBuffer(0, GreenBuffer, INDICATOR_DATA); SetIndexBuffer(1, RedBuffer, INDICATOR_DATA); IndicatorSetString(INDICATOR_SHORTNAME, "Buy Sell Volume %"); CreateLabel(); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectsDeleteAll(0, "Label"); } 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[]) { for(int i = prev_calculated; i < rates_total; i++) { calculateVolumePercentages(i, open, close, tick_volume); updateLabel(i, time); } return(rates_total); } void calculateVolumePercentages(int index, const double &open[], const double &close[], const long &volume[]) { if(index < 10) return; double green_volume = 0.0; double red_volume = 0.0; bool is_volume_zero = true; for(int i = 0; i < 10; i++) { if(volume[index - i] != 0) { is_volume_zero = false; } if(close[index - i] > open[index - i]) { green_volume += (double)volume[index - i]; } else { red_volume += (double)volume[index - i]; } } if(is_volume_zero) { Print("Volume data is zero for all 10 bars."); } double total_volume = green_volume + red_volume; if(total_volume != 0) { GreenBuffer[index] = (green_volume / total_volume) * 100.0; RedBuffer[index] = (red_volume / total_volume) * 100.0; } else { GreenBuffer[index] = 0; RedBuffer[index] = 0; } } void CreateLabel() { ObjectCreate(0, "Label", OBJ_LABEL, 0, 0, 0); ObjectSetInteger(0, "Label", OBJPROP_CORNER, CORNER_LEFT_UPPER); ObjectSetInteger(0, "Label", OBJPROP_XDISTANCE, 600); ObjectSetInteger(0, "Label", OBJPROP_YDISTANCE, 10); } void updateLabel(int index, const datetime &time[]) { if(index < 10) return; string symbol = Symbol(); string time_str = TimeToString(time[index], TIME_DATE|TIME_MINUTES); ObjectSetString(0, "Label", OBJPROP_TEXT, "Buy: " + DoubleToString(GreenBuffer[index], 2) + "%. Sell: " + DoubleToString(RedBuffer[index], 2) + "%"); Print("Volume for " + symbol + " at " + time_str + " is : Buy: " + DoubleToString(GreenBuffer[index], 2) + "%. Sell: " + DoubleToString(RedBuffer[index], 2) + "%."); }This is my Indicator code on basis of it I am trying to make a EA which will buy and sell if either one of the volume percentage is 60% or above

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I get this error while backtesting the EA 2023.07.27 13:52:46.704 VolumeEA (USDCHF,M5) array out of range in 'VolumeEA.mq5' (94,19) Please can anyone help whats wrong with the code ?