//+------------------------------------------------------------------+ //| sashken_indicator.mq4 | //| No Copyright, funtrader | //+------------------------------------------------------------------+ #property copyright "No Copyright, funtrader" #property link "http://championship.mql4.com" // // Indicatorsettings // #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Blue #property indicator_color2 Green #property indicator_color3 Red #property indicator_color4 Yellow // // Buffer // double bufferMA1[]; double bufferMA2[]; double bufferMA3[]; double bufferMA4[]; // // Parameter // // MA-Properties extern int shortMAPeriod = 7; extern int shortMAMethod = MODE_SMMA; extern int shortMAValue = PRICE_CLOSE; extern int longMAPeriod = 20; extern int longMAMethod = MODE_SMA; extern int longMAValue = PRICE_OPEN; extern int maShift1 = 1; extern int maShift2 = 2; extern int maOffset = 0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexStyle( 0, DRAW_LINE ); SetIndexBuffer( 0, bufferMA1 ); SetIndexStyle( 1, DRAW_LINE ); SetIndexBuffer( 1, bufferMA2 ); SetIndexStyle( 2, DRAW_LINE ); SetIndexBuffer( 2, bufferMA3 ); SetIndexStyle( 3, DRAW_LINE ); SetIndexBuffer( 3, bufferMA4 ); Print( "ServerTime: ", TimeToStr( CurTime(),TIME_DATE|TIME_SECONDS ), ", LocalTime: ", TimeToStr( LocalTime(),TIME_DATE|TIME_SECONDS ) ); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int countedBars = IndicatorCounted(); //---- check for possible errors if ( countedBars < 0 ) { return(-1); } //---- the last counted bar will be recounted if ( countedBars > 0 ) { countedBars--; } int barsToCount = Bars - countedBars; double MA1, MA2, MA3, MA4; for ( int i = barsToCount; i >= 0; i-- ) { MA1 = iMA( NULL, 0, shortMAPeriod, maOffset, shortMAMethod, shortMAValue, i + maShift1 ); MA2 = iMA( NULL, 0, shortMAPeriod, maOffset, shortMAMethod, shortMAValue, i + maShift2 ); MA3 = iMA( NULL, 0, longMAPeriod, maOffset, longMAMethod, longMAValue, i + maShift1 ); MA4 = iMA( NULL, 0, longMAPeriod, maOffset, longMAMethod, longMAValue, i + maShift2 ); bufferMA1[i] = MA1; bufferMA2[i] = MA2; bufferMA3[i] = MA3; bufferMA4[i] = MA4; if ( MA1 < MA3 && MA2 > MA4 ) { Print("Long. ", TimeToStr( Time[i], TIME_DATE|TIME_SECONDS ), " - ", Symbol(), ", Open: ", Open[i] ); } if ( MA1 > MA3 && MA2 < MA4) { Print("Short. ",TimeToStr( Time[i], TIME_DATE|TIME_SECONDS ), " - ", Symbol(), ", Open: ", Open[i] ); } } return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Series array that contains open prices of each bar
Series array that contains open time of each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: