/* */ #property version "1.00" #property strict // Input parameters input double stopspriceXAU = 12; input int EngPercent = 6; input int limitnumber = 40; input int stopnumber = 3; extern double MaxRiskPerTrade = 1; // % of balance to risk in one trade. // Global variables bool bullisheng; bool bearisheng; bool last5barsbear; bool last5barsbull; double numofPipsforLongs; double numofPipsforShorts; double BullaboveSixty; double BearbelowSixty; double LimitForLongs; double LimitForShorts; double StopForLongs; double StopForShorts; double testforsizeofstoplongs; double testforsizeofstopshorts; double initialCapital = AccountEquity(); //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { double BarValueBulls = High[0] - Open[0]; // Get size of bar for longs double BarValueBears = Open[0] - Low[0]; // Get size of bar for shorts double SixtyPercentBulls = (BarValueBulls / 10) * EngPercent; // check if valid bar over 60% of full bar range double SixtyPercentBears = (BarValueBears / 10) * EngPercent; // check if valid bar over 60% of full bar range double BullaboveSixty = Open[0] + SixtyPercentBulls; double BearbelowSixty = Open[0] - SixtyPercentBears; int lowestbar = iLowest(_Symbol, _Period, MODE_LOW, stopnumber, 1); int highestbar = iHighest(_Symbol, _Period, MODE_HIGH, stopnumber, 1); int highbar1 = iHighest(_Symbol, _Period, MODE_HIGH, limitnumber,1); int lowbar1 = iLowest(_Symbol, _Period, MODE_LOW, limitnumber, 1); // Limit values double LimitForLongs=(High[highbar1] + stopspriceXAU); double LimitForShorts=(Low[lowbar1] - (stopspriceXAU)); // Stop values double StopForLongs=(Low[lowestbar]); double StopForShorts=(High[highestbar]); double testforsizeofstopshorts = StopForShorts - Close[0]; double testforsizeofstoplongs = Close[0] - StopForLongs; double last5barsbear = Close[1] < Open[1] && Close[2] < Open[2] && Close[3] < Open[3] && Close[4] < Open[4] && Close[5] < Open[5]; double last5barsbull = Close[1] > Open[1] && Close[2] > Open[2] && Close[3] > Open[3] && Close[4] > Open[4] && Close[5] > Open[5]; // Engulfing conditions bullisheng = Close[0] >= BullaboveSixty && Open[1] >= Close[1] && Close[0] > Open[0] && Close[0] >= Open[1] && Close[0] - Open[0] > Open[1] - Close[1]; bearisheng = Close[0] <= BearbelowSixty && Close[1] >= Open[1] && Open[0] > Close[0] && Open[1] >= Close[0] && Open[0] - Close[0] > Close[1] - Open[1]; if (testforsizeofstopshorts < 0.7 || testforsizeofstopshorts > 1){ StopForShorts = Close[0] + 0.6 + stopspriceXAU; numofPipsforShorts = StopForShorts - Close[0]; } if (testforsizeofstoplongs < 0.7 || testforsizeofstoplongs > 1) { StopForLongs = Close[0] - 0.6 - stopspriceXAU; numofPipsforLongs = Close[0] - StopForLongs; } if (bullisheng && last5barsbear){ //double test = Close[0] - StopForLongs; double positionValue1 = (initialCapital * (MaxRiskPerTrade/100) / numofPipsforLongs); OrderSend(Symbol(),OP_BUY, 0.02,Ask,3,StopForLongs,LimitForLongs,"",0,0,Red); } if (bearisheng && last5barsbull){ OrderSend(Symbol(),OP_SELL,0.02,Bid,3,StopForShorts,LimitForShorts,"",0,0,Blue); } return; } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { } //+------------------------------------------------------------------+ // We print the position size in lots. // Print("Position size in lots Longs - ", CalculateLotSizeLongs(numofPipsforLongs)); //Print("Position size in lots shorts - ", CalculateLotSizeLongs(numofPipsforShorts)); // Print("num of pips longs - ", numofPipsforLongs); // Print("num of pips shorts - ", numofPipsforShorts); //Print("highbar1 = ", High[highbar1]); // Print("limit for longs = ", LimitForLongs); // // Print("highestbar = ", High[highestbar]); // Print("stop for shorts = ", StopForShorts);