Alert modification.

Back to topics list To post a new topic, please log in or register
avatar
2
Dejwidziu 2015.07.30 13:29
 

Hi. Please help me with change a bit a code of indicator. 


 Here I try to put a commend. So when DTOSC crossing and change for SELL/Buy

 I would like to show a text on terminal Sell/Buy. I need only this monit as a text. I'm not intersting especcialy about how Dtosc looks. Only when is sell then show me text sell;

Regards my best David 

avatar
2
Dejwidziu 2015.07.30 13:31 #
 
#property indicator_separate_window

#property indicator_buffers 2

#property indicator_minimum 0

#property indicator_maximum 100

#property indicator_color1 Red

#property indicator_color2 Blue

#property indicator_width1 2

#property indicator_width2 2

#property indicator_level1 20

#property indicator_level2 80




extern string TimeFrame = "Current time frame";

extern int PeriodRSI =13;

extern int PeriodStoch= 8;

extern int PeriodSK = 5;

extern int PeriodSD = 3;

// 0 = SMA

// 1 - EMA

// 2 - SMMA

// 3 - LWMA

extern int MAMode=0;

extern bool alertsOn = true;

extern bool alertsOnCurrent = true;

extern bool alertsMessage = true;

extern bool alertsSound = true;

extern bool alertsEmail = false;

extern string soundfile = "alert2.wav";




double SK[];

double SD[];

double StoRSI[];

double RSI[];

double cross[];

string IndicatorFileName;

int timeFrame;

bool returnBars=false;



//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+




int init()

{

IndicatorBuffers(5);

SetIndexBuffer(0,SK);

SetIndexBuffer(1,SD);

SetIndexBuffer(2,StoRSI);

SetIndexBuffer(3,RSI);

SetIndexBuffer(4,cross);





if (TimeFrame == "getBarsCount")

{

returnBars=true;

return(0);

}

timeFrame = stringToTimeFrame(TimeFrame);







IndicatorShortName("DTOSC ("+PeriodRSI+","+PeriodStoch+","+PeriodSK+","+PeriodSD+")");

IndicatorFileName = WindowExpertName();

return(0);

}

int deinit() { return(0); }



//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+





int start()

{

int i,limit;

int counted_bars = IndicatorCounted();



if(counted_bars < 0) return(-1);

if(counted_bars > 0) counted_bars--;

limit=Bars-counted_bars;






if (returnBars) { SK[0] = limit; return(0); }

if (timeFrame != Period())

{

limit = MathMax(limit,MathMin(Bars,iCustom(NULL,timeFrame,IndicatorFileName,"getBarsCount",0,0)*timeFrame/Period()));







for(i=0; i<limit; i++)

{

int y = iBarShift(NULL,timeFrame,Time[i]);

SK[i] = iCustom(NULL,timeFrame,IndicatorFileName,"",PeriodRSI,PeriodStoch,PeriodSK,PeriodSD,MAMode,0,y);

SD[i] = iCustom(NULL,timeFrame,IndicatorFileName,"",PeriodRSI,PeriodStoch,PeriodSK,PeriodSD,MAMode,1,y);

}

return(0);

}





for(i=limit; i>=0; i--)

{

RSI[i] = iRSI(NULL,0,PeriodRSI,PRICE_CLOSE,i);

double LLV = RSI[ArrayMinimum(RSI,PeriodStoch,i)];

double HHV = RSI[ArrayMaximum(RSI,PeriodStoch,i)];

if ((HHV-LLV)!=0)

StoRSI[i] = 100.0*((RSI[i] - LLV)/(HHV - LLV));

else StoRSI[i] = 0;

}

for(i=limit; i>=0; i--) SK[i]=iMAOnArray(StoRSI,0,PeriodSK,0,MAMode,i);

for(i=limit; i>=0; i--)

{

SD[i]=iMAOnArray( SK,0,PeriodSD,0,MAMode,i);

cross[i] = cross[i+1];

if (SK[i]>SD[i]) cross[i] = 1;

if (SK[i]<SD[i]) cross[i] = -1;

}

if (alertsOn)

{

if (alertsOnCurrent)

int whichBar = 0;

else whichBar = 1;

if (cross[whichBar] != cross[whichBar+1])

if (cross[whichBar] == 1)

doAlert("BUY");
ObjectCreate("ObjName", OBJ_LABEL, 0, 0, 0);

ObjectSetText("ObjName","BUY",53, "Verdana", Green);

ObjectSet("ObjName", OBJPROP_CORNER, 0);

ObjectSet("ObjName", OBJPROP_XDISTANCE, 10);

ObjectSet("ObjName", OBJPROP_YDISTANCE, 33);



// Here I try to put a commend. So when DTOSC crossing and change for SELL/Buy

// I would like to show a text on terminal Sell/Buy.

// I need only this monit as a text. I'm not intersting especcialy about how Dtosc looks. Only when is sell then show me text sell;







doAlert("SELL");

} ObjectCreate("ObjName", OBJ_LABEL, 0, 0, 0);

ObjectSetText("ObjName","Sell",53, "Verdana", Red);

ObjectSet("ObjName", OBJPROP_CORNER, 0);

ObjectSet("ObjName", OBJPROP_XDISTANCE, 10);

ObjectSet("ObjName", OBJPROP_YDISTANCE, 33);





return(0);

}
//------------------------------------------------------------------

//

//------------------------------------------------------------------

void doAlert(string doWhat)

{

static string previousAlert="nothing";

static datetime previousTime;

string message;



if (previousAlert != doWhat || previousTime != Time[0]) {

previousAlert = doWhat;

previousTime = Time[0];







message = StringConcatenate(Symbol()," at ",TimeToStr(TimeLocal(),TIME_SECONDS)," Kierunek ",doWhat);

if (alertsMessage) Alert(message);

if (alertsEmail) SendMail(StringConcatenate(Symbol()," Dtosc "),message);

if (alertsSound) PlaySound(soundfile);

}

}



//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+





int stringToTimeFrame(string tfs)

{

for(int l = StringLen(tfs)-1; l >= 0; l--)

{

int tchar = StringGetChar(tfs,l);

if((tchar > 96 && tchar < 123) || (tchar > 223 && tchar < 256))

tfs = StringSetChar(tfs, l, tchar - 32);

else

if(tchar > -33 && tchar < 0)

tfs = StringSetChar(tfs, l, tchar + 224);

}


int tf=0;

if (tfs=="M1" || tfs=="1") tf=PERIOD_M1;

if (tfs=="M5" || tfs=="5") tf=PERIOD_M5;

if (tfs=="M15"|| tfs=="15") tf=PERIOD_M15;

if (tfs=="M30"|| tfs=="30") tf=PERIOD_M30;

if (tfs=="H1" || tfs=="60") tf=PERIOD_H1;

if (tfs=="H4" || tfs=="240") tf=PERIOD_H4;

if (tfs=="D1" || tfs=="1440") tf=PERIOD_D1;

if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1;

if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1;

if (tf<Period()) tf=Period();

return(tf);
avatar
12995
WHRoeder 2015.07.30 14:23 #
 
Dejwidziu:

if (cross[whichBar] != cross[whichBar+1])

if (cross[whichBar] == 1)

doAlert("BUY");
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. You have no braces "{}" around your cross code
  3. or around your buy alert code.
  4. or an else{ sell alert code}
  5. Nor do you delete your buy object when you sell alert and visa versa.
Back to topics list  

To add comments, please log in or register