Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //+------------------------------------------------------------------+
- //| Copyright 2010 |
- //| steadywinner.mipropia.com |
- //| steadywinner@gmail.com |
- //| SteadyWinner Version 4.2 |
- //| Pair:EURUSD Any timeframe |
- //+------------------------------------------------------------------+
- #property copyright "SteadyWinner"
- #property link "steadywinner@gmail.com"
- #define MIN_STOPLOSS_POINT 5
- #define MIN_TAKEPROFIT_POINT 5
- string sNameExpert = "SteadyWinner V4.2";
- int nAccount =0;
- // 2010/9/18 Change (4) - Set sane value for StopLoss, TakeProfit and TrailingStop
- // in both Buy / Sell orders
- double dOneStopLossPoint = 50;
- double dOneTakeProfitPoint = 12;
- double dOneTrailingStopPoint = 10;
- double dBuyStopLossPoint;
- double dSellStopLossPoint;
- double dBuyTakeProfitPoint;
- double dSellTakeProfitPoint;
- double dBuyTrailingStopPoint;
- double dSellTrailingStopPoint;
- extern int MagicNumber = 338833;
- extern int nPctToRisk = 2;
- double dLots=0.01;
- double MinLots = 0;
- double MaxLots = 0;
- double point = 0;
- int nSlippage = 3;
- bool lFlagUseHourTrade = True;
- int nFromHourTrade = 0;
- int nToHourTrade = 23;
- bool lFlagUseSound = True;
- string sSoundFileName = "alert.wav";
- color colorOpenBuy = Blue;
- color colorCloseBuy = Aqua;
- color colorOpenSell = Red;
- color colorCloseSell = Aqua;
- string Please_Enter_Password = "0";
- string password;
- //--------------------------------------------------------------------------------
- void init() {
- // for 4 or 5 digit brokers
- if (Digits == 3 || Digits == 5) {
- point = Point*10;
- }
- else {
- point = Point;
- }
- // 2010/9/18 Change (4) - Use single variable for StopLoss / TakeProfit / TrailingStop
- // But keep original variable intact so can be fine tuned for buy / sell separately later
- dBuyStopLossPoint = dOneStopLossPoint;
- dSellStopLossPoint = dOneStopLossPoint;
- dBuyTakeProfitPoint = dOneTakeProfitPoint;
- dSellTakeProfitPoint = dOneTakeProfitPoint;
- dBuyTrailingStopPoint = dOneTrailingStopPoint;
- dSellTrailingStopPoint = dOneTrailingStopPoint;
- ObjectCreate("ObjName1", OBJ_LABEL, 0, 0, 0);
- ObjectSetText("ObjName1", "http://steadywinner.mipropia.com steadywinner@gmail.com", 9, "Verdana", White);
- ObjectSet("ObjName1", OBJPROP_CORNER, 0);
- ObjectSet("ObjName1", OBJPROP_XDISTANCE, 20);
- ObjectSet("ObjName1", OBJPROP_YDISTANCE, 20);
- ObjectCreate("ObjName2", OBJ_LABEL, 0, 0, 0);
- ObjectSetText("ObjName2", "SteadyWinner (V4), risking "+nPctToRisk+"% of your account", 9, "Verdana", White);
- ObjectSet("ObjName2", OBJPROP_CORNER, 0);
- ObjectSet("ObjName2", OBJPROP_XDISTANCE, 20);
- ObjectSet("ObjName2", OBJPROP_YDISTANCE, 40);
- ObjectCreate("ObjName3", OBJ_LABEL, 0, 0, 0);
- // 2010/9/18 Change (2) - Unified and Simplified Lot Size Display
- MinLots = MarketInfo(Symbol(),MODE_MINLOT);
- dLots = (MathCeil(AccountEquity ()/((dOneStopLossPoint*10)/nPctToRisk)))/100;
- dLots = NormalizeDouble(dLots/MinLots,0) * MinLots;
- ObjectSetText("ObjName3", "You are trading " + DoubleToStr(dLots,2) + " Lots. Account Minimum Lot Size=" + DoubleToStr(MinLots,2), 9, "Verdana", White);
- ObjectSet("ObjName3", OBJPROP_CORNER, 0);
- ObjectSet("ObjName3", OBJPROP_XDISTANCE, 20);
- ObjectSet("ObjName3", OBJPROP_YDISTANCE, 60);
- ObjectCreate("ObjName4", OBJ_LABEL, 0, 0, 0);
- // 2010/9/18 Change (5) - Screen display now show values from variables instead of hard coded values
- ObjectSetText("ObjName4", "Stoploss=" + DoubleToStr(dOneStopLossPoint,0)
- + " Take profit=" + DoubleToStr(dOneTakeProfitPoint,0)
- + " Trailing stop=" + DoubleToStr(dOneTrailingStopPoint,0), 9, "Verdana", White);
- ObjectSet("ObjName4", OBJPROP_CORNER, 0);
- ObjectSet("ObjName4", OBJPROP_XDISTANCE, 20);
- ObjectSet("ObjName4", OBJPROP_YDISTANCE, 80);
- ObjectCreate("ObjName5", OBJ_LABEL, 0, 0, 0);
- ObjectSetText("ObjName5", "Put this EA on EURUSD H1 ", 9, "Verdana", White);
- ObjectSet("ObjName5", OBJPROP_CORNER, 0);
- ObjectSet("ObjName5", OBJPROP_XDISTANCE, 20);
- ObjectSet("ObjName5", OBJPROP_YDISTANCE, 100);
- if (StringFind(Symbol(),"EURUSD",0) < 0) Alert("Put this EA on EURUSD chart. H1.");
- }
- //--------------------------------------------------------------------------------
- void deinit() {
- // 2010/9/18 Change (3) - Delete only objects from this EA
- ObjectDelete("ObjName1");
- ObjectDelete("ObjName2");
- ObjectDelete("ObjName3");
- ObjectDelete("ObjName4");
- ObjectDelete("ObjName5");
- }
- //--------------------------------------------------------------------------------
- int start(){
- // 2010/9/18 Change (2) - Unified and Simplified Lot Size Display
- // 2010/9/18 Change (5) - Screen display now show values from variables instead of hard coded values
- MinLots = MarketInfo(Symbol(),MODE_MINLOT);
- dLots = (MathCeil(AccountEquity ()/((dOneStopLossPoint*10)/nPctToRisk)))/100;
- dLots = NormalizeDouble(dLots/MinLots,0) * MinLots;
- ObjectSetText("ObjName3", "You are trading " + DoubleToStr(dLots,2) + " Lots. Account Minimum Lot Size=" + DoubleToStr(MinLots,2), 9, "Verdana", White);
- if (lFlagUseHourTrade){
- if (!(Hour()>=nFromHourTrade && Hour()<=nToHourTrade)) {
- Comment("Time for trade has not come else!");
- return(0);
- }
- }
- if(Bars < 100){
- Print("bars less than 100");
- return(0);
- }
- if (nAccount > 0 && nAccount != AccountNumber()){
- Comment("Trade on account :"+AccountNumber()+" FORBIDDEN!");
- return(0);
- }
- if((dBuyStopLossPoint > 0 && dBuyStopLossPoint < MIN_STOPLOSS_POINT) ||
- (dSellStopLossPoint > 0 && dSellStopLossPoint < MIN_STOPLOSS_POINT)){
- Print("StopLoss less than " + MIN_STOPLOSS_POINT);
- return(0);
- }
- if((dBuyTakeProfitPoint > 0 && dBuyTakeProfitPoint < MIN_TAKEPROFIT_POINT) ||
- (dSellTakeProfitPoint > 0 && dSellTakeProfitPoint < MIN_TAKEPROFIT_POINT)){
- Print("TakeProfit less than " + MIN_TAKEPROFIT_POINT);
- return(0);
- }
- // indicators
- double diWPR1=iWPR(NULL,1,155,0);
- double diWPR2=iWPR(NULL,5,155,0);
- double diWPR3=iWPR(NULL,15,155,0);
- double diWPR4=iWPR(NULL,1,155,0);
- double diWPR5=iWPR(NULL,1,250,0);
- double diWPR6=iWPR(NULL,1,500,0);
- double diClose25=iClose(NULL,1,0);
- double diMA26=iMA(NULL,1,605,0,MODE_EMA,PRICE_CLOSE,0);
- double diMA27=iMA(NULL,1,700,0,MODE_EMA,PRICE_CLOSE,0);
- double diMA28=iMA(NULL,5,700,0,MODE_EMA,PRICE_CLOSE,0);
- double diMA29=iMA(NULL,15,700,0,MODE_EMA,PRICE_CLOSE,0);
- double diATR64=iATR(NULL,1,600,0);
- double diStochastic81=iStochastic(NULL,5,55,15,3,MODE_EMA,PRICE_CLOSE,MODE_MAIN,0);
- double diStochastic82=iStochastic(NULL,5,55,15,3,MODE_EMA,PRICE_CLOSE,MODE_SIGNAL,0);
- double diStochastic83=iStochastic(NULL,5,100,35,3,MODE_EMA,PRICE_CLOSE,MODE_MAIN,0);
- double diStochastic84=iStochastic(NULL,5,100,35,3,MODE_EMA,PRICE_CLOSE,MODE_SIGNAL,0);
- double diRSI93=iRSI(NULL,1,3,PRICE_CLOSE,0);
- // MoneyManagement
- MinLots = MarketInfo(Symbol(),MODE_MINLOT);
- MaxLots = MarketInfo(Symbol(),MODE_MAXLOT);
- for (int ioht=OrdersHistoryTotal() -1; ioht >= 0; ioht--) {
- OrderSelect(ioht, SELECT_BY_POS, MODE_HISTORY);
- if (OrderMagicNumber() == MagicNumber)
- ioht = 0;
- }
- if (OrderProfit() == 0)
- dLots = MinLots;
- if (OrderProfit() > 0 && OrderLots() >= MinLots && OrderMagicNumber() == MagicNumber) {
- // 2010/9/18 Change (5) - Pip value from variables dStopLossPoint are used instead of hard coded values 500 (50x10)
- dLots = (MathCeil(AccountEquity ()/((dOneStopLossPoint*10)/nPctToRisk)))/100;
- // 2010/9/18 Change (1) - Tranform dLots to Integer Multiple of MinLots
- dLots = NormalizeDouble(dLots/MinLots,0) * MinLots;
- if (dLots == 0) {
- dLots = MinLots;
- Print("Balance too low: Trading minimum lot size!");
- }
- }
- // if lose, use smallest lot to test the market before resume full lots
- if (OrderProfit() < 0 && OrderMagicNumber() == MagicNumber)
- dLots = MinLots;
- // ********** special days - trade smallest lot to avoid risk *******
- if ( Month() == 12 && Day()>15)
- dLots = MinLots;
- if (DayOfWeek()==5 && Hour()>18)
- dLots = MinLots;
- // limits
- if (dLots < MinLots)
- dLots = MinLots;
- if (dLots > MaxLots)
- dLots = MaxLots;
- // *******************************************************************
- // Stop SteadyWinner from trading if capital is danger low, less than 100
- if(AccountFreeMargin() < (100)){
- Print("We have no money. Free Margin = " + AccountFreeMargin());
- return(0);
- }
- bool lFlagBuyOpen = false, lFlagSellOpen = false, lFlagBuyClose = false, lFlagSellClose = false;
- lFlagBuyOpen = ((diATR64>0.0001)) && diRSI93<35 &&
- (diStochastic81<diStochastic82) && (diStochastic83<diStochastic84)
- && (diWPR1<-99.99) &&
- (diMA27 < diClose25) && (diMA28 < diClose25) && (diMA29 < diClose25)
- ;
- lFlagSellOpen = ((diATR64>0.0001)) && diRSI93>65 &&
- (diStochastic81>diStochastic82) && (diStochastic83>diStochastic84)
- && (diWPR1>-0.01) &&
- (diMA27 > diClose25) && (diMA28 > diClose25) && (diMA29 > diClose25)
- ;
- lFlagBuyClose = (OrderMagicNumber() == MagicNumber && TimeCurrent()-OrderOpenTime()>360) &&
- (diStochastic81>diStochastic82) && (diStochastic83>diStochastic84)
- && (diWPR1>-50)
- ;
- lFlagSellClose = (OrderMagicNumber() == MagicNumber && TimeCurrent()-OrderOpenTime()>360) &&
- (diStochastic81<diStochastic82) && (diStochastic83<diStochastic84)
- && (diWPR1<-50)
- ;
- // operaton codes
- if (!ExistPositions()){
- if (lFlagBuyOpen){
- OpenBuy();
- return(0);
- }
- if (lFlagSellOpen){
- OpenSell();
- return(0);
- }
- }
- if (ExistPositions()){
- if(OrderType()==OP_BUY){
- if (lFlagBuyClose){
- bool flagCloseBuy = OrderClose(OrderTicket(), OrderLots(), Bid, nSlippage, colorCloseBuy);
- if (flagCloseBuy && lFlagUseSound)
- PlaySound(sSoundFileName);
- return(0);
- }
- }
- if(OrderType()==OP_SELL){
- if (lFlagSellClose){
- bool flagCloseSell = OrderClose(OrderTicket(), OrderLots(), Ask, nSlippage, colorCloseSell);
- if (flagCloseSell && lFlagUseSound)
- PlaySound(sSoundFileName);
- return(0);
- }
- }
- }
- if (dBuyTrailingStopPoint > 0 || dSellTrailingStopPoint > 0){
- for (int i=0; i<OrdersTotal(); i++) {
- if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
- bool lMagic = true;
- if (MagicNumber > 0 && OrderMagicNumber() != MagicNumber)
- lMagic = false;
- if (OrderSymbol()==Symbol() && lMagic) {
- if (OrderType()==OP_BUY && dBuyTrailingStopPoint > 0) {
- if (Bid-OrderOpenPrice() > dBuyTrailingStopPoint*point) {
- if (OrderStopLoss()<Bid-dBuyTrailingStopPoint*point)
- ModifyStopLoss(Bid-NormalizeDouble(dBuyTrailingStopPoint*point,5));
- }
- }
- if (OrderType()==OP_SELL) {
- if (OrderOpenPrice()-Ask>dSellTrailingStopPoint*point) {
- if (OrderStopLoss()>Ask+dSellTrailingStopPoint*point || OrderStopLoss()==0)
- ModifyStopLoss(Ask+NormalizeDouble(dSellTrailingStopPoint*point,5));
- }
- }
- }
- }
- }
- }
- return (0);
- }
- //--------------------------------------------------------------------------------
- bool ExistPositions() {
- for (int i=0; i<OrdersTotal(); i++) {
- if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
- bool lMagic = true;
- if (MagicNumber > 0 && OrderMagicNumber() != MagicNumber)
- lMagic = false;
- if (OrderSymbol()==Symbol() && lMagic) {
- return(True);
- }
- }
- }
- return(false);
- }
- //--------------------------------------------------------------------------------
- void ModifyStopLoss(double ldStopLoss) {
- bool lFlagModify = OrderModify(OrderTicket(), NormalizeDouble(OrderOpenPrice(),5), NormalizeDouble(ldStopLoss,5), NormalizeDouble(OrderTakeProfit(),5), 0, CLR_NONE);
- if (lFlagModify && lFlagUseSound)
- PlaySound(sSoundFileName);
- }
- //--------------------------------------------------------------------------------
- void OpenBuy() {
- double dStopLoss = 0, dTakeProfit = 0;
- if (dBuyStopLossPoint > 0)
- dStopLoss = NormalizeDouble(Bid-dBuyStopLossPoint*point,5);
- if (dBuyTakeProfitPoint > 0)
- dTakeProfit = NormalizeDouble(Bid + dBuyTakeProfitPoint * point,5);
- int numorder = OrderSend(Symbol(), OP_BUY, dLots, Ask, nSlippage, 0, 0, "SteadyWinner4", MagicNumber, 0, colorOpenBuy);
- if (numorder > -1) {
- OrderSelect(numorder,SELECT_BY_TICKET);
- OrderModify(OrderTicket(),OrderOpenPrice(),dStopLoss,dTakeProfit,0,Green);
- }
- if (numorder > -1 && lFlagUseSound)
- PlaySound(sSoundFileName);
- }
- //--------------------------------------------------------------------------------
- void OpenSell() {
- double dStopLoss = 0, dTakeProfit = 0;
- if (dSellStopLossPoint > 0)
- dStopLoss = NormalizeDouble(Ask+dSellStopLossPoint*point,5);
- if (dSellTakeProfitPoint > 0)
- dTakeProfit = NormalizeDouble(Ask-dSellTakeProfitPoint*point,5);
- int numorder = OrderSend(Symbol(),OP_SELL, dLots, Bid, nSlippage, 0, 0, "SteadyWinner4", MagicNumber, 0, colorOpenSell);
- if (numorder > -1) {
- OrderSelect(numorder,SELECT_BY_TICKET);
- OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(dStopLoss,5), NormalizeDouble(dTakeProfit,5),0,Green);
- }
- if (numorder > -1 && lFlagUseSound)
- PlaySound(sSoundFileName);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement