Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #property copyright "modified vertex by eR"
- #property link "modified vertex by eR"
- #property indicator_separate_window
- #property indicator_buffers 8
- #property indicator_color1 Red
- #property indicator_color2 clrNONE
- #property indicator_color3 clrNONE
- #property indicator_color4 clrNONE
- #property indicator_levelcolor MediumOrchid
- #property indicator_maximum 12.0
- #property indicator_minimum -12.0
- #property indicator_level1 -6.0
- #property indicator_level2 6.0
- #property indicator_level3 -10.0
- #property indicator_level4 10.0
- #property indicator_levelstyle 2
- extern int Processed = 1000;
- extern int Control_Period = 14;
- //int Signal_Period = 5;
- //int Signal_Method = MODE_SMA;
- //int BB_Up_Period = 12;
- //int BB_Up_Deviation = 2;
- //int BB_Dn_Period = 12;
- //int BB_Dn_Deviation = 2;
- double levelOb = 6;
- double levelOs = -6;
- double extremelevelOb = 10;
- double extremelevelOs = -10;
- extern bool alertsOn = true;
- bool alertsOnObOs = false;
- bool alertsOnExtremeObOs = true;
- bool alertsOnCurrent = false;
- bool alertsMessage = true;
- bool alertsSound = true;
- bool alertsEmail = false;
- bool alertsNotify = false;
- string soundfile = "alert2.wav";
- bool arrowsVisible = true;
- string arrowsIdentifier = "wpr arrows1";
- double arrowsUpperGap = 1.0;
- double arrowsLowerGap = 0.1;
- /*
- bool arrowsOnFiftyCross = false;
- color arrowsOnFiftyCrossUpColor= LimeGreen;
- color arrowsOnFiftyCrossDnColor= Red;
- int arrowsOnFiftyCrossUpCode = 241;
- int arrowsOnFiftyCrossDnCode = 242;
- int arrowsOnFiftyCrossSize = 2;
- */
- bool arrowsOnLeavingObOs = true;
- color arrowsLeavingObOsUpColor = DodgerBlue;
- color arrowsLeavingObOsDnColor = OrangeRed;
- int arrowsLeavingObOsUpCode = 241;
- int arrowsLeavingObOsDnCode = 242;
- int arrowsLeavingObOsSize = 1;
- double values[];
- double signal[];
- double band_up[];
- double band_dn[];
- double trend1[];
- double trend2[];
- double x1 = 76;
- double x2 = 24;
- int WprPrice = 1;
- int Risk = 0;
- double ArrowsGap = 1.0;
- double arrDn[];
- double arrUp[];
- double wpr[];
- double price[];
- double trend[];
- int init()
- {
- IndicatorBuffers(6);
- SetIndexBuffer(0, values);
- SetIndexStyle(0,DRAW_LINE);
- //SetIndexBuffer(1, signal);
- //SetIndexBuffer(2, band_up);
- //SetIndexBuffer(3, band_dn);
- //SetIndexBuffer(1, trend1);
- SetIndexBuffer(2, trend2);
- IndicatorShortName( "");
- SetIndexLabel(0,"");
- SetIndexLabel(1,"");
- SetIndexLabel(2,"");
- SetIndexLabel(3,"");
- SetIndexLabel(4,"");
- SetIndexLabel(5,"");
- SetIndexBuffer(4,price);
- SetIndexStyle(4,DRAW_NONE);
- return (0);
- }
- int deinit() {
- //deleteArrows();
- ObjectDelete("ss");
- ObjectDelete("bs");
- return (0);
- }
- int start()
- {
- datetime bar_time;
- int idx, counter, offset, bar_shft, bar_cont;
- double price_high, price_close, price_low, trigger_high, trigger_low;
- double sum_up, sum_dn, complex_up, complex_dn;
- int counted = IndicatorCounted();
- if (counted < 0) return (-1);
- if (counted > 0) counted--;
- int limit = Bars - counted;
- if (limit > Processed) limit = Processed;
- for (idx = limit; idx >= 0; idx--) {
- counter = 0;
- complex_up = 0; complex_dn = 0;
- trigger_high = -999999; trigger_low = 999999;
- while (counter < Control_Period) {
- sum_up = 0; sum_dn = 0;
- offset = idx + counter;
- bar_time = iTime(Symbol(), 0, offset);
- bar_shft = iBarShift(Symbol(), 0, bar_time, FALSE);
- bar_cont = bar_shft - Period(); if (bar_cont < 0) bar_cont = 0;
- x1 = x1 + Risk;
- x2 = x2 - Risk;
- for (int jdx = bar_shft; jdx >= bar_cont; jdx--) {
- int period = 3 + Risk * 2;
- double range = 0; for (int k = 0; k < 10; k++) range += High[jdx+k] - Low[jdx+k]; range /= 10.0;
- bool found1 = false; for (k = 0; k < 6 && !found1; k++) found1 = (MathAbs(Open[jdx+k] - Close[jdx+k+1])>= range * 2.0);
- bool found2 = false; for (k = 0; k < 9 && !found2; k++) found2 = (MathAbs(Close[jdx+k+3] - Close[jdx+k]) >= range * 4.6);
- if (found1) period = 3;
- if (found2) period = 4;
- price[jdx] = getPrice(WprPrice,jdx);
- double hi = High[Highest(NULL, 0, MODE_HIGH,period,jdx+1)];
- double lo = Low[Lowest(NULL, 0, MODE_LOW, period,jdx+1)];
- if (hi!=lo)
- wpr[jdx] = 100+(-100)*(hi - price[jdx]) / (hi - lo);
- else wpr[jdx] = 0;
- //double r1 = iRSI(NULL,0,RSI,PRICE_OPEN,jdx+1);
- //double r2 = iRSI(NULL,0,RSI,PRICE_OPEN,jdx);
- price_high = price[jdx];//iHigh(Symbol(), 0, jdx);
- price_close = Open[jdx];//iClose(Symbol(), 0, jdx);
- price_low = price[jdx];//iLow(Symbol(), 0, jdx);
- if (price_high > trigger_high) {trigger_high = price_high; sum_up += price_close;}
- if (price_low < trigger_low) {trigger_low = price_low; sum_dn += price_close;}
- }
- counter++;
- complex_up += sum_up; complex_dn += sum_dn;
- }
- if (complex_dn != 0.0 && complex_up != 0.0)
- values[idx] = complex_dn / complex_up - complex_up / complex_dn;
- }
- for (idx = limit; idx >= 0; idx--)
- {
- //signal[idx] = iMAOnArray(values, 0, Signal_Period, 0, Signal_Method, idx);
- //band_up[idx] = iBandsOnArray(values, 0, BB_Up_Period, BB_Up_Deviation, 0, MODE_UPPER, idx);
- //band_dn[idx] = iBandsOnArray(values, 0, BB_Dn_Period, BB_Dn_Deviation, 0, MODE_LOWER, idx);
- trend1[idx] = trend1[idx+1];
- trend2[idx] = trend2[idx+1];
- if (values[idx+1]<levelOb && values[idx]>levelOb) trend1[idx] =-1;
- if (values[idx+1]>levelOs && values[idx]<levelOs) trend1[idx] = 1;
- if (values[idx]>extremelevelOb) trend2[idx] =-1;
- if (values[idx]<extremelevelOs) trend2[idx] = 1;
- //manageArrow(idx);
- }
- //
- //
- //
- //
- //
- if (alertsOn)
- {
- if (alertsOnCurrent)
- int whichBar = 0;
- else whichBar = 1;
- //
- //
- //
- //
- //
- static datetime time1 = 0;
- static string mess1 = "";
- if (alertsOnObOs && trend1[whichBar] != trend1[whichBar+1])
- {
- if (trend1[whichBar] == 1 && trend1[idx] !=-1) doAlert(time1,mess1,whichBar,"crossing oversold");
- if (trend1[whichBar] == -1 && trend1[idx] != 1) doAlert(time1,mess1,whichBar,"crossing overbought");
- }
- static datetime time2 = 0;
- static string mess2 = "";
- if (alertsOnExtremeObOs && trend2[whichBar] != trend2[whichBar+1])
- {
- if (trend2[whichBar] == 1) doAlert(time2,mess2,whichBar,"crossing extreme oversold");
- if (trend2[whichBar] == -1) doAlert(time2,mess2,whichBar,"crossing extreme overbought");
- }
- }
- return (0);
- }
- /*
- void Tulis(string namateks, string teks, color warna, int pojok, int posx, int posy,int size)
- {
- ObjectCreate(namateks, OBJ_LABEL, 0, 0, 0);
- ObjectSetText(namateks, teks, size, teks, warna);
- ObjectSet(namateks, OBJPROP_CORNER, pojok);
- ObjectSet(namateks, OBJPROP_XDISTANCE, posx);
- ObjectSet(namateks, OBJPROP_YDISTANCE, posy);
- }
- */
- ////////////////////////////////////////////////////////////////
- double getPrice(int type, int i)
- {
- switch (type)
- {
- case 1: return((Open[i+1]));
- case 7: return((Open[i]+Close[i])/2.0);
- case 8: return((Open[i]+High[i]+Low[i]+Close[i])/4.0);
- default : return(iMA(NULL,0,1,0,MODE_SMA,type,i+1));
- }
- }
- //
- //
- //
- //
- /*
- void manageArrow(int idx)
- {
- if (arrowsVisible)
- {
- ObjectDelete(arrowsIdentifier+":1:"+Time[idx]);
- ObjectDelete(arrowsIdentifier+":2:"+Time[idx]);
- string lookFor = arrowsIdentifier+":"+Time[idx]; ObjectDelete(lookFor);
- if (arrowsOnLeavingObOs && trend1[idx] != trend1[idx+1])
- {
- if (trend1[idx+1] == -1 && trend1[idx] !=-1) drawArrow("2",0.5,idx,arrowsLeavingObOsUpColor,arrowsLeavingObOsUpCode,arrowsLeavingObOsSize,false);
- if (trend1[idx+1] == 1 && trend1[idx] != 1) drawArrow("2",0.5,idx,arrowsLeavingObOsDnColor,arrowsLeavingObOsDnCode,arrowsLeavingObOsSize, true);
- }
- }
- }
- */
- //
- //
- //
- //
- //
- /*
- void drawArrow(string nameAdd, double gapMul, int idx,color theColor,int theCode,int theWidth,bool up)
- {
- string name = arrowsIdentifier+":"+nameAdd+":"+Time[idx];
- double gap = iATR(NULL,0,20,idx)*gapMul;
- //
- //
- //
- //
- //
- ObjectCreate(name,OBJ_ARROW,0,Time[idx],0);
- ObjectSet(name,OBJPROP_ARROWCODE,theCode);
- ObjectSet(name,OBJPROP_COLOR,theColor);
- ObjectSet(name,OBJPROP_WIDTH,theWidth);
- if (up)
- ObjectSet(name,OBJPROP_PRICE1,High[idx] + arrowsUpperGap * gap);
- else ObjectSet(name,OBJPROP_PRICE1,Low[idx] - arrowsLowerGap * gap);
- }
- */
- //
- //
- //
- //
- //
- /*
- void deleteArrows()
- {
- string lookFor = arrowsIdentifier+":";
- int lookForLength = StringLen(lookFor);
- for (int idx=ObjectsTotal()-1; idx>=0; idx--)
- {
- string objectName = ObjectName(idx);
- if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
- }
- }
- */
- //
- //
- //
- void doAlert(datetime& previousTime, string& previousAlert, int forBar, string doWhat)
- {
- string message;
- if (previousAlert != doWhat || previousTime != Time[forBar]) {
- previousAlert = doWhat;
- previousTime = Time[forBar];
- //
- //
- //
- //
- //
- message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Vertex ",doWhat);
- if (alertsMessage) Alert(message);
- if (alertsNotify) SendNotification(message);
- if (alertsEmail) SendMail(StringConcatenate(Symbol()," Vertex "),message);
- if (alertsSound) PlaySound(soundfile);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement