This script is designed to automatically trade in the Forex market based on a set of technical indicators. Here's the breakdown:

Overall Strategy:

The script aims to identify potential buying or selling opportunities by analyzing several market indicators. If all the indicators point to a buying opportunity, it opens a "buy" trade. Conversely, if all indicators suggest selling, it opens a "sell" trade. The script also manages existing trades, closing them under specific conditions to potentially profit from market movements.

Key Components and How They Work:

  1. Input Parameters: The script has several adjustable settings (called "extern" variables) that you can customize. These include:

    • Lots: The size of the trades the script will execute (e.g., 1.0 means one standard lot).
    • fastmacd, slowmacd, signalmacd, psmma, stochD, stochK, stochS: These are settings used to configure the technical indicators, specifically defining the periods and smoothing methods.
    • Magic: A unique identifier number used to distinguish trades opened by this script from trades opened manually or by other scripts.
    • Slippage: The maximum acceptable difference between the requested price and the actual executed price when opening a trade.
  2. Time Check: The script checks the current time and only executes its logic when a new time period starts. This prevents it from performing the same calculations repeatedly within the same time frame, saving resources and avoiding unnecessary actions.

  3. Trade Management:

    • Existing Orders Check: The script first checks if there are any existing trades opened by itself (identified by the "magic number").
    • Closing Existing Trades: If an existing trade is found, the script evaluates whether to close the trade based on the current market conditions. If a "buy" trade is open, and the indicators now suggest a "sell" opportunity, the script will attempt to close the "buy" trade and open a "sell" trade in its place, and vice versa.
    • Order Closing: The script uses the OrderCloseBy function to close a currently oppened trade.
  4. Opening New Trades:

    • Signal Evaluation: If no existing trades are found or if the script has closed an existing trade, it evaluates the current market conditions to determine if a new trade should be opened.
    • "longsignal()" and "shortsignal()": These functions are the core of the trading strategy. They examine multiple market indicators. If all the conditions within longsignal() are met, it signals a buying opportunity. If all the conditions within shortsignal() are met, it signals a selling opportunity.
    • Order Placement: Based on the signals, the script will place a "buy" (long) or "sell" (short) order in the market.
  5. Technical Indicators: The longsignal() and shortsignal() functions rely on several technical indicators, including:

    • Awesome Oscillator (AO): Measures market momentum.
    • Moving Average Convergence Divergence (MACD): Identifies trends and potential changes in those trends.
    • Moving Average of Oscillator (OsMA): Similar to MACD, but focuses on the difference between the MACD line and the signal line.
    • Smoothed Moving Average (SMMA): Calculates the average price over a specific period.
    • Stochastic Oscillator: Compares a security's closing price to its price range over a certain period.
    • Candle Open Price: Simple comparison of the current candle open price against the previous candle.

    Each indicator function returns a value (+1 or -1) based on its calculation and compares this value against a positive or negative threshold to generate a signal.

  6. Trade Execution:

    • OrderSend(): Sends the order to the broker with the specified parameters (symbol, order type, volume, price, slippage, etc.).
    • Sleep(): After sending an order, the script pauses for 30 seconds. This is likely intended to allow the order to be properly processed and avoid placing multiple orders in quick succession.
    • Error Handling: If the order placement fails (e.g., due to insufficient funds or market conditions), the script adjusts the time and exits the current cycle.

In Simple Terms:

Imagine this script as a robot trader that follows a set of rules to buy and sell currencies. It constantly monitors several indicators that are like weather vanes for the market. If all the vanes point in one direction (e.g., "buy"), the robot places a buy order. If they all point in the opposite direction ("sell"), it places a sell order. The robot also manages existing trades, closing them and potentially reversing the position if the "weather vanes" start pointing the other way. The settings allow you to adjust how sensitive the robot is to these signals.

Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reached
Indicators Used
Bill Williams Awesome oscillatorMACD HistogramMoving Average of OscillatorMoving average indicatorStochastic oscillator
2 Views
0 Downloads
0 Favorites

Profitability Reports

NZD/USD Oct 2024 - Jan 2025
101.00 %
Total Trades 8
Won Trades 4
Lost trades 4
Win Rate 50.00 %
Expected payoff 23.62
Gross Profit 20957.00
Gross Loss -20768.00
Total Net Profit 189.00
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
110.00 %
Total Trades 7
Won Trades 4
Lost trades 3
Win Rate 57.14 %
Expected payoff 278.86
Gross Profit 20638.00
Gross Loss -18686.00
Total Net Profit 1952.00
-100%
-50%
0%
50%
100%
ssb5_123
//+-------------------------------------------------------------------------+
//|                                                                SSB5.mq4 |
//|                Copyright © 2009, Yury V. Reshetov  http://ssb.bigfx.ru/ |
//|                                                    http://ssb.bigfx.ru/ |
//+-------------------------------------------------------------------------+
#property copyright "Copyright © 2009, Yury V. Reshetov http://ssb.bigfx.ru"
#property link      "http://ssb.bigfx.ru"

/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see http://www.gnu.org/licenses/
*/

extern double lots = 1;
extern int fastmacd = 47;
extern int slowmacd = 95;
extern int signalmacd = 74;
extern int psmma = 45;
extern int stochD = 12;
extern int stochK = 25;
extern int stochS = 56;
extern int magic = 888;
extern int slippage = 0;
static int prevtime = 0;

int init() {
   prevtime = Time[0];
   return(0);
}

int start() {

   if (! IsTradeAllowed()) {
      return(0);
   }

   if (Time[0] == prevtime) {
      return(0);
   }
   prevtime = Time[0];

   int ticket = -1;
   int total = OrdersTotal();
   for (int i = total - 1; i >= 0; i--) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if ((OrderSymbol() == Symbol()) && (OrderMagicNumber() == magic)) {
         int prevticket = OrderTicket();
         if (OrderType() == OP_BUY) {
            if (shortsignal()) {
               ticket = OrderSend(Symbol(), OP_SELL, 2.0 * lots, Bid, slippage, 0, 0, WindowExpertName(), magic, 0, Red);
               Sleep(30000);
               if (ticket < 0) {
                  prevtime = Time[1];
                  return(0);
               } else {
                  OrderCloseBy(ticket, prevticket, Red);
               }
            }
          } else {
            if (longsignal()) {
               ticket = OrderSend(Symbol(), OP_BUY, 2.0 * lots, Ask, slippage, 0, 0, WindowExpertName(), magic, 0, Blue);
               Sleep(30000);
               if (ticket < 0) {
                  prevtime = Time[1];
                  return(0);
               } else {
                  OrderCloseBy(ticket, prevticket, Blue);
               }
            }
          }
          return(0);
      }
   }

   if (longsignal()) {
      ticket = OrderSend(Symbol(), OP_BUY, lots, Ask, slippage, 0, 0, WindowExpertName(), magic, 0, Blue);
      Sleep(30000);
      if (ticket < 0) {
         prevtime = Time[1];
      }
      return(0);
   }
   if (shortsignal()) {
      ticket = OrderSend(Symbol(), OP_SELL, lots, Bid, slippage, 0, 0, WindowExpertName(), magic, 0, Red);
      Sleep(30000);
      if (ticket < 0) {
         prevtime = Time[1];
      }
      return(0);
   }
   return(0);
}

bool longsignal() {
   if (fcandle() < 0) {
      return(false);
   }
   if (fao() < 0) {
      return(false);
   }
   if (fao1() < 0) {
      return(false);
   }
   if (fmacd() < 0) {
      return(false);
   }
   if (fmacd1() < 0) {
      return(false);
   }
   if (fosma1() < 0) {
      return(false);
   }
   if (fsmma() < 0) {
      return(false);
   }
   if (fstoch1() < 0) {
      return(false);
   }
   if (fstoch2() < 0) {
      return(false);
   }
   return(true);
}

bool shortsignal() {
   if (fcandle() > 0) {
      return(false);
   }
   if (fao() > 0) {
      return(false);
   }
   if (fao1() > 0) {
      return(false);
   }
   if (fmacd() > 0) {
      return(false);
   }
   if (fmacd1() > 0) {
      return(false);
   }
   if (fosma1() > 0) {
      return(false);
   }
   if (fsmma() > 0) {
      return(false);
   }
   if (fstoch1() > 0) {
      return(false);
   }
   if (fstoch2() > 0) {
      return(false);
   }
   return(true);
}
int fcandle() {
   int result = 0;
   if (Open[0] < Open[1]) {
      result = 1;
   }
   if (Open[0] > Open[1]) {
      result = -1;
   }
   return(result);
}



int fao() {
   int result = 0;
   double ind = iAO(Symbol(), 0, 0);
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}

int fao1() {
   int result = 0;
   double ind = iAO(Symbol(), 0, 0);
   double ind1 = iAO(Symbol(), 0, 1);
   if ((ind - ind1) < 0) {
      result = 1;
   }
   if ((ind - ind1) > 0) {
      result = -1;
   }
   return(result);
}
int fmacd() {
   int result = 0;
   double ind = iMACD(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, MODE_MAIN, 0);
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}

int fmacd1() {
   int result = 0;
   double ind = iMACD(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, MODE_MAIN, 0);
   double ind1 = iMACD(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, MODE_MAIN, 1);
   if ((ind - ind1) > 0) {
      result = 1;
   }
   if ((ind - ind1) < 0) {
      result = -1;
   }
   return(result);
}

int fosma1() {
   int result = 0;
   double ind = iOsMA(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, 0);
   double ind1 = iOsMA(Symbol(), 0, fastmacd, slowmacd, signalmacd, PRICE_OPEN, 1);
   if ((ind - ind1) < 0) {
      result = 1;
   }
   if ((ind - ind1) > 0) {
      result = -1;
   }
   return(result);
}







int fsmma() {
   int result = 0;
   double ind = Open[0] - iMA(Symbol(), 0, psmma, 0, MODE_SMMA, PRICE_OPEN, 0);
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}



int fstoch1() {
   int result = 0;
   double ind = iStochastic(Symbol(), 0, stochK, stochD, stochS, MODE_SMMA, 0,MODE_MAIN, 0) - 50.0;
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}

int fstoch2() {
   int result = 0;
   double ind = iStochastic(Symbol(), 0, stochK, stochD, stochS, MODE_SMMA, 0,MODE_SIGNAL, 0) - 50.0;
   if (ind > 0) {
      result = 1;
   }
   if (ind < 0) {
      result = -1;
   }
   return(result);
}

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