//+---------------------------------------------------------------------------+ //| ChaosTrader.mq4 | //| Jay Davis | //| https://www.tidyneat.com | //+---------------------------------------------------------------------------+ #property copyright "Jay Davis" #property link "https://www.tidyneat.com" #property version "1.00" #property strict // Awesome Indicator #define PERIOD_FAST 5 #define PERIOD_SLOW 34 input int magnitude=10; // Pips of distance from mouth needed input bool UseFirstWiseMan=true; input bool UseSecondWiseMan= true; input bool UseThirdWiseMan = true; input double lotSize=0.01; // What size for your orders input int magic=1010101; // magic number string volumeString=""; double stoploss=0; int InpJawsPeriod=13; // Jaws Period int InpJawsShift=8; // Jaws Shift int InpTeethPeriod=8; // Teeth Period int InpTeethShift=5; // Teeth Shift int InpLipsPeriod=5; // Lips Period int InpLipsShift=3; // Lips Shift datetime expiry = TimeCurrent(); //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { static datetime candletime=0; if(candletime!=Time[0]) { expiry=TimeCurrent()+PeriodSeconds(PERIOD_CURRENT); if(UseFirstWiseMan) FirstWiseMan(); if(UseSecondWiseMan)SecondWiseMan(); if(UseThirdWiseMan)ThirdWiseMan(); candletime=Time[0]; } } //+------------------------------------------------------------------+ //| Check if another order can be placed | //+------------------------------------------------------------------+ bool IsNewOrderAllowed() { //--- get the number of pending orders allowed on the account int max_allowed_orders=(int)AccountInfoInteger(ACCOUNT_LIMIT_ORDERS); //--- if there is no limitation, return true; you can send an order if(max_allowed_orders==0) return(true); //--- if we passed to this line, then there is a limitation; find out how many orders are already placed int orders=OrdersTotal(); //--- return the result of comparing return(orders Boolean | //+------------------------------------------------------------------+ bool BullishDivergent(int bar) { double low=iLow(NULL,PERIOD_CURRENT,bar), median=(iHigh(NULL,PERIOD_CURRENT,bar)+low)/2; if(lowmedian) { return true; } return false; } //+------------------------------------------------------------------+ //| A bearish divergent bar is a bar that has a higher high and | //| closes in the bottom half of the bar. | //| Integer --> Boolean | //+------------------------------------------------------------------+ bool BearishDivergent(int bar) { double high=iHigh(NULL,PERIOD_CURRENT,bar), median=(iLow(NULL,PERIOD_CURRENT,bar)+high)/2; if(high>iHigh(NULL,PERIOD_CURRENT,bar+1) && iClose(NULL,PERIOD_CURRENT,bar) Double | //+------------------------------------------------------------------+ double Magnitude(int bar) { double mag=0, magLips=iMA(NULL,0,InpLipsPeriod,InpLipsShift,MODE_SMMA,PRICE_MEDIAN,bar), high= iHigh(NULL,PERIOD_CURRENT,bar), low = iLow(NULL,PERIOD_CURRENT,bar); if(BullishDivergent(bar)==true) { mag=magLips-high; } if(BearishDivergent(bar)==true) { mag=low-magLips; } return mag; } //+------------------------------------------------------------------+ /* On a bullish divergent bar, we place the buy stop just above the top of the bullish divergent bar (see B, Figure 9.1) and on the bearish divergent bar we place our sell stop just below the bottom of the bearish divergent bar Gregory-Williams, Justine. Trading Chaos: Maximize Profits with Proven Technical Techniques (A Marketplace Book) (Kindle Locations 2852-2854). Wiley. Kindle Edition. */ //+------------------------------------------------------------------+ //| Set stoplosses | //| Integer | //+------------------------------------------------------------------+ void SetStoplosses(int type,double stopLoss) { //Print(__FUNCTION__); double stopLevel=MarketInfo(NULL,MODE_STOPLEVEL)*Point; int total = OrdersTotal(); for(int i = total; i >= 0; i--) { // Select order to work with if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { // Check if order magic number matches if(OrderMagicNumber()==magic) { if(OrderType()==type && type==OP_BUY) { if(OrderStopLoss()stopLoss && stopLoss>Ask+stopLevel) { // Set new stoploss if(OrderModify(OrderTicket(),OrderOpenPrice(),stopLoss,0,0,clrAliceBlue)) { Print("Stoploss moved on #",OrderTicket()," to ",stopLoss); } } } } } } } //+------------------------------------------------------------------+ //| Check the correctness of the order volume | //+------------------------------------------------------------------+ bool CheckVolumeValue(double volume,string &description) { //--- minimal allowed volume for trade operations double min_volume=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_MIN); if(volumemax_volume) { description=StringFormat("Volume is greater than the maximal allowed SYMBOL_VOLUME_MAX=%.2f",max_volume); return(false); } //--- get minimal step of volume changing double volume_step=SymbolInfoDouble(Symbol(),SYMBOL_VOLUME_STEP); int ratio=(int)MathRound(volume/volume_step); if(MathAbs(ratio*volume_step-volume)>0.0000001) { description=StringFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f", volume_step,ratio*volume_step); return(false); } description="Correct volume value"; return(true); } //+------------------------------------------------------------------+