Stocheurusd

Author: Copyright � 2006, MetaQuotes Software Corp.
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Stochastic oscillator
1 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
0.00 %
Total Trades 0
Won Trades 0
Lost trades 0
Win Rate 0.0 %
Expected payoff 0.00
Gross Profit 0.00
Gross Loss 0.00
Total Net Profit 0.00
-100%
-50%
0%
50%
100%
Stocheurusd
//+------------------------------------------------------------------+
//|                                                      MyStoch.mq4 |
//|                      Copyright © 2006, MetaQuotes Software Corp. |
//|                                        http://www.alpari-idc.ru/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, MetaQuotes Software Corp."
#property link      "http://www.alpari-idc.ru/"

#include <stdlib.mqh>
#include <WinUser32.mqh>

#define MAGICMA 20050610
extern double Lots         =0.1;
extern double TakeProfit   =10;
extern double StopLoss     =1000;
extern double TrailingStop =100;

int res;

double Points;
double iStoch1;
double iStoch2;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   Points=MarketInfo("EURUSD",MODE_POINT);

//----
   return(0);
  }
  
  //+-------------------------------------+
  //ïðîâåðÿåì íàëè÷èå îòêðûòûõ îðäåðîâ
  //+-------------------------------------+
  int CalculateCurrentOrders(string symbol)
  {
  
  int buys=0,sells=0;
  for(int i=0;i<OrdersTotal();i++)
  {
  if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)break;
  if(OrderSymbol()=="EURUSD"&&OrderMagicNumber()==MAGICMA)
  {
  if(OrderType()==OP_BUY) buys++;
  if(OrderType()==OP_SELL) sells++;
  }
  }
  if(buys>0)return(buys);
  else return(-sells);
  }
  //+----------------------------------------------+
  //îòêðûâàåì îðäåð
  //+----------------------------------------------+
    void CheckForOpen()
  {
    iStoch1=iStochastic("EURUSD",0,7,10,4,MODE_SMA,0,MODE_MAIN,0);
     iStoch2=iStochastic("EURUSD",0,7,10,4,MODE_SMA,0,MODE_MAIN,1);
  //---------------------------------------------------------------------------------------------------//
  if(iStoch2<iStoch1&&iStoch1>=10&&iStoch1<15)
  res=OrderSend("EURUSD",OP_BUY,Lots,Ask,3,Ask-StopLoss*Points,Ask+TakeProfit*Points,"",MAGICMA,0,Blue);
  //---------------------------------------------------------------------------------------------------//
  if(iStoch2>iStoch1&&iStoch1<=95&&iStoch1>90)
  res=OrderSend("EURUSD",OP_SELL,Lots,Bid,3,Bid+StopLoss*Points,Bid-TakeProfit*Points,"",MAGICMA,0,Red);
  //---------------------------------------------------------------------------------------------------//

  return;
  }
  //---------------------------------------------------------------------+
  //Çàêðûâàåì îðäåðà
  //---------------------------------------------------------------------+
  void CheckForClose()
  {
 
     int total=OrdersTotal();
     int ordertype;
     int ticket;
     int index;
     //double priceClose;
     
     if(iStoch1<50)
     for( index=total-1;index>=0;index--)
     if(OrderSelect(index,SELECT_BY_POS))
      {
        ordertype=OrderType();
        ticket=OrderTicket();
     if(ordertype==OP_SELL&&OrderMagicNumber()==MAGICMA)
     OrderClose(ticket,OrderLots(),Ask,3,Red);
     else break;
      }
      
     if(iStoch1>50)
     for( index=total-1;index>=0;index--)
     if(OrderSelect(index,SELECT_BY_POS))
      {
        ordertype=OrderType();
        ticket=OrderTicket();
     if(ordertype==OP_BUY&&OrderMagicNumber()==MAGICMA)
     OrderClose(ticket,OrderLots(),Bid,3,Red);
     else break;
      }
             
          
  
  }
 

//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+

void start()
  {
//----

  if(Bars<100||IsTradeAllowed()==false)return;
  if(CalculateCurrentOrders("EURUSD")==0)CheckForOpen();
  else CheckForClose();
  
//----
   //return;
  }

//+------------------------------------------------------------------+

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