//+------------------------------------------------------------------ //| Stopreversal Mt4.mq4 //| //| //| Conversion only Dr. Gaines //| dr_richard_gaines@yahoo.com //| //+------------------------------------------------------------------ #property copyright " Dominic." #property link " http://www.metaquotes.net/" #property indicator_chart_window #include <stdlib.mqh> #property indicator_buffers 3 #property indicator_color1 Lime #property indicator_width1 1 #property indicator_color2 Orange #property indicator_width2 1 #property indicator_color3 Magenta #property indicator_width3 0 //+------------------------------------------------------------------ //| Common External variables //+------------------------------------------------------------------ //+------------------------------------------------------------------ //| External variables //+------------------------------------------------------------------ extern double nPips = 0.0008; extern bool Alerts = true; extern bool Email = false; //+------------------------------------------------------------------ //| Special Convertion Functions //+------------------------------------------------------------------ int LastTradeTime; //static datetime dt = 0; double ExtHistoBuffer[]; double ExtHistoBuffer2[]; int up=0,dn=0; double LBuffer[]; double SBuffer[]; int above = 0; int below = 0; void SetLoopCount(int loops) { } void SetIndexValue(int shift, double value) { ExtHistoBuffer[shift] = value; // if ((Alerts == true) && (dt != iTime(NULL,0,0))) //&& (Close[0]==Close[shift])) // { // Alert(Symbol(), " M", Period(), " Stopreversal has crossed up"); // PlaySound("timeout.wav"); // if (Email == true) // { // SendMail(Symbol()+" "+OrderComment(),"Stopreversal crossed up"); // } // dt = iTime(NULL,0,0); // above=1; // below=0; // } } void SetIndexValue2(int shift, double value) { ExtHistoBuffer2[shift] = value; // if ((Alerts == true) && (dt != iTime(NULL,0,0))) //&& (Close[0]==Close[shift])) // { // Alert(Symbol(), " M", Period(), " Stopreversal has crossed down"); // PlaySound("timeout.wav"); // if (Email == true) // { // SendMail(Symbol()+" "+OrderComment(),"Stopreversal crossed down"); // } // dt = iTime(NULL,0,0); // above=0; // below=1; // } } //+------------------------------------------------------------------ //| End //+------------------------------------------------------------------ //+------------------------------------------------------------------ //| Initialization //+------------------------------------------------------------------ int init() { IndicatorBuffers(3); SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID); SetIndexArrow(0, 159); SetIndexBuffer(0, ExtHistoBuffer); SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID); SetIndexArrow(1, 159); // SetIndexBuffer(0, ExtHistoBuffer); SetIndexBuffer(0, ExtHistoBuffer); SetIndexBuffer(1, ExtHistoBuffer2); SetIndexBuffer(2, LBuffer); SetIndexStyle(2, DRAW_LINE, STYLE_DOT); return(0); } int start() { //+------------------------------------------------------------------ //| Local variables //+------------------------------------------------------------------ static datetime dt = 0; int shift = 0; double cnt = 0; double TrStopLevel = 0; double PREV = 0; double pass = 0; SetLoopCount(0); // loop from first bar to current bar (with shift=0) for(shift=Bars-2;shift>=0 ;shift--){ if( (Close[shift] == PREV) ) { TrStopLevel=PREV; } else { if( (Close[shift+1])<PREV && (Close[shift]<PREV) ) { TrStopLevel=MathMin(PREV,Close[shift]*(1+nPips)); } else { if( ((Close[shift+1])>PREV) && (Close[shift]>PREV) ) { TrStopLevel=MathMax(PREV,Close[shift]*(1-nPips)); } else { if( (Close[shift]>PREV) ) { TrStopLevel=Close[shift]*(1-nPips); } else TrStopLevel=Close[shift]*(1+nPips); } } } LBuffer[shift]=TrStopLevel; if( Close[shift] > TrStopLevel && Close[shift+1]<PREV && PREV != 0 ) { //SetOrder(OP_BUY,1,ask,2,0,ask+TakeProfit*Point,blue); //Alert("buy"); SetIndexValue(shift, TrStopLevel); //SetOrder(OP_BUY,1,ask,2,0,ask+TakeProfit*Point,blue); if ((Alerts == true) && (dt != iTime(NULL,0,0))&& (ExtHistoBuffer[0]== TrStopLevel))//&& (Close[0]==Close[shift])) { Alert(Symbol(), " M", Period(), " Stopreversal has crossed up"); PlaySound("timeout.wav"); if (Email == true) { SendMail(Symbol()+" "+OrderComment(),"Stopreversal crossed up"); } dt = iTime(NULL,0,0); above=1; below=0; } } if( Close[shift] < TrStopLevel && Close[shift+1]>PREV && PREV != 0 ) { //SetOrder(OP_SELL,1,bid,2,0,bid-TakeProfit*Point,Red); SetIndexValue2(shift, TrStopLevel); if ((Alerts == true) && (dt != iTime(NULL,0,0))&& (ExtHistoBuffer2[0]== TrStopLevel))//&& (Close[0]==Close[shift])) { Alert(Symbol(), " M", Period(), " Stopreversal has crossed down"); PlaySound("timeout.wav"); if (Email == true) { SendMail(Symbol()+" "+OrderComment(),"Stopreversal crossed down"); } dt = iTime(NULL,0,0); above=0; below=1; } //Alert("Sell"); } PREV=TrStopLevel; //Alert(TrStopLevel); } return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Indicator Curves created:
Implements a curve of type DRAW_ARROW
Implements a curve of type DRAW_LINE
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features:
It issuies visual alerts to the screen
It plays sound alerts
It sends emails