Support Board
Date/Time: Wed, 08 Jan 2025 18:00:26 +0000
Post From: Looking to replicate StochRSI osc fromMT4 in Sierra
[2016-07-01 00:09:51] |
User113734 - Posts: 60 |
It is my understanding that most Stoch RSI indicators can add K period and slow period... is that something Sierra can deliver in its StochRSI? If it helps, find below the MT4 code: #property indicator_separate_window #property indicator_levelcolor PaleTurquoise #property indicator_buffers 1 #property indicator_color1 Lime #property indicator_width1 2 #property indicator_level1 20.0 #property indicator_level2 80.0 extern int RSIPeriod = 8; extern int PeriodK = 8; extern int SlowPeriod = 3; double gda_88[]; double g_ibuf_92[]; double gda_96[]; bool gi_100 = FALSE; string gs_104; int init() { IndicatorBuffers(1); SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2); SetIndexBuffer(0, g_ibuf_92); SetIndexDrawBegin(0, RSIPeriod); gs_104 = "MT4-StochasticRSI-Oscillator-" + "v1.1" + " (" + RSIPeriod + "," + PeriodK + "," + SlowPeriod + ")"; IndicatorShortName(gs_104); SetIndexLabel(0, gs_104); ArraySetAsSeries(gda_88, TRUE); ArraySetAsSeries(gda_96, TRUE); Print(gs_104); Print("Copyright (c) 2007 - Bruce Hellstrom, bhweb@speakeasy.net"); return (0); } int deinit() { return (0); } int start() { double ld_12; double ld_20; int li_0 = IndicatorCounted(); if (li_0 < 0) return (-1); if (li_0 > 0) li_0--; if (ArraySize(gda_88) != ArraySize(g_ibuf_92)) { ArraySetAsSeries(gda_88, FALSE); ArrayResize(gda_88, ArraySize(g_ibuf_92)); ArraySetAsSeries(gda_88, TRUE); } if (ArraySize(gda_96) != ArraySize(g_ibuf_92)) { ArraySetAsSeries(gda_96, FALSE); ArrayResize(gda_96, ArraySize(g_ibuf_92)); ArraySetAsSeries(gda_96, TRUE); } int li_4 = Bars - li_0; for (int li_8 = 0; li_8 < li_4; li_8++) { gda_88[li_8] = iRSI(NULL, 0, RSIPeriod, PRICE_CLOSE, li_8); if (gi_100) if (gda_88[li_8] > 100.0) Print("Bar: ", li_8, " RSI: ", gda_88[li_8]); } for (li_8 = 0; li_8 < li_4; li_8++) { ld_12 = LLV(gda_88, PeriodK, li_8); ld_20 = HHV(gda_88, PeriodK, li_8); if (ld_20 - ld_12 > 0.0) { gda_96[li_8] = 100.0 * ((gda_88[li_8] - ld_12) / (ld_20 - ld_12)); if (gi_100 && li_8 < 100) if (gda_96[li_8] > 100.0) Print("Bar: ", li_8, " TempBuffer: ", gda_96[li_8], " RSI: ", gda_88[li_8], " hhv: ", ld_20, " llv:", ld_12); } } for (li_8 = 0; li_8 < li_4; li_8++) g_ibuf_92[li_8] = iMAOnArray(gda_96, 0, SlowPeriod, 0, MODE_EMA, li_8); return (0); } double LLV(double ada_0[], int ai_4, int ai_8) { double ld_ret_12 = 0.0; int li_20 = ai_8; for (int li_24 = li_20; li_24 < li_20 + ai_4; li_24++) { if (li_24 == li_20) ld_ret_12 = ada_0[li_24]; ld_ret_12 = MathMin(ld_ret_12, ada_0[li_24]); } return (ld_ret_12); } double HHV(double ada_0[], int ai_4, int ai_8) { double ld_ret_12 = 0.0; int li_20 = ai_8; for (int li_24 = li_20; li_24 < li_20 + ai_4; li_24++) { if (li_24 == li_20) ld_ret_12 = ada_0[li_24]; ld_ret_12 = MathMax(ld_ret_12, ada_0[li_24]); } return (ld_ret_12); } |