//+------------------------------------------------------------------+ //| Heiken Ashi Expert Advisor.mq4 | //| Copyright © 2008, TradingSytemForex | //| http://www.tradingsystemforex.com | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, papaforex trading" #property link "http://www.tradingsystemforex.com" #define OrSt "PapaForex EA" extern string IS="---------------- Indicator Settings"; extern int MaMetod=2; extern int MaPeriod=6; extern int MaMetod2=3; extern int MaPeriod2=2; extern int MA.Period=35; extern int pq=2; extern int pr=10; extern int ps=5; extern int trigger=3; extern int fx_sid_limit = 1000; extern int fx_sid_barsize=2; extern int fx_sid_trh=10; extern int FasterMode = 3; //0=sma, 1=ema, 2=smma, 3=lwma extern int FasterMA = 2; extern int SlowerMode = 3; //0=sma, 1=ema, 2=smma, 3=lwma extern int SlowerMA = 5; extern string LM="---------------- Lot Management"; extern double Lots=0.1; extern bool MM=false; //money management extern double Risk=10; //risk in percentage extern string TSTB="---------------- TP SL TS BE"; bool RealSL_Enabled=false; int RealSL=5; //stop loss under 15 pÓps bool RealTP_Enabled=false; int RealTP=10; //take profit under 10 pÓps extern int SL=0; //stop loss extern int TP=500; //take profit extern int TS=0; //trailing stop extern int TS_Step=1; //trailing stop step extern int BE=0; //breakeven extern string EXT="---------------- Extras"; extern bool Reverse=false; extern bool Add_Positions=false; //positions cumulated extern int MaxOrders=1; //maximum number of orders extern int Magic=0; int Slip=3;static int TL=0;double MML=0; int SignalMA(double FastMA,double SlowMA) { static int theresult =0; if (FastMA>SlowMA) {theresult= 2;} //LONG_VALUE else if (FastMAICA1 && Open[i]>ICA2))BV=1; if (SV==1)theresult=1; else if(BV==1)theresult=2; else theresult=0; return(theresult); } int HA_Signal(double HA1,double HA2) { static int condition =0; if(HA2>HA1)condition =2; else if(HA1>HA2)condition =1; else condition = 0; return(condition); } int ExitSignal(double SlowMA1) { static int theresult=0; int curprice; if (Bid>SlowMA1) // if price is going up { curprice = (Bid-SlowMA1)/Point; if(curprice>=50) theresult=2; } else if(Bid=50) theresult=1; } else theresult=0; Print("Bid: "+Bid+" "+" SlowMA: "+SlowMA1+" "+theresult); return(theresult); } datetime OncePerBar=0; bool NewBar() { if(OncePerBar != Time[0]) {return (true); } else { return(false); } } int PriceAction() { static int theresult=0; int i=0,body1,body2; if((Open[i+1]=150) theresult=2; } else if((Open[i+1]>Close[i+1])&&(Open>Bid)) //lower lows { body2= (Open[i+1]-Close[i+1])/Point; body1 = (Open-Bid)/Point; if(body1+body2>=150) theresult=1; } else theresult=0; Print(body1+" "+body2); return(theresult); } // expert start function int start(){int j=0,limit=1;double BV=0,SV=0;BV=0;SV=0;double HA1,HA2,FXS1,FXS2,FXS3,FXS4,fxnow,fxprev,fxprev2,ICA1,ICA2,FastMA,SlowMA,SlowMA1; string fxsniper; if(CntO(OP_BUY,Magic)>0)TL=1;if(CntO(OP_SELL,Magic)>0)TL=-1;for(int i=1;i<=limit;i++){ HA1=iCustom(Symbol(),0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,2,i); HA2=iCustom(Symbol(),0,"Heiken_Ashi_Smoothed",MaMetod,MaPeriod,MaMetod2,MaPeriod2,3,i); // ICA1=iCustom(Symbol(),0,"i-CAi",MA.Period,0,i+1); // ICA2=iCustom(Symbol(),0,"i-CAi",MA.Period,0,i); FastMA=iCustom(Symbol(),0,"MACross",FasterMode,FasterMA,SlowerMode,SlowerMA,2,i); SlowMA=iCustom(Symbol(),0,"MACross",FasterMode,FasterMA,SlowerMode,SlowerMA,3,i+1); SlowMA1=iCustom(Symbol(),0,"MACross",FasterMode,FasterMA,SlowerMode,SlowerMA,3,0); fxsniper = "FX Sniper's Sidewinder Overlay"; fxnow=iCustom(Symbol(),0,fxsniper,fx_sid_limit,fx_sid_barsize,fx_sid_trh,0,0); fxprev=iCustom(Symbol(),0,fxsniper,fx_sid_limit,fx_sid_barsize,fx_sid_trh,0,1); fxprev2=iCustom(Symbol(),0,fxsniper,fx_sid_limit,fx_sid_barsize,fx_sid_trh,0,2); int sidsignal=SignalSid(fxnow,fxprev,fxprev2); int hasignal= HA_Signal(HA1,HA2); //int icaisignal=ICAI_Signal(ICA1,ICA2,i); int pricesignal= PriceAction(); int MASignal=SignalMA(FastMA,SlowMA); if((sidsignal==1)&&(hasignal==2)&&pricesignal==2){if(Reverse)SV=1;else BV=1;break;} if((sidsignal==1)&&(hasignal==1)&&pricesignal==1){if(Reverse)BV=1;else SV=1;break;}} int SignalExit=ExitSignal(SlowMA1); Print("Price: "+pricesignal+" HA: "+hasignal+" sid: "+sidsignal); // expert money management if(MM){if(Risk<0.1||Risk>100){Comment("Invalid Risk Value.");return(0);} else{MML=MathFloor((AccountFreeMargin()*AccountLeverage()*Risk*Point*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo(Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_MINLOT);}} if(MM==false){MML=Lots;} // expert init positions int cnt=0,OP=0,OS=0,OB=0,CS=0,CB=0;OP=0;for(cnt=0;cnt=1){OS=0; OB=0;}OB=0;OS=0;CB=0;CS=0; // expert conditions to open position // Here the variable opened_on_current_bar is set appropriately if(SV>0){OS=1;OB=0;}if(BV>0){OB=1;OS=0;} // expert conditions to close position if((SignalExit==1)||(RealSL_Enabled&&(OrderOpenPrice()-Bid)/Point>=RealSL)||(RealTP_Enabled&&(Ask-OrderOpenPrice())/Point>=RealTP)){CB=1;} if((SignalExit==2)||(RealSL_Enabled&&(Ask-OrderOpenPrice())/Point>=RealSL)||(RealTP_Enabled&&(OrderOpenPrice()-Bid)/Point>=RealTP)){CS=1;} for(cnt=0;cnt0){if((pb-OrderOpenPrice())>BE*pp){if((OrderStopLoss()-OrderOpenPrice())<0){ModSL(OrderOpenPrice()+0*pp);}}} // expert trailing stop if(TS>0){if((pb-OrderOpenPrice())>TS*pp){if(OrderStopLoss()0){if((OrderOpenPrice()-pa)>BE*pp){if((OrderOpenPrice()-OrderStopLoss())<0){ModSL(OrderOpenPrice()-0*pp);}}} if(TS>0){if(OrderOpenPrice()-pa>TS*pp){if(OrderStopLoss()>pa+(TS+TS_Step-1)*pp||OrderStopLoss()==0){ModSL(pa+TS*pp);return;}}}}} //expert stoploss void ModSL(double ldSL){bool fm;fm=OrderModify(OrderTicket(),OrderOpenPrice(),ldSL,OrderTakeProfit(),0,CLR_NONE);Alert("Sell: "+Bid);SendMail("Sell "+Symbol()+"Period: "+ Period()," Price: "+Bid);} //expert add positions function bool AddP(){int _num=0; int _ot=0; for (int j=0;j_ot) _ot=OrderOpenTime();}}if(_num==0) return(true);if(_num>0 && ((Time[0]-_ot))>0) return(true);else return(false);}