domi-harvest

Author: Copyright� Domi-Harvest 2009
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategy
Indicators Used
Relative strength indexMoving average indicatorStochastic oscillator
1 Views
0 Downloads
0 Favorites
domi-harvest
#property copyright "Copyright© Domi-Harvest 2009"
#property link "jadvir@gmail.com"
extern double Deposit       =  10000 ;
extern double Risk          =  10;
extern double TrailingStop  =  20;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   double Lots,Lot,Hi,Lo,Sell,Buy,By,Sl,Tg,Tpb,Tps,TR,TpB,TpS,Stop,Fma,Sma,Fma1,Sma1,Lot1;
   double Fma2,Fma3,Sma2,Sma3,Sma4,Fma4,Fma5,Sma5,close,StoM,StoS,TakeProfit,Rsi;
   int cnt,total,i;
   
   Rsi=iRSI(NULL,0,5,PRICE_CLOSE,0);
   Fma1=iMA(NULL,0,12,0,MODE_EMA,PRICE_CLOSE,0);
   Sma1=iMA(NULL,0,26,0,MODE_EMA,PRICE_CLOSE,0);   
   StoM=iStochastic(NULL,PERIOD_H1,5,3,3,MODE_EMA,0,MODE_MAIN,0);
   StoS=iStochastic(NULL,PERIOD_H1,5,3,3,MODE_EMA,0,MODE_SIGNAL,0);
   Fma1=iMA(NULL,PERIOD_H1,9,0,MODE_EMA,PRICE_CLOSE,0);
   Sma1=iMA(NULL,PERIOD_H1,5,0,MODE_EMA,PRICE_CLOSE,0);

   if (AccountBalance()>=Deposit*2)
   Lots= ((AccountBalance()/100000*Risk)/2);
   Lot=NormalizeDouble(Lots,1);
   
   if (OrderProfit()>=500 && OrderProfit()<=700)
   Lots= ((AccountBalance()/100000*Risk)*1.5);
   Lot=NormalizeDouble(Lots,1);
   
   if (AccountBalance()<=Deposit)
   Lots= ((AccountBalance()/100000*Risk)/4);
   Lot=NormalizeDouble(Lots,1);
   
   Lots= (AccountBalance()/100000*Risk);
   Lot=NormalizeDouble(Lots,1);
      
  total=OrdersTotal();
   if(total<1)

   {
      // Normal Tradee with adjustable risk
      
        Comment( 
        " ----------------------------------------\n",
        " Name   ",AccountName(),"\n",
        " ----------------------------------------\n",
        " Trading Signal NONE \n",
        " Trading Lot              ",Lot," Lot","\n", 
        " ----------------------------------------\n", 
        " Profit       $",AccountBalance()-Deposit,"\n", 
        " ----------------------------------------");
    
        
 // check for long position (BUY) possibility
  
        
        if (Volume[0]<2)  return;

        if ( Rsi>70 && StoM>StoS && Bid>Open[0] && Hour()>=1 && Hour()<=23)  
               {
         OrderSend(Symbol(),OP_BUY,Lot,Ask,5,0,Bid+20*Point,0,0,Green);
        }
       if ( Rsi<30 && StoM<StoS && Bid<Open[0] && Hour()>=1 && Hour()<=23) 
        {
         OrderSend(Symbol(),OP_SELL,Lot,Bid,5,0,Ask-20*Point,0,0,Red);
        }
        
     }
     
       
     // CHECK WHEN TO COLLECT YOUR PROFIT FROM THE MARKET 
   for(cnt=0;cnt<total;cnt++)
     {
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==false)break;
      if(OrderSymbol()!=Symbol()) continue;
      if(OrderType()<=OP_SELL &&   // check for opened position
         OrderSymbol()==Symbol())  // check for symbol
        {
         if(OrderType()==OP_BUY)   // long position is opened
           {
            // should it be closed?
           
         if((Bid==High[3]) )
                {
                 OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position
                 return(0); // exit
                }
            // check for trailing stop
            if(TrailingStop>0)
              {                 
               if(Bid-OrderOpenPrice()>Point*TrailingStop)
                 {
                  if(OrderStopLoss()<Bid-Point*TrailingStop)
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                    }
                 }
              }
           }
         
         else // go to short position
           {
           if((Ask==Low[3]))
              {
               OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
               return(0); // exit
              }
            // check for trailing stop
            if(TrailingStop>0)
              {                 
               if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
                 {
                  if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                    {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                     return(0);
                    }
                 }
              }
           }
        }
     }
   return(0);
  }
// 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 ---