SimplePivot

Author: Copyright � 2006, Derk Wehler, Global One Group
Orders Execution
It Closes Orders by itself It automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
12.00 %
Total Trades 167
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -59.29
Gross Profit 1306.00
Gross Loss -11207.00
Total Net Profit -9901.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
77.00 %
Total Trades 951
Won Trades 434
Lost trades 517
Win Rate 0.46 %
Expected payoff -10.12
Gross Profit 32961.00
Gross Loss -42587.00
Total Net Profit -9626.00
-100%
-50%
0%
50%
100%
SimplePivot
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//|                                                  SimplePivot.mq4 |
//|                  Copyright © 2006, Derk Wehler, Global One Group |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Derk Wehler, Global One Group"
#property link      "http://www.metaquotes.net"

//---- input parameters
extern int Lots = 1;

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
   static int prevTradeOp = -1;
   static int prevBars = -1;
   static int ticketNum = -1;
   
   int curBars = Bars;
   if (prevBars == -1)
      prevBars = curBars;

   Print("curBars, prevBars = ", curBars);
   if (curBars == prevBars)
      return(0);
   Print("After checking bars");
      
   prevBars = curBars;
   
   // Only buy and tell on the first tick of new candle creation
   double prevHigh = High[1];
   double prevLow = Low[1];
   double curOpen = Open[0];
   double pivot = (prevHigh + prevLow) / 2;
   int tradeOp = OP_BUY;

   // Determine whether we are in a buy or sell position for this candle
   if (curOpen < prevHigh && curOpen > pivot)
      tradeOp = OP_SELL;

   // If we were in a buy, and still in a buy for this new candle, do not 
   // close and re-open the trade, giving up the spread again.  Same for sell.
   if (tradeOp == prevTradeOp && prevTradeOp != -1)
      return(0);
      
   Print("Closing old trade");
   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   // Close the current trade
   if (ticketNum != -1)
   {
      OrderSelect(ticketNum, SELECT_BY_TICKET);
   
      // long position is opened
      if (OrderType() == OP_BUY) 
      {
         OrderClose(ticketNum, OrderLots(), Bid, 0, Violet);
      }
      // short position is opened
      else
      {
         OrderClose(ticketNum, OrderLots(), Ask, 0, Violet);
      }
   }
   
   Print("Opening new trade");
   // - - - - - - - - - - - - - - - - - - - - - - - - - - - - 
   // Open new trade
   if (tradeOp == OP_BUY)
   {
     ticketNum = OrderSend(Symbol(), OP_BUY, Lots, Ask, 0, 0,
         0, "Simple Pivot", 55255, 0, Green);
      if (ticketNum > 0)
      {
         if (OrderSelect(ticketNum, SELECT_BY_TICKET))
            Print("BUY order opened : ",OrderOpenPrice());
      }
      else 
         Print("Error opening BUY order : ", GetLastError());
   }
   else
   {
      ticketNum = OrderSend(Symbol(), OP_SELL, Lots, Bid, 0, 0,
         0, "CSimple Pivot", 55255, 0, Red);
      if (ticketNum > 0)
      {
         if (OrderSelect(ticketNum, SELECT_BY_TICKET))
            Print("SELL order opened : ", OrderOpenPrice());
      }
      else 
         Print("Error opening SELL order : ", GetLastError());
   }
     
   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 ---