#property copyright "2022, IonOne" #property link "http://forex-station.com" #property strict #property indicator_chart_window #property indicator_buffers 7 #property indicator_color1 Yellow #property indicator_color2 Red #property indicator_color3 Yellow #property indicator_width1 4 #property indicator_width2 4 #property indicator_width3 2 extern int bars = 10000; extern string s23141SS="";//_ extern string s2345="Settings CCI";//_ extern int CCIPeriod = 4;//period CCI extern int thrCCI = -50;//threshold CCI extern string s2314SS="";//_ extern string s213S45="Settings RSI";//_ extern int RSIPeriod = 2;//period RSI extern int thrRSI = 25;//threshold RSI enum type_ { type_RSI, //RSI type_CCI, //CCI type_confluence // Confluence of Both }; enum typeExit_ { firstSignal, //first signal bothSignals // both signals }; extern string s231224SS="";//_ extern string s234SS="Settings Confluence";//_ extern type_ type = type_RSI;//entry Type extern typeExit_ typeExit = bothSignals;//exit Type int trades = 0; string s1112 = "";//_ string emp1 = "/////////////arrows settings////////////"; int arrow_code_up = 233; int arrow_code_down = 234; color arrow_color_up = clrLime; color arrow_color_down = clrRed; int arrows_width = 4; double rsiS[]; double bars_[]; double up_arr[];//! double dn_arr[];//! double st_arr[];//! double profit_[]; double drawdown[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { bars = bars / (PeriodSeconds(PERIOD_CURRENT) / double(PeriodSeconds(PERIOD_H1))); Print("Bars = ",bars); SetIndexBuffer(0,up_arr); SetIndexStyle(0,DRAW_ARROW,EMPTY,arrows_width,arrow_color_up); SetIndexArrow(0,arrow_code_up); SetIndexLabel(0,"UP arrow"); SetIndexBuffer(1,dn_arr); SetIndexStyle(1,DRAW_ARROW,EMPTY,arrows_width,arrow_color_down); SetIndexArrow(1,arrow_code_down); SetIndexLabel(1,"DOWN arrow"); SetIndexBuffer(2,st_arr); SetIndexStyle(2,DRAW_ARROW,EMPTY,4,clrYellow); SetIndexArrow(2,251); SetIndexLabel(2,"stop"); //SetIndexStyle(3,DRAW_LINE); //SetIndexBuffer(3,rsiS); SetIndexBuffer(4,profit_); SetIndexStyle(4,DRAW_NONE); SetIndexBuffer(5,bars_); SetIndexStyle(5,DRAW_NONE); SetIndexBuffer(6,drawdown); SetIndexStyle(6,DRAW_NONE); ArrayInitialize(drawdown, -EMPTY_VALUE); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ double max = -EMPTY_VALUE, min = EMPTY_VALUE; double dd = -EMPTY_VALUE; void ComputeDrawDown(int i) { if (last == -1) return; if (lastPrice <= 0) return; double v = 0;; double w = 0;; if ((last == 0)) { v = (iHigh(NULL,0,i) - lastPrice)/lastPrice; w = (iLow(NULL,0,i) - lastPrice)/lastPrice; } else if ((last == 1)) { v = (lastPrice - iLow(NULL,0,i))/lastPrice; w = (lastPrice - iHigh(NULL,0,i))/lastPrice; } double equity1 = profit + v; double equity2 = profit + w; if (equity1 > maxEquity) maxEquity = equity1; if (maxEquity - equity2 > dd) dd = maxEquity - equity2; } datetime tim; double maxEquity = -EMPTY_VALUE; double price; int arrows = 0; datetime timBar; double b0; double b1; double bb0; double bb1; double lastPrice; int last = -1; double profit = 0; int lasti = 0; int lst = -1; double ma0,ma1; int lastS = -1; int trend = -1; bool once = true; datetime timEntry = -1; int trendi = 0; bool Trend,previousEntry,previousExit; int length = 0; int lastTrend = 0; int alternate; int wins = 0; int start() { //---- int limit; int CountedBars=IndicatorCounted(); if(CountedBars>Bars-1) CountedBars=Bars-1; if(CountedBars<0) return(-1); if(CountedBars>0) CountedBars--; if(CountedBars<10) CountedBars = 10; limit=MathMin(Bars-1-CountedBars, bars); once = false; datetime tim = TimeCurrent(); int i = limit; while(i>0) // Öèêë ïî íåïîñ÷èòàííûì áàðàì { int shift = 0; bool exact = false; double rsi0,cci0; double rsi1,cci1; if (type == type_RSI || type == type_confluence) { rsi0 = iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i); rsi1 = iRSI(NULL,0,RSIPeriod,PRICE_CLOSE,i+1); } if (type == type_CCI || type == type_confluence) { cci0 = iCCI(NULL,0,CCIPeriod,PRICE_CLOSE,i); cci1 = iCCI(NULL,0,CCIPeriod,PRICE_CLOSE,i+1); } bool buy=0,sell=0; bool exitBuy=0,exitSell=0; double atr0 = iATR(NULL,0,14, i+shift); double atrDist0 = iATR(NULL,0,14, i+shift); double atrDist1 = iATR(NULL,0,14, i+shift+1); int hh = iHighest(NULL,0,MODE_HIGH,410,i); int ll = iLowest(NULL,0,MODE_LOW,410,i); double highest = iHigh(NULL,0,hh); double lowest = iLow(NULL,0,ll); double high0 = iHigh(NULL,0,i+shift); double low0 = iLow(NULL,0,i+shift); double high1 = iHigh(NULL,0,i+shift+1); double low1 = iLow(NULL,0,i+shift+1); double maEntry0 = iMA(NULL,0,20,0,MODE_EMA,PRICE_CLOSE,i); double ma0 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,i); double ma1 = iMA(NULL,0,200,0,MODE_EMA,PRICE_CLOSE,i+1); double c0 = iClose(NULL,0,i+shift); double o0 = iOpen(NULL,0,i+shift); double c1 = iClose(NULL,0,i+1+shift); double o1 = iOpen(NULL,0,i+1+shift); double entryPrice; double exitPrice; if ((last == -1) && ((type == type_RSI && rsi0 < thrRSI && rsi1 >= thrRSI) || (type == type_CCI && cci0 < thrCCI && cci1 >= thrCCI) || (type == type_confluence && rsi0 < thrRSI && rsi1 >= thrRSI && cci0 < thrCCI && cci1 >= thrCCI))) { buy = true; entryPrice = c0; } else if ((last == -1) && ((type == type_RSI && rsi0 > 100-thrRSI && rsi1 <= 100-thrRSI) || (type == type_CCI && cci0 > -thrCCI && cci1 <= -thrCCI) || (type == type_confluence && rsi0 > 100-thrRSI && rsi1 <= 100-thrRSI && cci0 > -thrCCI && cci1 <= -thrCCI))) { sell = true; entryPrice = c0; } if (last == 1 && ((type == type_RSI && rsi0 < thrRSI && rsi1 >= thrRSI) || (type == type_CCI && cci0 < thrCCI && cci1 >= thrCCI) || (type == type_confluence && ((typeExit == firstSignal && ((rsi0 < thrRSI && rsi1 >= thrRSI) || (cci0 < thrCCI && cci1 >= thrCCI))) || (typeExit == bothSignals && ((rsi0 < thrRSI && cci0 < thrCCI))))))) { exitSell = true; exitPrice = c0; } else if (last == 0 && ((type == type_RSI && rsi0 > 100-thrRSI && rsi1 <= 100-thrRSI) || (type == type_CCI && cci0 > -thrCCI && cci1 <= -thrCCI) || (type == type_confluence && ((typeExit == firstSignal && ((rsi0 > 100-thrRSI && rsi1 <= 100-thrRSI) || (cci0 > -thrCCI && cci1 <= -thrCCI))) || (typeExit == bothSignals && ((rsi0 > 100-thrRSI && cci0 > -thrCCI))))))) { exitBuy = true; exitPrice = c0; } double cEntry0 = iClose(NULL,0,i+shift); //pas une erreur, sinon on a le prix close "Entry" qui arrive plus tard double cExit0 = iClose(NULL,0,i+shift); lasti++; if (last > -1) ComputeDrawDown(i+shift); //bool waitHigherTFClose = true; bool nbEntry = false; if (timEntry != iTime(NULL,0,i+shift)) { if (timEntry > -1) nbEntry = true; timEntry = iTime(NULL,0,i+shift); } if (lasti > 0) { if (last == 0 && exitBuy) { double c = exitPrice; if (lastPrice > 0) profit += (c - lastPrice)/lastPrice; last = -1; st_arr[i+shift] = c; if (c > lastPrice) wins++; } if (last == 1 && exitSell) { double c = exitPrice; if (lastPrice > 0) profit += (lastPrice - c)/lastPrice; last = -1; st_arr[i+shift] = c; if (c < lastPrice) wins++; } } { if (/*(lst == 1 || lst == -1) &&*/ last == -1 && buy/* && c0 >= level*/) { lastPrice = entryPrice; up_arr[i+shift] = iLow(NULL,0,i+shift) - atr0; last = 0; lasti = 0; lst = 0; trades++; } if (/*(lst == 0 || lst == -1) && */last == -1 && sell/* && c0 <= 100-level*/) { lastPrice = entryPrice; dn_arr[i+shift] = iHigh(NULL,0,i+shift) + atr0; last = 1; lasti = 0; lst = 1; trades++; } } i--; } drawdown[0*0] = dd; profit_[0*0] = profit; bars_[0*0] = bars; static bool once = true; if (1) if (once) { Print("Profit = ",profit); Print("dd = ",drawdown[0]); Print("Trades = ",trades); if (trades > 0) Print("HR = ",100*wins/double(trades)); Print("duration processing = ",(int)(TimeCurrent() - tim)); } once = false; //---- return(0); } //+------------------------------------------------------------------+