//+------------------------------------------------------------------+ //| StopHunting101.mq4 | //| Copyright © 2009, MetaQuotes Software Corp. | //| http://www.metaquotes.net | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, MetaQuotes Software Corp." #property link "http://www.metaquotes.net" #include #include #include //flags int EA_ID = 101; bool debug=false; int heartbeat = 0; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //does not work on any timeframe other than H1 if (Period() != PERIOD_H1) { if (debug==true) {Print("The chart is not on H1, exiting code.");} return; } // does not work on holidays. if(DayOfWeek()==0 || DayOfWeek()==6) return(0); //heartbeat code //if(Hour()>=0 && Minute()==0 && heartbeat == 0) {Print("Time is "+Hour()+" - StopHunting101EA still operating");heartbeat=1;} //if (Minute()>=1 && heartbeat ==1) {heartbeat=0;} //Buffers & lotsizes double BufferLong = 0.0003; //takes into account the spread double Lotsize = 1; double TradeTargetPrice = 15; double TradeStopLoss = 15; //5 decimal systems like Alpari if (Point==0.00001) { TradeTargetPrice=TradeTargetPrice*10; TradeStopLoss=TradeStopLoss*10; } //set the psych levels for stop hunting double stops_array[11] = {1.0, 1.1, 1.2, 1.25, 1.3, 1.4, 1.5, 1.6, 1.75, 1.8, 1.9, 2.0}; double ignoreLevel = 0.0; //200 IMA calculation double MA200 = iMA(NULL,PERIOD_H1,13,8,MODE_SMA,PRICE_MEDIAN,0); //Work out nearest price level double currPANearest = NormalizeDouble(Bid,1); Comment("currPANearest="+DoubleToStr(currPANearest,1)); int Arrayint = ArrayBsearch(stops_array,currPANearest,WHOLE_ARRAY,0,MODE_DESCEND); if (currPANearest != stops_array[Arrayint]) {return;} //if the price is not next to anything in the array then exit //if any orders exist from the EA, don't bother entering any more int total = OrdersTotal(); for(int i=total-1;i>=0;i--) { OrderSelect(i, SELECT_BY_POS); if ( OrderMagicNumber() == EA_ID ) return; } //if orders were recently entered for this level, don't enter again //BUY ON UPTREND //---------------- //if PA > 200MA (uptrend) and PA < psych (below resistance level), do some rounding //when PA reaches psych-0.015, BUY 2 lots //1 lot has TP of pysch level, SL is psych-0.015-0.015 //1 lot has TP of psych+0.015 //its SL is moved to BE on PA reaching psych if (debug==true) {Print("creating orders");} double LongSL1 = currPANearest-(TradeStopLoss*2*Point); //both SLs are the same as each other double LongSL2 = currPANearest-(TradeStopLoss*2*Point); double LongTP1 = currPANearest; //15pips double LongTP2 = currPANearest+(TradeTargetPrice*Point); //30pips if (Bid>MA200 && Bid==currPANearest-(TradeTargetPrice*Point) && currPANearest!=ignoreLevel) { //LONG1 RefreshRates(); int ticket=OrderSend(Symbol(),OP_BUY,Lotsize,Ask,NULL,LongSL1,LongTP1,"LONG1",101,0,Green); if(!ticket) { int errorCode = GetLastError(); if(errorCode != ERR_NO_RESULT ) logError("OrderSend", "Error", errorCode); } //LONG2 RefreshRates(); ticket=OrderSend(Symbol(),OP_BUY,Lotsize,Ask,NULL,LongSL1,LongTP2,"LONG1",101,0,Green); if(!ticket) { errorCode = GetLastError(); if(errorCode != ERR_NO_RESULT ) logError("OrderSend", "Error", errorCode); } ignoreLevel = currPANearest; } //SELL ON DOWNTREND //------------------- //if PA<200 (downtrend) and PA>psych (above support), do some rounding //when PA reaches psych+0.015, SELL 2 lots //1 lots has TP of psych level, SL is psych+0.015+0.015 double ShortSL1 = currPANearest+(TradeStopLoss*2*Point); //both SLs are the same as each other double ShortSL2 = currPANearest+(TradeStopLoss*2*Point); double ShortTP1 = currPANearest; //15pips double ShortTP2 = currPANearest-(TradeTargetPrice*Point); //30pips if (Bid