Stoch_TP_TS_V3103

Author:
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 strategy
Indicators Used
Stochastic oscillator
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites
Stoch_TP_TS_V3103
//+------------------------------------------------------------------+
//|                                            Stoch_TP_TS_V3103.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""

int time = 0;
extern int minut = 56;
extern int orders = 2;
extern int trailstop = 15;
extern int start = 95;
extern int stolos = 830;
extern int diff = 175;
extern int sign = 0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   double lot;
   if (AccountBalance() >= orders*diff*1000) lot=100;
   else if (AccountBalance() < orders*diff)
   {  Print("Not enough money!");   }
   else lot=(MathRound(AccountBalance()/(orders*diff))/10);
   
   if ((time != TimeHour(TimeCurrent())) && (minut == TimeMinute(TimeCurrent())))
   {
      time = TimeHour(TimeCurrent());
      double base = iStochastic(Symbol(),Period(),5,3,3,0,0,0,0);
      double signal = iStochastic(Symbol(),Period(),5,3,3,0,0,1,0);
      int ticket;
      int total=OrdersTotal();
      if(total<orders)
      {
         if (((signal - base) >= sign) && (base <= 80) && (base >= 20))
         {
            while(true)
            {
               ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,3,0,0,"SELL",0,0,Red);
               if(ticket<=0) Print("Error = ",GetLastError());
               else { Print("ticket = ",ticket); break; }
               //---- 10 seconds wait
               Sleep(10000);
            }
            PlaySound("alert2.wav");
         }
         else if (((base - signal) > sign) && (base <= 80) && (base >= 20))
         {
            while(true)
            {
               ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,3,0,0,"BUY",0,0,Green);
               if(ticket<=0) Print("Error = ",GetLastError());
               else { Print("ticket = ",ticket); break; }
               //---- 10 seconds wait
               Sleep(10000);
            }
            PlaySound("alert2.wav");
         }
      }
   }
   for (int i = 0; i < OrdersTotal(); i++) 
	{
		OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
		double TSTP = trailstop * Point;
		double STLO = stolos * Point;
		double TKPR = (start + 2 * start) * Point;

		if (OrderComment() == "BUY")
		{
			if ((Bid - OrderOpenPrice()) >= start * Point)
			{
				if (OrderStopLoss() < (Bid - TSTP))
				{
					OrderModify(OrderTicket(), OrderOpenPrice(), Bid - TSTP, 0, Red);
					PlaySound("expert.wav");
				}
			}
			else if (OrderStopLoss() == 0)
			{
			   OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - STLO, OrderOpenPrice() + TKPR,0);
			}
		}
		else if (OrderComment() == "SELL")
		{
			if ((OrderOpenPrice() - Ask) >= start * Point)
			{
				if (OrderStopLoss() > (Ask + TSTP))
				{
					OrderModify(OrderTicket(), OrderOpenPrice(), Ask + TSTP, 0, Red);
					PlaySound("expert.wav");
				}
			}
			else if (OrderStopLoss() == 0)
			{
			   OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + STLO, OrderOpenPrice() - TKPR,0);
			}
		}
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+

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 ---