Turbo_PT_Scalper

Author: Copyright � 2008, Tim Hyder
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It plays sound alertsIt sends emails
0 Views
0 Downloads
0 Favorites
Turbo_PT_Scalper
//+------------------------------------------------------------------+ 
//|               PowerTrend 5 Minute Scalper                        | 
//|                                                                  | 
//|   Copyright © 2008, Tim Hyder aka Hiachiever                     |
//|                                                                  |
//+------------------------------------------------------------------+ 
#property copyright "Copyright © 2008, Tim Hyder"
#property link      "http://www.the4xtrader.com"

#define vers    "20.Feb.2008"
#define major   1
#define minor   0

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 Magenta
#property indicator_color3 DodgerBlue
#property indicator_color4 Magenta
#property indicator_width1 2
#property indicator_width2 2


extern string NOTESETTINGS = " - - - INDICATOR SETTINGS - - - ";
extern int MA1.Period = 5;
extern int MA2.Period = 5;

extern string NOTE1 = " 0 = SMA, 1 = EMA, 2 = SSMA, 3 = LWMA";
extern int MA1.Method = MODE_EMA;
extern int MA2.Method = MODE_EMA;

extern string NOTE2 = "0 = Close, 1 = Open, 2 = High, 3 = Low";
extern int MA1.Price = PRICE_HIGH;
extern int MA2.Price = PRICE_LOW;

extern int MA1.Shift=0;
extern int MA2.Shift=0;

extern int RSI.Period = 9;
extern int RSI.Upper = 70;
extern int RSI.Lower = 30;
extern string NOTEALERTS = " - - - -  ALERTS  - - - - ";
extern bool MsgAlerts = true;
extern bool SoundAlerts = true;
extern string SoundAlertFile = "alert.wav";
extern bool eMailAlerts = false;

double Buf1[], Buf2[], ShortSig[], LongSig[];
double LO_TF_EMA_1 = 0, LO_TF_EMA_2 = 0, MID_TF_EMA_1 = 0, MID_TF_EMA_2 = 0, HI_TF_EMA_1 = 0, HI_TF_EMA_2 = 0, MAX_TF_EMA_1 = 0, MAX_TF_EMA_2 = 0;
string prefix = "PTScalper";
datetime LastAlert;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   //---- indicators
   IndicatorBuffers(4);

   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buf1);
   SetIndexDrawBegin(0,MA1.Period+MA1.Shift);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Buf2);
   SetIndexDrawBegin(1,MA1.Period+MA1.Shift);

 	SetIndexBuffer(2,LongSig);
	SetIndexStyle(2,DRAW_ARROW,EMPTY,1);
	SetIndexArrow(2,233);
	
	SetIndexBuffer(3,ShortSig);
	SetIndexStyle(3,DRAW_ARROW,EMPTY,1);
	SetIndexArrow(3,234);

   //---- name for DataWindow and indicator subwindow label   
   IndicatorShortName(prefix);
   LastAlert = Time[0];

   //----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   double MAHg, MALw, RSI_Current = 0, RSI_Prior = 0; 
   string Subj, Msg;
   string MainTxt = Symbol()+ ", TF: " + TF2Str(Period());
  
   int counted_bars=IndicatorCounted();
   //---- check for possible errors
   if(counted_bars<0) return(-1);
   //---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;

   int limit=Bars-counted_bars;
   for(int i=0;i<limit;i++)
   {
      MAHg = iMA(NULL, 0, MA1.Period, MA1.Shift, MA1.Method, MA1.Price, i+1);
      MALw = iMA(NULL, 0, MA2.Period, MA2.Shift, MA2.Method, MA2.Price, i+1);
      
      LO_TF_EMA_1 = iCustom(Symbol(), Period(), "4MA_Price_Action_MTF", 0, 1000, 21, 0, " ", MODE_EMA, " ", PRICE_MEDIAN, 3, i);
      LO_TF_EMA_2 = iCustom(Symbol(), Period(), "4MA_Price_Action_MTF", 0, 1000, 21, 0, " ", MODE_EMA, " ", PRICE_MEDIAN, 3, i+1);
      MID_TF_EMA_1 = iCustom(Symbol(), Period(), "4MA_Price_Action_MTF", 0, 1000, 21, 0, " ", MODE_EMA, " ", PRICE_MEDIAN, 2, i);
      MID_TF_EMA_2 = iCustom(Symbol(), Period(), "4MA_Price_Action_MTF", 0, 1000, 21, 0, " ", MODE_EMA, " ", PRICE_MEDIAN, 2, i+1);
      HI_TF_EMA_1 = iCustom(Symbol(), Period(), "4MA_Price_Action_MTF", 0, 1000, 21, 0, " ", MODE_EMA, " ", PRICE_MEDIAN, 1, i);
      HI_TF_EMA_2 = iCustom(Symbol(), Period(), "4MA_Price_Action_MTF", 0, 1000, 21, 0, " ", MODE_EMA, " ", PRICE_MEDIAN, 1, i+1);
      MAX_TF_EMA_1 = iCustom(Symbol(), Period(), "4MA_Price_Action_MTF", 0, 1000, 21, 0, " ", MODE_EMA, " ", PRICE_MEDIAN, 0, i);
      MAX_TF_EMA_2 = iCustom(Symbol(), Period(), "4MA_Price_Action_MTF", 0, 1000, 21, 0, " ", MODE_EMA, " ", PRICE_MEDIAN, 0, i+1);
      
      RSI.Upper = 70;
      RSI.Lower = 30;
      
     if (LO_TF_EMA_1 >= LO_TF_EMA_2 && LO_TF_EMA_1 >= MID_TF_EMA_1 && MID_TF_EMA_1 >= MID_TF_EMA_2 && MID_TF_EMA_1 >= HI_TF_EMA_1 && HI_TF_EMA_1 >= HI_TF_EMA_2 && HI_TF_EMA_1 >= MAX_TF_EMA_1 && MAX_TF_EMA_1 >= MAX_TF_EMA_2) {RSI.Upper = 80;RSI.Lower = 40;} 
     if (LO_TF_EMA_1 <= LO_TF_EMA_2 && LO_TF_EMA_1 <= MID_TF_EMA_1 && MID_TF_EMA_1 <= MID_TF_EMA_2 && MID_TF_EMA_1 <= HI_TF_EMA_1 && HI_TF_EMA_1 <= HI_TF_EMA_2 && HI_TF_EMA_1 <= MAX_TF_EMA_1 && MAX_TF_EMA_1 <= MAX_TF_EMA_2) {RSI.Upper = 60;RSI.Lower = 20;} 
          
      Buf1[i] = MAHg;
      Buf2[i] = MALw;

      RSI_Prior = iCustom(Symbol(), Period(), "Turbo_JRSX_Close", RSI.Period, 0, i+1);
      RSI_Current = iCustom(Symbol(), Period(), "Turbo_JRSX_Close", RSI.Period, 0, i);
      
      if (Close[i] > MAHg && RSI_Current >RSI.Upper && RSI_Current < RSI_Prior)
      {
         ShortSig[i] = High[i]+SignalArrowSpacer(); 
         if (LastAlert != Time[0])
         {
           Subj = MainTxt + ".  Short Entry Alert";
           Msg = Subj + " @ " + TimeToStr(TimeLocal(),TIME_SECONDS);
           DoAlerts(Msg,Subj);
           LastAlert = Time[0]; 
         }
      }   
      else if (Close[i] < MALw && RSI_Current < RSI.Lower && RSI_Current > RSI_Prior)
      {
         LongSig[i] = Low[i]-SignalArrowSpacer();
         if (LastAlert != Time[0])
         {
           Subj = MainTxt + ".  Long Entry Alert";
           Msg = Subj + " @ " + TimeToStr(TimeLocal(),TIME_SECONDS);
           DoAlerts(Msg,Subj);
           LastAlert = Time[0]; 
         }
      }
      
   }
   return(0);
  }
//+------------------------------------------------------------------+

void DoAlerts(string msgText,string eMailSub)
{
  {
   if (MsgAlerts) Alert(msgText);
   if (SoundAlerts) PlaySound(SoundAlertFile);
   if (eMailAlerts) SendMail(eMailSub, msgText);
  }
}


double SignalArrowSpacer()
//Allow the correct positioning of Signal Arrows for each TF.
{
   switch(Period())
   {
      case PERIOD_M1: return(5*Point); break;
      case PERIOD_M5: return(5*Point); break;
      case PERIOD_M15: return(10*Point); break;
      case PERIOD_M30: return(15*Point); break;
      case PERIOD_H1: return(20*Point); break;
      case PERIOD_H4: return(30*Point); break;
      case PERIOD_D1: return(60*Point); break;
      case PERIOD_W1: return(100*Point); break;
      case PERIOD_MN1: return(150*Point); break;
   }
}

string TF2Str(int period) 
{
  switch (period) 
  {
    case PERIOD_M1: return("M1");
    case PERIOD_M5: return("M5");
    case PERIOD_M15: return("M15");
    case PERIOD_M30: return("M30");
    case PERIOD_H1: return("H1");
    case PERIOD_H4: return("H4");
    case PERIOD_D1: return("D1");
    case PERIOD_W1: return("W1");
    case PERIOD_MN1: return("MN");
  }
  return (Period());
} 

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---