//+------------------------------------------------------------------+ //| AreaBreaker.mq5 | //| Copyright 2021, Nkondog Anselme Venceslas | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2021, Nkondog Anselme Venceslas" #property link "https://www.mql5.com" #property version "1.00" #include // Description of variables #include // Error library #include // Prechecks #include // #include #include // Scan for opened positions #include //Check transaction history #include //Manage trade dynamic open and close conditions #include // Check buy and sell entries signals and execute them #include // Lot size calculate //#include //Draw trading range boundaries on chart //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ //Zigzag drawing inputs string prefix = "SRLevel_"; //Object name prefix color lineColor = clrYellow; int lineWeight = 2; double SRLevels[]; double Buffer[]; int Handle; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int OnInit() { //--- Handle = iCustom(Symb, PERIOD_CURRENT, "Examples\\ZigZag", Depth, Deviation, Backstep); if(Handle==INVALID_HANDLE) { Print("Could not create a handle to ZigZag indicator"); return(INIT_FAILED); } //Clean up any SR levels left from earlier indicators ObjectsDeleteAll(0, prefix, 0, OBJ_HLINE); ChartRedraw(0); ArrayResize(SRLevels, LookBack); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- IndicatorRelease(Handle); ObjectsDeleteAll(0, prefix, 0, OBJ_HLINE); ChartRedraw(0); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- ArraySetAsSeries(Buffer,true); CopyBuffer(Handle, 0, 0, 3, Buffer); if(candleChanged()) if(Buffer[0]>0) Print("Zigzag level ", Buffer[0]); //DrawLevels(); SymbolInfoTick(_Symbol,last_tick); if(!ScanPositions()) return; CheckHistory(); CheckSpread(); EvaluateEntry(); ProfitRunner(); CloseOpenPositions(); ExecuteEntry(); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ /* 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[]) { //One time convert points to a price gap static double levelGap = GapPoint*SymbolInfoDouble(Symb, SYMBOL_POINT); if(rates_total ==prev_calculated) return(rates_total); //Get most recent lookback peaks double zz =0; double zzPeaks[]; int zzCount = 0; ArrayResize(zzPeaks, LookBack); ArrayInitialize(zzPeaks, 0.0); int count = CopyBuffer(Handle, 0, 0, rates_total, Buffer); if(count < 0) { int err = GetLastError(); return(0); } for(int i=1; i=0; i--) { price += zzPeaks[i]; priceCount++; if(i=0 || (zzPeaks[i]-zzPeaks[i-1]) > GapPoint) { if(priceCount >= Sensitivity) { price = price/priceCount; SRLevels[srCounter] = price; srCounter++; } price =0; priceCount=0; } } DrawLevels(); //--- return value of prev_calculated for next call return(rates_total); } */ //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void DrawLevels() { for(int i=0; i