Indicator conversion request for Stochastic Divergence
Forums › ProRealTime English forum › ProBuilder support › Indicator conversion request for Stochastic Divergence
- This topic has 2 replies, 1 voice, and was last updated 3 years ago by ginko.
Viewing 3 posts - 1 through 3 (of 3 total)
-
-
01/24/2017 at 12:22 PM #22250
Hi Nic and all,
Could I please request for this reliable indicator to be converted to PRT? I personally use it with success in my daytrading on the M15 timeframe.
Please see screenshot below for how it looks like in MT4. I’ve attached the MQ4 source code and file.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549//------------------------------------------------------------------#property copyright "www.forex-tsd.com"#property link "www.forex-tsd.com"//------------------------------------------------------------------#property indicator_separate_window#property indicator_buffers 4#property indicator_color1 Aqua#property indicator_color2 Magenta#property indicator_color3 LightSeaGreen#property indicator_color4 Red#property indicator_level1 80#property indicator_level2 20#property indicator_maximum 100#property indicator_minimum 0//////////extern string TimeFrame = "Current time frame";extern int StoKPeriod = 8;extern int StoDPeriod = 3;extern int StoSlowing = 3;extern int StoPrice = 0;extern int SignalMode = MODE_SMA;extern int DivergearrowSize = 0;extern double arrowsUpperGap = 0.25;extern double arrowsLowerGap = 0.25;extern bool drawDivergences = true;extern bool ShowClassicalDivergence = true;extern bool ShowHiddenDivergence = false;extern bool drawIndicatorTrendLines = true;extern bool drawPriceTrendLines = true;extern color divergenceBullishColor = Lime;extern color divergenceBearishColor = Red;extern string drawLinesIdentificator = "stochdiverge1";extern bool divergenceAlert = true;extern bool divergenceAlertsMessage = true;extern bool divergenceAlertsSound = true;extern bool divergenceAlertsEmail = false;extern bool divergenceAlertsNotify = false;extern string divergenceAlertsSoundName = "alert1.wav";extern bool alertsOn = true;extern bool alertsOnCurrent = true;extern bool alertsMessage = true;extern bool alertsSound = true;extern bool alertsNotify = true;extern bool alertsEmail = false;extern string soundFile = "alert2.wav";//////////double bullishDivergence[];double bearishDivergence[];double sto[];double sig[];double trend[];//////////string indicatorName;string labelNames;string indicatorFileName;bool calculateValue;bool returnBars;int timeFrame;//+------------------------------------------------------------------//|//+------------------------------------------------------------------//////////int init(){IndicatorBuffers(5);SetIndexBuffer(0,bullishDivergence); SetIndexStyle(0,DRAW_ARROW,0,DivergearrowSize); SetIndexArrow(0,233);SetIndexBuffer(1,bearishDivergence); SetIndexStyle(1,DRAW_ARROW,0,DivergearrowSize); SetIndexArrow(1,234);SetIndexBuffer(2,sto);SetIndexBuffer(3,sig);SetIndexBuffer(4,trend);//////////timeFrame = stringToTimeFrame(TimeFrame);labelNames = "Stochastic_DivergenceLine "+drawLinesIdentificator+":";indicatorName = timeFrameToString(timeFrame)+" Stochastic ("+StoKPeriod+","+StoDPeriod+","+StoSlowing+")";IndicatorShortName(indicatorName);//////////indicatorFileName = WindowExpertName();calculateValue = (TimeFrame=="calculateValue"); if (calculateValue) return(0);returnBars = (TimeFrame=="returnBars"); if (returnBars) return(0);return(0);}//////////int deinit(){int length=StringLen(labelNames);for(int i=ObjectsTotal()-1; i>=0; i--){string name = ObjectName(i);if(StringSubstr(name,0,length) == labelNames) ObjectDelete(name);}return(0);}//+------------------------------------------------------------------//|//+------------------------------------------------------------------//////////int start(){int i,limit,counted_bars=IndicatorCounted();if(counted_bars<0) return(-1);if(counted_bars>0) counted_bars--;limit = MathMin(Bars-counted_bars,Bars-1);if (returnBars) { bullishDivergence[0] = limit+1; return(0); }//////////if (calculateValue || timeFrame == Period()){for (i=limit; i>=0; i--){sto[i] = iStochastic(NULL,0,StoKPeriod,StoDPeriod,StoSlowing,SignalMode,StoPrice,MODE_MAIN ,i);sig[i] = iStochastic(NULL,0,StoKPeriod,StoDPeriod,StoSlowing,SignalMode,StoPrice,MODE_SIGNAL,i);trend[i] = trend[i+1];if (sto[i]>sig[i]) trend[i]= 1;if (sto[i]<sig[i]) trend[i]=-1;if (drawDivergences){CatchBullishDivergence(i);CatchBearishDivergence(i);}}manageAlerts();return(0);}//////////limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName,"returnBars",0,0)*timeFrame/Period()));for (i=limit;i>=0;i--){int y = iBarShift(NULL,timeFrame,Time[i]);sto[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",StoKPeriod,StoDPeriod,StoSlowing,StoPrice,SignalMode,DivergearrowSize,arrowsUpperGap,arrowsLowerGap,drawDivergences,ShowClassicalDivergence,ShowHiddenDivergence,drawIndicatorTrendLines,drawPriceTrendLines,divergenceBullishColor,divergenceBearishColor,drawLinesIdentificator,divergenceAlert,divergenceAlertsMessage,divergenceAlertsSound,divergenceAlertsEmail,divergenceAlertsNotify,divergenceAlertsSoundName,2,y);sig[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",StoKPeriod,StoDPeriod,StoSlowing,StoPrice,SignalMode,DivergearrowSize,arrowsUpperGap,arrowsLowerGap,drawDivergences,ShowClassicalDivergence,ShowHiddenDivergence,drawIndicatorTrendLines,drawPriceTrendLines,divergenceBullishColor,divergenceBearishColor,drawLinesIdentificator,divergenceAlert,divergenceAlertsMessage,divergenceAlertsSound,divergenceAlertsEmail,divergenceAlertsNotify,divergenceAlertsSoundName,3,y);bullishDivergence[i] = EMPTY_VALUE;bearishDivergence[i] = EMPTY_VALUE;int firstBar = iBarShift(NULL,0,iTime(NULL,timeFrame,y));if (i==firstBar){bullishDivergence[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",StoKPeriod,StoDPeriod,StoSlowing,StoPrice,SignalMode,DivergearrowSize,arrowsUpperGap,arrowsLowerGap,drawDivergences,ShowClassicalDivergence,ShowHiddenDivergence,drawIndicatorTrendLines,drawPriceTrendLines,divergenceBullishColor,divergenceBearishColor,drawLinesIdentificator,divergenceAlert,divergenceAlertsMessage,divergenceAlertsSound,divergenceAlertsEmail,divergenceAlertsNotify,divergenceAlertsSoundName,0,y);bearishDivergence[i] = iCustom(NULL,timeFrame,indicatorFileName,"calculateValue",StoKPeriod,StoDPeriod,StoSlowing,StoPrice,SignalMode,DivergearrowSize,arrowsUpperGap,arrowsLowerGap,drawDivergences,ShowClassicalDivergence,ShowHiddenDivergence,drawIndicatorTrendLines,drawPriceTrendLines,divergenceBullishColor,divergenceBearishColor,drawLinesIdentificator,divergenceAlert,divergenceAlertsMessage,divergenceAlertsSound,divergenceAlertsEmail,divergenceAlertsNotify,divergenceAlertsSoundName,1,y);}}manageAlerts();return(0);}//////////void CatchBullishDivergence(int shift){shift++;bullishDivergence[shift] = EMPTY_VALUE;ObjectDelete(labelNames+"l"+DoubleToStr(Time[shift],0));ObjectDelete(labelNames+"l"+"os" + DoubleToStr(Time[shift],0));if(!IsIndicatorLow(shift)) return;//////////int currentLow = shift;int lastLow = GetIndicatorLastLow(shift+1);if (sto[currentLow] > sto[lastLow] && Low[currentLow] < Low[lastLow]){if (ShowClassicalDivergence){bullishDivergence[currentLow] = sto[currentLow] - arrowsLowerGap * iATR(NULL,0,20,currentLow);if (drawPriceTrendLines) DrawPriceTrendLine("l",Time[currentLow],Time[lastLow],Low[currentLow],Low[lastLow], divergenceBullishColor,STYLE_SOLID);if (drawIndicatorTrendLines)DrawIndicatorTrendLine("l",Time[currentLow],Time[lastLow],sto[currentLow],sto[lastLow],divergenceBullishColor,STYLE_SOLID);if (divergenceAlert) DisplayAlert("Classical bullish divergence",currentLow);}}//////////if (sto[currentLow] < sto[lastLow] && Low[currentLow] > Low[lastLow]){if (ShowHiddenDivergence){bullishDivergence[currentLow] = sto[currentLow] - arrowsLowerGap * iATR(NULL,0,20,currentLow);if (drawPriceTrendLines) DrawPriceTrendLine("l",Time[currentLow],Time[lastLow],Low[currentLow],Low[lastLow], divergenceBullishColor, STYLE_DOT);if (drawIndicatorTrendLines) DrawIndicatorTrendLine("l",Time[currentLow],Time[lastLow],sto[currentLow], sto[lastLow],divergenceBullishColor, STYLE_DOT);if (divergenceAlert) DisplayAlert("Reverse bullish divergence",currentLow);}}}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+//////////void CatchBearishDivergence(int shift){shift++;bearishDivergence[shift] = EMPTY_VALUE;ObjectDelete(labelNames+"h"+DoubleToStr(Time[shift],0));ObjectDelete(labelNames+"h"+"os" + DoubleToStr(Time[shift],0));if(IsIndicatorPeak(shift) == false) return;int currentPeak = shift;int lastPeak = GetIndicatorLastPeak(shift+1);//////////if (sto[currentPeak] < sto[lastPeak] && High[currentPeak]>High[lastPeak]){if (ShowClassicalDivergence){bearishDivergence[currentPeak] = sto[currentPeak] + arrowsUpperGap * iATR(NULL,0,20,currentPeak);if (drawPriceTrendLines) DrawPriceTrendLine("h",Time[currentPeak],Time[lastPeak],High[currentPeak],High[lastPeak], divergenceBearishColor,STYLE_SOLID);if (drawIndicatorTrendLines) DrawIndicatorTrendLine("h",Time[currentPeak],Time[lastPeak],sto[currentPeak],sto[lastPeak],divergenceBearishColor,STYLE_SOLID);if (divergenceAlert) DisplayAlert("Classical bearish divergence",currentPeak);}}//////////if (sto[currentPeak] > sto[lastPeak] && High[currentPeak] < High[lastPeak]){if (ShowHiddenDivergence){bearishDivergence[currentPeak] = sto[currentPeak] + arrowsUpperGap * iATR(NULL,0,20,currentPeak);if (drawPriceTrendLines) DrawPriceTrendLine("h",Time[currentPeak],Time[lastPeak],High[currentPeak],High[lastPeak], divergenceBearishColor, STYLE_DOT);if (drawIndicatorTrendLines) DrawIndicatorTrendLine("h",Time[currentPeak],Time[lastPeak],sto[currentPeak],sto[lastPeak],divergenceBearishColor, STYLE_DOT);if (divergenceAlert) DisplayAlert("Reverse bearish divergence",currentPeak);}}}//////////bool IsIndicatorPeak(int shift){if(sto[shift] >= sto[shift+1] && sto[shift] > sto[shift+2] && sto[shift] > sto[shift-1])return(true);elsereturn(false);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+////bool IsIndicatorLow(int shift){if(sto[shift] <= sto[shift+1] && sto[shift] < sto[shift+2] && sto[shift] < sto[shift-1])return(true);elsereturn(false);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+////int GetIndicatorLastPeak(int shift){for(int i = shift+5; i < Bars; i++){if(sto[i] >= sto[i+1] && sto[i] > sto[i+2] && sto[i] >= sto[i-1] && sto[i] > sto[i-2])return(i);}return(-1);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+////int GetIndicatorLastLow(int shift){for (int i = shift+5; i < Bars; i++){if (sto[i] <= sto[i+1] && sto[i] < sto[i+2] && sto[i] <= sto[i-1] && sto[i] < sto[i-2])return(i);}return(-1);}//////////void DisplayAlert(string doWhat, int shift){string dmessage;static datetime lastAlertTime;if(shift <= 2 && Time[0] != lastAlertTime){dmessage = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Stochastic ",doWhat);if (divergenceAlertsMessage) Alert(dmessage);if (divergenceAlertsNotify) SendNotification(dmessage);if (divergenceAlertsEmail) SendMail(StringConcatenate(Symbol()," Stochastic "),dmessage);if (divergenceAlertsSound) PlaySound(divergenceAlertsSoundName);lastAlertTime = Time[0];}}//////////void DrawPriceTrendLine(string first,datetime t1, datetime t2, double p1, double p2, color lineColor, double style){string label = labelNames+first+"os"+DoubleToStr(t1,0);ObjectDelete(label);ObjectCreate(label, OBJ_TREND, 0, t1, p1, t2, p2, 0, 0);ObjectSet(label, OBJPROP_RAY, 0);ObjectSet(label, OBJPROP_COLOR, lineColor);ObjectSet(label, OBJPROP_STYLE, style);ObjectSet(label, OBJPROP_WIDTH, 2);}//////////void DrawIndicatorTrendLine(string first,datetime t1, datetime t2, double p1, double p2, color lineColor, double style){int indicatorWindow = WindowFind(indicatorName);if (indicatorWindow < 0) return;//////////string label = labelNames+first+DoubleToStr(t1,0);ObjectDelete(label);ObjectCreate(label, OBJ_TREND, indicatorWindow, t1, p1, t2, p2, 0, 0);ObjectSet(label, OBJPROP_RAY, 0);ObjectSet(label, OBJPROP_COLOR, lineColor);ObjectSet(label, OBJPROP_STYLE, style);ObjectSet(label, OBJPROP_WIDTH, 2);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+//////////string sTfTable[] = {"M1","M5","M15","M30","H1","H4","D1","W1","MN"};int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};//////////int stringToTimeFrame(string tfs){tfs = StringUpperCase(tfs);for (int i=ArraySize(iTfTable)-1; i>=0; i--)if (tfs==sTfTable[i] || tfs==""+iTfTable[i]) return(MathMax(iTfTable[i],Period()));return(Period());}string timeFrameToString(int tf){for (int i=ArraySize(iTfTable)-1; i>=0; i--)if (tf==iTfTable[i]) return(sTfTable[i]);return("");}//////////string StringUpperCase(string str){string s = str;for (int length=StringLen(str)-1; length>=0; length--){int tchar = StringGetChar(s, length);if((tchar > 96 && tchar < 123) || (tchar > 223 && tchar < 256))s = StringSetChar(s, length, tchar - 32);else if(tchar > -33 && tchar < 0)s = StringSetChar(s, length, tchar + 224);}return(s);}//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+//////////void manageAlerts(){if (alertsOn){if (alertsOnCurrent)int whichBar = 0;else whichBar = 1; whichBar = iBarShift(NULL,0,iTime(NULL,timeFrame,whichBar));if (trend[whichBar] != trend[whichBar+1]){if (trend[whichBar] == 1) doAlert(whichBar,"crossing signal up");if (trend[whichBar] ==-1) doAlert(whichBar,"crossing signal down");}}}//////////void doAlert(int forBar, string doWhat){static string previousAlert="nothing";static datetime previousTime;string message;if (previousAlert != doWhat || previousTime != Time[forBar]) {previousAlert = doWhat;previousTime = Time[forBar];//////////message = StringConcatenate(Symbol()," ",timeFrameToString(timeFrame)," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Stochastic ",doWhat);if (alertsMessage) Alert(message);if (alertsNotify) SendNotification(message);if (alertsEmail) SendMail(StringConcatenate(Symbol(), Period(), " Stochastic "),message);if (alertsSound) PlaySound(soundFile);}}01/26/2017 at 1:58 PM #22582stochastic divergence indicator can already be found in this forum topic: https://www.prorealcode.com/topic/programming-divergence-of-stochastic/
10/21/2021 at 1:12 PM #180073 -
AuthorPosts
Viewing 3 posts - 1 through 3 (of 3 total)
Find exclusive trading pro-tools on
Similar topics: