cloud's trade 2

Author: cloud666@rbcmail.ru
Profit factor:
2.30

This script is designed to automate trading in the Forex market using the MetaTrader platform. Here's a breakdown of how it works:

1. Initial Setup & Configuration:

  • The script starts by reading in a set of rules and settings. These settings, defined as "extern," allow you to customize the script's behavior without needing to modify the code itself. These settings include:

    • Stochastic Oscillator Parameters: These define how the script uses a technical indicator called the Stochastic Oscillator. (Kperiod, Dperiod, Slowing, Method, PriceUsing)
    • Order Size: Maximum amount to risk on a trade (MaxLot) and a factor to calculate the lot size based on the account balance (LotSpliter).
    • Profit & Loss Levels: Values for setting target profits (TakeProfit), stop-loss levels to limit potential losses (StopLoss), minimum profit thresholds (MinProfit), and profit levels at which the stop-loss might be adjusted (TrailingStop, ProfitPoints).
    • Trading Conditions: Rules that must be met before the script opens or closes a trade (Condition1, Condition2, CloseByOtherSideCondition).

2. Main Operation - The "Start" Function:

  • This is the heart of the script, where the magic happens. It's executed repeatedly by the MetaTrader platform to analyze the market and manage trades.
  • Checking for Existing Trades: It first checks if any trades are already open.
    • If no trades are open, it decides whether to open a new buy or sell order based on the trading conditions (see step 3).
    • If a trade is already open, it manages the existing trade, by the stop loss.

3. Determining Buy or Sell Signals (The "U" Functions):

  • The script uses two sets of rules, "U1" and "U2", to decide if it should buy or sell.
  • U1: This rule set uses the Stochastic Oscillator, a popular technical indicator that measures the momentum of price. It looks for situations where the Stochastic Oscillator suggests the market is either "overbought" (likely to fall) or "oversold" (likely to rise). The parameters specified can impact on this part.
  • U2: This rule set uses Fractals, which identify potential reversal points on a chart. It looks for patterns of fractals to indicate an upward or downward trend.
  • Combining Rules: The "U" function combines the results of "U1" and "U2" based on whether Condition1 or Condition2 are enabled (set to 1). If either of the conditions are met on one of the two rules, it returns a buy or sell signal.

4. Opening Trades (OrderBuy & OrderSell):

  • If the "U" function signals a buy or sell, the script determines the appropriate order size ("Lot") based on your account balance and the specified LotSpliter parameter.
  • The script then sends an order to the Forex broker to open a buy or sell position at the current market price. It also sets the stop-loss and take-profit levels based on the configured settings if any.

5. Managing Open Trades:

  • If a trade is already open, the script continuously monitors its performance and takes the following actions:
    • Trailing Stop: It adjusts the stop-loss level upwards for buy orders or downwards for sell orders as the price moves in a favorable direction. This helps to lock in profits and limit potential losses.
    • Profit Target: If the trade reaches a certain profit level ("ProfitPoints") and the current profit is below a minimum level ("MinProfit"), the script closes the trade. This is a profit-taking mechanism.
    • Opposite Signal: If the opposite signal is generated by the "U" function based on "CloseByOtherSideCondition", the script closes the existing trade and prepares to open a trade in the opposite direction.

6. Closing Trades (CloseOnlyOrder):

  • The script has a function to close the current active trade based on some of the conditions mentioned above (profit taking or signal reversal).

In short, this script is an automated trading system that uses technical indicators (Stochastic Oscillator, Fractals) to generate buy and sell signals, manage open trades with trailing stops and profit targets, and close trades based on certain conditions. The overall goal is to automate trading decisions and potentially generate profits.

Price Data Components
Series array that contains open time of each bar
Orders Execution
Checks for the total of closed ordersChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reachedIt Closes Orders by itself
Indicators Used
Stochastic oscillatorFractals
Miscellaneous
It issuies visual alerts to the screen
9 Views
0 Downloads
0 Favorites
cloud's trade 2
#property copyright "cloud666@rbcmail.ru"
extern int Kperiod=            8;
extern int Dperiod=            8;
extern int Slowing=             4;
extern int Method=              3 ;
extern int PriceUsing=          1;
extern double MaxLot=         0.0;
extern double TakeProfit=   0.000;
extern double TrailingStop= 0.01;
extern double StopLoss=     0.05;
extern double MinProfit=   0.0000;
extern double ProfitPoints= 0.000;
extern int Condition1=          1;
extern int Condition2=          1;
extern double LotSpliter=     0.1;
extern int CloseByOtherSideCondition=1;
double Lot;
double PP=0;
double slu,sld,a,b;
double tp,sl;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   Alert("V2");
   tp=TakeProfit;
   sl=StopLoss;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
//   if(AccountServer()!="SIG-Demo.com"){return(0);}
   OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY);
   if(DayOfYear() == TimeDayOfYear(OrderCloseTime()))
   {
      return(0);
   }
   if(OrdersTotal()==0)
   {   
      PP=0;
      preinit();
      if(U()==1)
      {
         OrderBuy();
         return(0);
      }
      if(U()==2)
      {
         OrderSell();
         return(0);
      }
      return(0);
   }
   if(OrdersTotal()==1)
   {
      SelectOnlyOrder();
      slu=Bid-OrderOpenPrice();
      b=Bid;
      sld=OrderOpenPrice()-Ask;
      a=Ask;
      if(OrderType()==0)
      {
         if((slu)>PP)
         {
            PP=slu;
         }
         if(((slu)>0.001) && (OrderStopLoss()<(b-TrailingStop)) && (OrderOpenPrice()<(b-TrailingStop)) && (OrderProfit()>MathAbs(OrderSwap())))
         {
            if(TrailingStop!=0)
            {
               OrderModify(OrderTicket(), 0, b-TrailingStop, 0, 0, 0);
            }
         }
      }
      if(OrderType()==1)
      {
         if((sld)>PP)
         {
            PP=sld;
         }
         if(((sld)>0.001) && (OrderStopLoss()>(a+TrailingStop)) && (OrderOpenPrice()>(a+TrailingStop)))
         {
            if(TrailingStop!=0)
            {
               OrderModify(OrderTicket(), 0, a+TrailingStop, 0, 0, 0);
            }
         }
      }
      if(ProfitPoints!=0)
      {
         if(OrderType()==0 && PP>=ProfitPoints && (slu)<=MinProfit)
         {
            CloseOnlyOrder();
            return(0);
         }
         if(OrderType()==1 && PP>=ProfitPoints && (sld)<=MinProfit)
         {
            CloseOnlyOrder();
            return(0);
         }
      }
      if(CloseByOtherSideCondition==1)
      {
         if(OrderType()==0 && U()==2)
         {
            CloseOnlyOrder();
            return(0);
         }
         if(OrderType()==1 && U()==1)
         {
            CloseOnlyOrder();
            return(0);
         }
      }
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
int U()
{
   if((U1()==2 && Condition1==1) || (U2()==2 && Condition2==1)){return(2);}
   if((U1()==1 && Condition1==1) || (U2()==1 && Condition2==1)){return(1);}
   return(0);
}
int U1()
{
   if(iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_SIGNAL,1)>=80)
   {
      if(iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_SIGNAL,2)<=iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_MAIN,2))
      {
         if(iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_SIGNAL,1)>=iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_MAIN,1))
         {
            return(2);
         }
      }
   }
   if(iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_SIGNAL,1)<=20)
   {
      if(iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_SIGNAL,2)>=iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_MAIN,2))
      {
         if(iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_SIGNAL,1)<=iStochastic(Symbol(),Period(),Kperiod,Dperiod,Slowing,Method,PriceUsing,MODE_MAIN,1))
         {
            return(1);
         }
      }
   }
   return(0);
}
int U2()
{
   double fu=0,fd=0;
   int f=0,shift=2;
   while(f<2)
   {
      if(iFractals(Symbol(),Period(),MODE_UPPER,shift)>0)
      {
         fu=fu+1;
         f=f+1;
      }
      if(iFractals(Symbol(),Period(),MODE_LOWER,shift)>0)
      {
         fd=fd+1;
         f=f+1;
      }
      shift=shift+1;
   }
   if(fu==2){return(2);}
   if(fd==2){return(1);}
   return(0);
}
int preinit()
{
   Lot=NormalizeDouble(MathFloor(LotSpliter*AccountBalance()*AccountLeverage()/Ask/MathPow(10,Digits+1)*10)/10,1);
   if(MaxLot>0 && Lot>MaxLot){Lot=MaxLot;}
   if(Lot>MarketInfo(Symbol(),25)){Lot=MarketInfo(Symbol(),25);}
   return(0);
}
int OrderBuy()
{
   if(StopLoss!=0 && TakeProfit!=0)
   {
      OrderSend(Symbol(), 0, NormalizeDouble(Lot,1), Ask, 0, NormalizeDouble(Ask-StopLoss,4), NormalizeDouble(Ask+TakeProfit,4), 0, 0, 0, 0);
      return(0);
   }
   if(StopLoss==0 && TakeProfit!=0)
   {
      OrderSend(Symbol(), 0, NormalizeDouble(Lot,1), Ask, 0, 0, NormalizeDouble(Ask+TakeProfit,4), 0, 0, 0, 0);
      return(0);
   }
   if(StopLoss==0 && TakeProfit==0)
   {
      OrderSend(Symbol(), 0, NormalizeDouble(Lot,1), Ask, 0, 0, 0, 0, 0, 0, 0);
      return(0);
   }
   if(StopLoss!=0 && TakeProfit==0)
   {
      OrderSend(Symbol(), 0, NormalizeDouble(Lot,1), Ask, 0, NormalizeDouble(Ask-StopLoss,4), 0, 0, 0, 0, 0);
      return(0);
   }
   return(0);
}
int OrderSell()
{
   if(StopLoss!=0 && TakeProfit!=0)
   {
      OrderSend(Symbol(), 1, NormalizeDouble(Lot,1), Bid, 0, NormalizeDouble(Bid+StopLoss,4), NormalizeDouble(Bid-TakeProfit,4), 0, 0, 0, 0);
      return(0);
   }
   if(StopLoss==0 && TakeProfit!=0)
   {
      OrderSend(Symbol(), 1, NormalizeDouble(Lot,1), Bid, 0, 0, NormalizeDouble(Bid-TakeProfit,4), 0, 0, 0, 0);
      return(0);
   }
   if(StopLoss==0 && TakeProfit==0)
   {
      OrderSend(Symbol(), 1, NormalizeDouble(Lot,1), Bid, 0, 0, 0, 0, 0, 0, 0);
      return(0);
   }
   if(StopLoss!=0 && TakeProfit==0)
   {
      OrderSend(Symbol(), 1, NormalizeDouble(Lot,1), Bid, 0, NormalizeDouble(Bid+StopLoss,4), 0, 0, 0, 0, 0);
      return(0);
   }
   return(0);
}
int CloseOnlyOrder()
{
   SelectOnlyOrder();
   RefreshRates();
   if(OrderType()==0)
   {
      OrderClose(OrderTicket(), OrderLots(), Bid, 0, 0);
   }
   else if(OrderType()==0)
   {
      OrderClose(OrderTicket(), OrderLots(), Ask, 0, 0);
   }
   return(0);
}
int SelectOnlyOrder()
{
   OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
   return(0);
}

Profitability Reports

GBP/AUD Jul 2025 - Sep 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%
EUR/USD Jul 2025 - Sep 2025
0.15
Total Trades 8
Won Trades 3
Lost trades 5
Win Rate 37.50 %
Expected payoff -133.09
Gross Profit 180.80
Gross Loss -1245.50
Total Net Profit -1064.70
-100%
-50%
0%
50%
100%
AUD/USD Jul 2025 - Sep 2025
1.17
Total Trades 7
Won Trades 4
Lost trades 3
Win Rate 57.14 %
Expected payoff 6.43
Gross Profit 315.00
Gross Loss -270.00
Total Net Profit 45.00
-100%
-50%
0%
50%
100%
USD/JPY Jan 2025 - Jul 2025
0.85
Total Trades 128
Won Trades 69
Lost trades 59
Win Rate 53.91 %
Expected payoff -0.23
Gross Profit 168.95
Gross Loss -198.94
Total Net Profit -29.99
-100%
-50%
0%
50%
100%
USD/CHF Jan 2025 - Jul 2025
13.21
Total Trades 14
Won Trades 12
Lost trades 2
Win Rate 85.71 %
Expected payoff 182.25
Gross Profit 2760.53
Gross Loss -208.99
Total Net Profit 2551.54
-100%
-50%
0%
50%
100%
USD/CAD Jan 2025 - Jul 2025
9.74
Total Trades 20
Won Trades 18
Lost trades 2
Win Rate 90.00 %
Expected payoff 36.24
Gross Profit 807.61
Gross Loss -82.89
Total Net Profit 724.72
-100%
-50%
0%
50%
100%
NZD/USD Jan 2025 - Jul 2025
0.20
Total Trades 6
Won Trades 5
Lost trades 1
Win Rate 83.33 %
Expected payoff -184.95
Gross Profit 282.30
Gross Loss -1392.00
Total Net Profit -1109.70
-100%
-50%
0%
50%
100%
GBP/USD Jan 2025 - Jul 2025
0.17
Total Trades 9
Won Trades 5
Lost trades 4
Win Rate 55.56 %
Expected payoff -145.06
Gross Profit 266.00
Gross Loss -1571.50
Total Net Profit -1305.50
-100%
-50%
0%
50%
100%
GBP/CAD Jan 2025 - Jul 2025
0.60
Total Trades 19
Won Trades 12
Lost trades 7
Win Rate 63.16 %
Expected payoff -26.46
Gross Profit 769.39
Gross Loss -1272.04
Total Net Profit -502.65
-100%
-50%
0%
50%
100%
GBP/AUD Jan 2025 - Jul 2025
0.14
Total Trades 7
Won Trades 3
Lost trades 4
Win Rate 42.86 %
Expected payoff -50.30
Gross Profit 55.02
Gross Loss -407.09
Total Net Profit -352.07
-100%
-50%
0%
50%
100%

Comments