Nouf_Stochastic_20&80(2)

Author: Copyright � 2007, dr_waleed
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategyIt Closes Orders by itself
Indicators Used
Stochastic oscillator
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
94.00 %
Total Trades 86
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -2.91
Gross Profit 4150.00
Gross Loss -4400.00
Total Net Profit -250.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
65.00 %
Total Trades 134
Won Trades 48
Lost trades 86
Win Rate 0.36 %
Expected payoff -22.76
Gross Profit 5550.00
Gross Loss -8600.00
Total Net Profit -3050.00
-100%
-50%
0%
50%
100%
Nouf_Stochastic_20&80(2)
//+------------------------------------------------------------------+
//|                                              nouf stochastic.mq4 |
//|                                     Copyright © 2007 , dr_waleed |
//|                                                dr_waleed@msn.com |
//+------------------------------------------------------------------+
 
#property copyright   "Copyright © 2007, dr_waleed"
#property link        "dr_waleed@msn.com" 

//---- Trades Limits

extern int         TakeProfit            = 150;
extern int         StopLoss              = 100;      
extern int         TrailingStop          = 100;  
extern bool        SmartClose            = true; 
extern int         current               = 0;
 
//---- Stochastic

extern int         Kperiod1              = 5;
extern int         Kperiod2              = 125;
extern int         Kperiod3              = 14;
extern int         Dperiod               = 3;
extern int         slowing               = 3; 

extern int         Sto5Buy               = 20;
extern int         Sto5Sell              = 80;

extern int         Sto125Buy             = 50;
extern int         Sto125Sell            = 50;

extern int         CloseBuy              = 80;
extern int         CloseSell             = 20;

 
//---- Money Monagement

extern bool        MoneyManagment        = false;
extern int         Risk                  = 5;
extern double      Lots                  = 1;
extern int         MaxTrades             = 1;

//---- Hour Trades

extern bool        UseHourTrade          = false;
extern int         FromHourTrade         = 0;
extern int         ToHourTrade           = 0;

//---- Global variables

extern int         Magic                 = 0;
string             eaComment             = "nouf stochastic";

//+------------------------------------------------------------------+
//|    Initialation function                                         |
//+------------------------------------------------------------------+

int init()
   {
    return(0);
   }

int orderscnt()
   {
    int cnt=0;
    for(int i =0;i<OrdersTotal();i++)
       {
        if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
          {
           if(OrderSymbol()== Symbol() && Magic==OrderMagicNumber())
             {
              cnt++;
             }
          }
       }
     return(cnt);
   }

//+------------------------------------------------------------------+
//|    Start function                                                |
//+------------------------------------------------------------------+

int start()
   {    
       
      if (UseHourTrade)
       {
       if(!(Hour()>=FromHourTrade&&Hour()<=ToHourTrade))
         {
          Comment("Non-Trading Hours!");
               return(0);   // Use Hour Trade
         }
       }
     
    if(Bars<100)
      {
       Print("bars less than 100");
          return(0);   // check Bars
      }
      
    if(TakeProfit < 10)
      {
        Print("TakeProfit less than 10");
        return(0);   // check Take Profit
      }
      
         
    double Stop, Limit;
    int cnt, total;
    
    if(MoneyManagment) Lots = subLotSize();
 

      double   stoM1, stoM2, stoM3, stoM4, stoM5;
      
             stoM1 = iStochastic( NULL, 0, Kperiod1, Dperiod, slowing, 0, 0, MODE_MAIN, current);
             stoM2 = iStochastic( NULL, 0, Kperiod1, Dperiod, slowing, 0, 0, MODE_MAIN, current+1); 
             stoM3 = iStochastic( NULL, 0, Kperiod2, Dperiod, slowing, 0, 0, MODE_MAIN, current);  
             stoM4 = iStochastic( NULL, 0, Kperiod3, Dperiod, slowing, 0, 0, MODE_MAIN, current);       
             stoM5 = iStochastic( NULL, 0, Kperiod3, Dperiod, slowing, 0, 0, MODE_MAIN, current+1);
                                                   
                       
    total=OrdersTotal();
    
    if(total<1) 
      {    
       if(AccountFreeMargin()<(1000*Lots))
         {
          Print("We have no money. Free Margin = ",AccountFreeMargin());
             return(0);  
         }    
            
//+------------------------------------------------------------------+
//|    Buy & Sell                                                    |
//+------------------------------------------------------------------+
            
       if    ( stoM1>Sto5Buy && stoM2<Sto5Buy && stoM3>Sto125Buy)   //------------------ Buy
         {
          if(orderscnt()<MaxTrades)
            {
             if(StopLoss==0)
               {Stop=0;TrailingStop=0;}
             else
               {Stop=Ask-StopLoss*Point;}
             if(TakeProfit==0)
               {Limit=0;}
             else
               {Limit=Ask+TakeProfit*Point;}
                OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Stop,Limit,eaComment,Magic,0,Green);
                PlaySound("Alert.wav");
               } 
             }
                          
       if    ( stoM1<Sto5Sell && stoM2>Sto5Sell && stoM3<Sto125Sell)   //------------------ Sell
         {
          if(orderscnt()<MaxTrades)
            {
             if(StopLoss==0)
               {Stop=0;TrailingStop=0;}
             else
               {Stop=Bid+StopLoss*Point;}
             if(TakeProfit==0)
               {Limit=0;}
             else
               {Limit=Bid-TakeProfit*Point;}
                OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Stop,Limit,eaComment,Magic,0,Red); 
                PlaySound("Alert.wav");
               }  
            }
        return(0);
      }
            
//+------------------------------------------------------------------+
//|    Trailing Stop                                                 |
//+------------------------------------------------------------------+ 

for(cnt=0;cnt<total;cnt++)
  {               
   OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
     {
      if(OrderType()==OP_BUY)
        {
         if(TrailingStop>0)  
           {                 
            if(Bid-OrderOpenPrice()>Point*TrailingStop)
              {
               if(OrderStopLoss()<Bid-Point*TrailingStop && OrderStopLoss()<OrderOpenPrice())
                 {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+Point*TrailingStop,OrderTakeProfit(),0,Green);
                           return(0);
                 }
              }
           }
        }
      if(OrderType()==OP_SELL)
        {
         if(TrailingStop>0)  
           {                 
            if(OrderOpenPrice()-Ask>Point*TrailingStop)
              {
               if(OrderStopLoss()>Ask+Point*TrailingStop && OrderStopLoss()>OrderOpenPrice())
                 {
                  OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()-Point*TrailingStop,OrderTakeProfit(),0,Red);
                        return(0);
                 }
              }
           }
        }
     }
  }
  
//+------------------------------------------------------------------+
//|    Smart Close                                                   |
//+------------------------------------------------------------------+ 

if (SmartClose)
  {      
   for(cnt=0;cnt<total;cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) 
        {
         if(OrderType()==OP_BUY)
           {
            if    ( stoM4<CloseBuy && stoM5>CloseBuy )   //-------------------------------Cloes Buy
              {
               OrderClose(OrderTicket(),OrderLots(),Bid,3,Yellow);
                       return(0);
              }
           }
         else
           {
            if    ( stoM4>CloseSell && stoM5<CloseSell )   //-------------------------------Close Sell
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Yellow);
                       return(0);
              }
           }
        }
     }
  }
    return(0);
   }
   
//+------------------------------------------------------------------+
//|    Money Management                                              |
//+------------------------------------------------------------------+
  
double subLotSize()
    {
     double lotMM = MathCeil(AccountFreeMargin() *  Risk / 1000) / 100; 
	    {
	     if(lotMM < 0.01)                 lotMM = Lots;
	     if(lotMM > 1.0)                  lotMM = MathCeil(lotMM);
	     if(lotMM > 100)                  lotMM = 100;
	      return (lotMM);
       }
    }
    
//------------------------------------------------------------------------- The End.

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---