stoch power EA_5e

Author: Copyright � 2007, AZAM575&SYLARVAMPIRE&YUSOF786

Okay, here's an explanation of what the provided MetaTrader script does, focusing on the logic of the script in plain language, without getting into programming jargon or suggesting improvements:

Overall Purpose:

This script is designed to automatically trade on the Forex market using the MetaTrader platform. It's built to open and manage trades based on signals from a technical indicator called the Stochastic Oscillator and other settings that you, the user, can customize. It aims to automate a trading strategy, opening multiple orders and managing risk.

Core Components and How They Work:

  1. Customizable Settings (External Variables):

    • The script starts with a long list of settings that you can change. These control almost every aspect of how the script operates. Examples include:
      • Stochastic Settings: How the Stochastic Oscillator is calculated (periods, levels, moving average type). This indicator is at the heart of deciding when to buy or sell.
      • Trade Settings: The size of the initial trades (Lots), the target profit for each trade (TakeProfit), how far apart to space multiple trades (Pips), and how much loss to tolerate (StopLoss).
      • Money Management: Whether to increase the size of subsequent trades if the strategy is working (multiply), and whether to adjust trade size based on your account balance (Money Management settings).
      • Account Protection: Settings to protect your account balance, by closing all trades if your balance goes below a certain value.
      • Trading Time: Settings to decide during which hours of the day should trades be opened.
  2. Initialization (init() function):

    • This part runs once when you first attach the script to a chart. In this particular script, it's mostly empty, meaning it doesn't do much when it starts up.
  3. Deinitialization (deinit() function):

    • This part runs once when you remove the script from a chart or close MetaTrader. It's designed to clean up anything the script created, in this case, deleting any graphical objects (arrows, lines) that the script might have drawn on the chart.
  4. The Main Loop (start() function):

    • This is the heart of the script, and it runs repeatedly, checking market conditions and making decisions. Here's a breakdown:

      • Trading Hour Check:

        • The script first checks if it's allowed to trade based on the time of day and the trading time settings you've chosen. It checks if the time is within a period allowed to trade on the Asian, European, or New York markets. It won't open new trades if it's outside those hours.
      • Lot Size Calculation:

        • It determines the appropriate trade size (Lots) based on your settings. This could be a fixed lot size, or a lot size calculated based on your account balance and risk settings.
      • Order Counting:

        • It counts how many open trades the script currently has for the specific currency pair it's attached to. It distinguishes between Market Orders (trades that are immediately executed) and Limit Orders (trades that will be executed when the price reaches a certain level)
        • It only considers trades that were opened by this specific script (identified by the Magic Number).
      • Friday Trading Check:

        • There's an option to prevent the script from opening new trades on Fridays.
      • Account Protection Checks:

        • The script checks if certain account protection rules have been triggered. These rules are designed to prevent large losses. Examples:
          • Money Protection: If losses reach a certain amount, it will close all trades and stop trading.
          • Equity Protection: If the account's equity (balance minus losses) falls below a certain percentage of the initial balance, it will close all trades.
          • SecureProfit Protection: After a certain number of trades are open, if the total profit reaches a set target, it will close all trades.
          • Orders Time Alive protection: If an order has been opened for a certain amount of time, it will close all trades
      • Closing Orders (If Needed):

        • If any of the account protection rules are triggered, or if it's Friday and trading on Friday is disabled, the script will attempt to close all open trades and stop opening new ones.
      • Maximum Trades Check:

        • It checks if the maximum number of allowed trades has been reached. If so, it stops opening new trades.
      • Stochastic Oscillator Calculation:

        • The script uses the Stochastic Oscillator indicator to generate buy or sell signals.
        • The script checks if the current value of the Stochastic Oscillator is above or below certain levels (H_level and L_level).
        • Based on these levels, it decides whether to consider opening a buy or sell trade.
      • Buy/Sell Decision:

        • Based on the Stochastic Oscillator and whether there are already open trades, the script decides whether to open a buy or sell order. If the user decides to reverse the buy/sell signals, the reverse condition gets applied here.
      • Trailing Stop (Order Modification):

        • If a trade is already open and the price moves favorably, the script will adjust the Stop Loss to "trail" the price. This helps to lock in profits.
      • Opening New Orders:

        • If the script decides to open a new trade, it will send an order to the MetaTrader platform to either:
          • Open a market order (execute the trade immediately at the current price).
          • Open a limit order (place an order to be executed when the price reaches a specific level).
  5. Other functions

    • OpenMarketOrders(): Opens Buy/Sell Market orders based on parameters
    • OpenLimitOrders(): Opens Buy/Sell Limit orders based on parameters
    • DeleteAllObjects(): Cleans all objects from the chart
    • OpenOrdersBasedOnSTOCH(): Calculates Buy/Sell signal based on STOCH conditions

In Simple Terms:

Imagine this script as a robot trader that you can customize with lots of different settings. It watches the market, specifically the Stochastic Oscillator, and based on that indicator, it decides whether to buy or sell. It manages the trades by setting profit targets and stop-loss levels. It also has safety features to protect your account from large losses and settings to define when to trade or not according to different hours of the day. You control how aggressive or conservative the robot is through the settings.

Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
Stochastic oscillator
4 Views
0 Downloads
0 Favorites

Profitability Reports

NZD/USD Oct 2024 - Jan 2025
553.00 %
Total Trades 6
Won Trades 4
Lost trades 2
Win Rate 66.67 %
Expected payoff 4.98
Gross Profit 36.50
Gross Loss -6.60
Total Net Profit 29.90
-100%
-50%
0%
50%
100%
AUD/USD Oct 2024 - Jan 2025
242.00 %
Total Trades 31
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff 11.33
Gross Profit 598.20
Gross Loss -247.10
Total Net Profit 351.10
-100%
-50%
0%
50%
100%
stoch power EA_5e
//+-----------------------------------------------------------------------------------+
//|                                                              STOCH POWER EA 5.mq4 |
//|                                               Copyright © 2005, Alejandro Galindo |
//|                                                               http://elCactus.com |
//|                               Copyright © 2007, AZAM575 & SYLARVAMPIRE & YUSOF786 |
//|                                                                 http://mymefx.com |
//+-----------------------------------------------------------------------------------+

///Please, do not sell this EA because its FREE

#property copyright "Copyright © 2007, AZAM575&SYLARVAMPIRE&YUSOF786"
#property link      "MYMEFX.COM"

extern string  INFO="STOCH POWER EA V5.0";
extern string  OWN="Copyright © 2007, AZAM575&SYLARVAMPIRE&YUSOF786";
extern string  sq="--STOCH SETTING--";
extern int    K_Period = 14;
extern int    D_Period = 3;
extern int    Slow_Period = 3;
extern int    Stoch_TF = 60;
extern int    H_level =97;
extern int    L_level =3;
extern string  ChooseLineMode="Choose 1=mode main, 2=mode signal";
extern int    stochlinemode = 1;
extern string  ChooseeMAMode="Choose 1=mode SMA, 2=mode LWMA, 3=mode EMA";
extern int    stochMAmode = 1;
extern bool ExitWithSTOCH=False;
extern string  sb="--TRADE SETTING--";
extern double Lots = 0.1;       // We start with this lots number
extern int    TakeProfit = 32;  // Profit Goal for the latest order opened
extern bool MyMoneyProfitTarget=False;
extern double My_Money_Profit_Target=50;
extern double multiply=2.0; 
extern int MaxTrades=15;        // Maximum number of orders to open
extern int Pips=22;             // Distance in Pips from one order to another
extern int    StopLoss = 0;  // StopLoss
extern int    TrailingStop = 0;// Pips to trail the StopLoss
extern string  MM="--MOney Management--"; // (from order 2, not from first order
extern string  MMSwicth="if one the lots size will increase based on account size";
extern int mm=0;                // if one the lots size will increase based on account size
extern string  riskset="risk to calculate the lots size (only if mm is enabled)";
extern int risk=1;             // risk to calculate the lots size (only if mm is enabled)
extern string accounttypes="0 if Normal Lots, 1 for mini lots, 2 for micro lots";
extern int AccountType=1;  // 0 if Normal Lots, 1 for mini lots, 2 for micro lots
extern string  magicnumber="--MAgic No--";
extern int MagicNumber=222777;  // Magic number for the orders placed
extern string  so="--CUTLOSS SETTING--";
extern bool SecureProfitProtection=False;
extern string  SP="If profit made is bigger than SecureProfit we close the orders";
extern int SecureProfit=20;     // If profit made is bigger than SecureProfit we close the orders
extern string  OTP="Number of orders to enable the account protection";
extern int OrderstoProtect=3;   // Number of orders to enable the account protection
extern string  ASP="if one will check profit from all symbols, if cero only this symbol";
extern bool AllSymbolsProtect=False; // if one will check profit from all symbols, if cero only this symbol
extern string  EP="if true, then the expert will protect the account equity to the percent specified";
extern bool EquityProtection=False;  // if true, then the expert will protect the account equity to the percent specified
extern string  AEP="percent of the account to protect on a set of trades";
extern int AccountEquityPercentProtection=90; // percent of the account to protect on a set of trades
extern string  AMP="if true, then the expert will use money protection to the USD specified";
extern bool AccountMoneyProtection=False;
extern double AccountMoneyProtectionValue=3000.00;
string  s1="--seting berapa jam dia nak open order--";
bool UseHourTrade = False;
int FromHourTrade = 0;
int ToHourTrade = 1;

extern string  TradingTime="--trading time setting--";
extern bool    UseTradingHours = false;
extern bool    TradeAsianMarket = true;
extern int     StartHour1 = 0;       // Start trades after time
extern int     StopHour1 = 3;      // Stop trading after time
extern bool    TradeEuropeanMarket = true;
extern int     StartHour2 = 9;       // Start trades after time
extern int     StopHour2 = 11;      // Stop trading after time
extern bool    TradeNewYorkMarket = false;
extern int     StartHour3 = 15;       // Start trades after time
extern int     StopHour3 = 17;      // Stop trading after time
extern bool TradeOnFriday=False;
extern string  OtherSetting="--Others Setting--";
int OrdersTimeAlive=0;  // in seconds
extern string  reverse="if one the desition to go long/short will be reversed";
extern bool ReverseCondition=False;  // if one the desition to go long/short will be reversed
extern string  limitorder="if true, instead open market orders it will open limit orders ";
extern bool SetLimitOrders=False; // if true, instead open market orders it will open limit orders 
int Manual=0;            // If set to one then it will not open trades automatically
color ArrowsColor=Black;       // color for the orders arrows


int OpenOrdersBasedOn=16; // Method to decide if we start long or short
bool ContinueOpening=True;

int  OpenOrders=0, cnt=0;
int MarketOpenOrders=0, LimitOpenOrders=0;
int  slippage=5;
double sl=0, tp=0;
double BuyPrice=0, SellPrice=0;
double lotsi=0, mylotsi=0;
int mode=0, myOrderType=0, myOrderTypetmp=0;

double LastPrice=0;
int  PreviousOpenOrders=0;
double Profit=0;
int LastTicket=0, LastType=0;
double LastClosePrice=0, LastLots=0;
double Pivot=0;
double PipValue=0;
bool Reversed=False;
double tmp=0;
double iTmpH=0;
double iTmpL=0;
datetime NonTradingTime[][2];
bool FileReaded=false;
string dateLimit = "2030.01.12 23:00";
int CurTimeOpeningFlag=0;
datetime LastOrderOpenTime=0;
bool YesStop;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   DeleteAllObjects();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- 
   int cnt=0;
   bool result;   
   string text="";
   string version="VERSI INI DAH EXPIRED...SILA YM xxul_gunturean utk penggantian";
   
  // skrip masa trading
    if (UseTradingHours)
   {

     YesStop = true;
// Check trading Asian Market
     if (TradeAsianMarket)
     {
        if (StartHour1 > 18)
        {
// Check broker that uses Asian open before 0:00

          if (Hour() >= StartHour1) YesStop = false;
          if (!YesStop)
          {
            if (StopHour1 < 24)
            {
              if ( Hour() <= StopHour1) YesStop = false;
            }
// These cannot be combined even though the code looks the same
            if (StopHour1 >=0)
            {
              if ( Hour() <= StopHour1) YesStop = false;
            }
          }
        }
        else
        {
          if (Hour() >= StartHour1 && Hour() <= StopHour1) YesStop = false;
        }
     }
     if (YesStop)
     {
// Check trading European Market
       if (TradeEuropeanMarket)
       {
         if (Hour() >= StartHour2 && Hour() <= StopHour2) YesStop = false;
       }
     }
     if (YesStop)
     {
// Check trading European Market
       if (TradeNewYorkMarket)
       {
         if (Hour() >= StartHour3 && Hour() <= StopHour3) YesStop = false;
       }
     }
     if (YesStop)
     {
//      Comment ("Trading has been stopped as requested - wrong time of day");
       return (0);
      }
   }
   
   // skrip masa trading
   
   if (AccountType==0)
   {
	 if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000); }
	 else { lotsi=Lots; }
   } 
   
   if (AccountType==1)
   {  // then is mini
    if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000)/10; }
	 else { lotsi=Lots; }
   }
   
   if (AccountType==2)
   {
    if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000)/100; }
    else { lotsi=Lots; }
   }

   if (lotsi<0.01) lotsi=0.01;
   if (lotsi>100) lotsi=100; 
   
   OpenOrders=0;
   MarketOpenOrders=0;
   LimitOpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
     {
	   if (OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber)
	   {				
	  	  if (OrderType()==OP_BUY || OrderType()==OP_SELL) 
	  	  {
	  	   MarketOpenOrders++;
	  	   LastOrderOpenTime=OrderOpenTime();
	  	  }
	  	  if (OrderType()==OP_SELLLIMIT || OrderType()==OP_BUYLIMIT) LimitOpenOrders++;
	  	  OpenOrders++;
	   }
	  }
   }  
   
   if (OpenOrders<1) 
   {
	  if (!TradeOnFriday && DayOfWeek()==5) 
	  {
	    Comment("TradeOnfriday is False");
	    return(0);
	  }
   }
   
   PipValue=MarketInfo(Symbol(),MODE_TICKVALUE); 
   
   if (PipValue==0) { PipValue=5; }
  
   if (AccountMoneyProtection && AccountBalance()-AccountEquity()>=AccountMoneyProtectionValue)
   {
    text = text + "\nClosing all orders and stop trading because account money protection activated..";
    Print("Closing all orders and stop trading because account money protection activated.. Balance: ",AccountBalance()," Equity: ",AccountEquity());
    PreviousOpenOrders=OpenOrders+1;
    ContinueOpening=False;
    return(0);
   }
   
   ////aku masukkan time
   if (UseHourTrade){
      if (!(Hour()>=FromHourTrade && Hour()<=ToHourTrade)) {
    text = text + "\nORDER TELAH DI TUTUP KERANA MASA DAH TAMAT.";
    Print("ORDER TELAH DI TUTUP KERANA MASA TAMAT. UNTUNG: ",AccountProfit()," EKUITI: ",AccountEquity());
    PreviousOpenOrders=OpenOrders+1;
    ContinueOpening=False;
    return(0);
   }
}
   //set my profit for one Day
   if (MyMoneyProfitTarget && AccountProfit()>= My_Money_Profit_Target)
   {
    text = text + "\nClosing all orders and stop trading because mymoney profit target reached..";
    Print("Closing all orders and stop trading because mymoney profit target reached.. Profit: ",AccountProfit()," Equity: ",AccountEquity());
    PreviousOpenOrders=OpenOrders+1;
    ContinueOpening=False;
    return(0);
   }
   // Account equity protection 
   if (EquityProtection && AccountEquity()<=AccountBalance()*AccountEquityPercentProtection/100) 
	 {
	 text = text + "\nClosing all orders and stop trading because account money protection activated.";
	 Print("Closing all orders and stop trading because account money protection activated. Balance: ",AccountBalance()," Equity: ", AccountEquity());
	 //Comment("Closing orders because account equity protection was triggered. Balance: ",AccountBalance()," Equity: ", AccountEquity());
	 //OrderClose(LastTicket,LastLots,LastClosePrice,slippage,Orange);		 
	 PreviousOpenOrders=OpenOrders+1;
	 ContinueOpening=False;
	 return(0);
   }
     
   // if dont trade at fridays then we close all
   if (!TradeOnFriday && DayOfWeek()==5)
   {
    PreviousOpenOrders=OpenOrders+1;
    ContinueOpening=False;
    text = text +"\nClosing all orders and stop trading because TradeOnFriday protection.";
    Print("Closing all orders and stop trading because TradeOnFriday protection.");
   }
   
   // Orders Time alive protection
   if (OrdersTimeAlive>0 && CurTime() - LastOrderOpenTime>OrdersTimeAlive)
   {
    PreviousOpenOrders=OpenOrders+1;
    ContinueOpening=False;
    text = text + "\nClosing all orders because OrdersTimeAlive protection.";
    Print("Closing all orders because OrdersTimeAlive protection.");
   }
   
   if (PreviousOpenOrders>OpenOrders) 
   {	  
	  for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
	  {
	     if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
	     {
	  	   mode=OrderType();
		   if ((OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) || AllSymbolsProtect) 
		   {
		 	 if (mode==OP_BUY || mode==OP_SELL)
		 	 { 
		 	  OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,ArrowsColor);
	 		  return(0);
	 		 }
		  }
		 }
	  }
	  for(cnt=0;cnt<OrdersTotal();cnt++)
	  {
	     if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
	     {
	  	   mode=OrderType();
		   if ((OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) || AllSymbolsProtect) 
		   {
		 	 if (mode==OP_SELLLIMIT || mode==OP_BUYLIMIT || mode==OP_BUYSTOP || mode==OP_SELLSTOP)
		 	 {
			  OrderDelete(OrderTicket());
	 		  return(0);
	 		 }
		  }
		 }
	  }
   }
   PreviousOpenOrders=OpenOrders;
      
   if (OpenOrders>=MaxTrades) 
   {
	  ContinueOpening=False;
   } else {
	  ContinueOpening=True;
   }

   if (LastPrice==0) 
   {
	  for(cnt=0;cnt<OrdersTotal();cnt++)
	  {	
	    if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
	    {
		  mode=OrderType();	
		  if (OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber) 
		  {
			LastPrice=OrderOpenPrice();
			if (mode==OP_BUY) { myOrderType=2; }
			if (mode==OP_SELL) { myOrderType=1;	}
		  }
		 }
	  }
   }

   // SecureProfit protection
  //if (SecureProfitProtection && MarketOpenOrders>=(MaxTrades-OrderstoProtect)
  // Modified to make easy to understand 
  if (SecureProfitProtection && MarketOpenOrders>=OrderstoProtect) 
   {
	  Profit=0;
     for(cnt=0;cnt<OrdersTotal();cnt++)
     {
      if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))
      {
       if ((OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) || AllSymbolsProtect)
        Profit=Profit+OrderProfit();         
      }
     }	    
	  if (Profit>=SecureProfit) 
	  {
	     text = text + "\nClosing orders because account protection with SecureProfit was triggered.";
	     Print("Closing orders because account protection with SeureProfit was triggered. Balance: ",AccountBalance()," Equity: ", AccountEquity()," Profit: ",Profit);
	     PreviousOpenOrders=OpenOrders+1;
		  ContinueOpening=False;
		  return(0);
	  }
   }

  myOrderTypetmp=3;
  switch (OpenOrdersBasedOn)
  {  
     case 16:
       myOrderTypetmp=OpenOrdersBasedOnSTOCH();
       break; 	
     default: 
        myOrderTypetmp=OpenOrdersBasedOnSTOCH();
        break;
  }
  
  


   if (OpenOrders<1 && Manual==0) 
   {
     myOrderType=myOrderTypetmp;
	  if (ReverseCondition)
	  {
	  	  if (myOrderType==1) { myOrderType=2; }
		  else { if (myOrderType==2) { myOrderType=1; } }
	  }
   }   
   if (ReverseCondition)
   {
    if (myOrderTypetmp==1) { myOrderTypetmp=2; }
    else { if (myOrderTypetmp==2) { myOrderTypetmp=1; } }
   }
   
   // if we have opened positions we take care of them
   cnt=OrdersTotal()-1;
   while(cnt>=0)
   {
     if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==false)        break;
	  if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) // && Reversed==False) 
	  {
        //Print("Ticket ",OrderTicket()," modified.");	     
	  	  if (OrderType()==OP_SELL) 
	  	  {		
	  	     if (ExitWithSTOCH&& myOrderTypetmp==2)
           {
             PreviousOpenOrders=OpenOrders+1;
             ContinueOpening=False;
             text = text +"\nClosing all orders because Indicator triggered another signal.";
             Print("Closing all orders because Indicator triggered another signal."); 
             //return(0);
           }
	  	  	  if (TrailingStop>0) 
			  {
				  if ((OrderOpenPrice()-OrderClosePrice())>=(TrailingStop*Point+Pips*Point)) 
				  {						
					 if (OrderStopLoss()>(OrderClosePrice()+TrailingStop*Point))
					 {										    
					    result=OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()+TrailingStop*Point,OrderClosePrice()-TakeProfit*Point-TrailingStop*Point,0,Purple);
					    if(result!=TRUE) Print("LastError = ", GetLastError());
                   else OrderPrint();
	  					 return(0);	  					
	  				 }
	  			  }
			  }
	  	  }
   
	  	  if (OrderType()==OP_BUY)
	  	  {
	  	     if (ExitWithSTOCH && myOrderTypetmp==1)
           {
             PreviousOpenOrders=OpenOrders+1;
             ContinueOpening=False;
             text = text +"\nClosing all orders because Indicator triggered another signal.";
             Print("Closing all orders because Indicator triggered another signal."); 
             //return(0);
           }
	  		 if (TrailingStop>0) 
	  		 {
			   if ((OrderClosePrice()-OrderOpenPrice())>=(TrailingStop*Point+Pips*Point)) 
				{
					if (OrderStopLoss()<(OrderClosePrice()-TrailingStop*Point)) 
					{					   
					   result=OrderModify(OrderTicket(),OrderOpenPrice(),OrderClosePrice()-TrailingStop*Point,OrderClosePrice()+TakeProfit*Point+TrailingStop*Point,0,ArrowsColor);		
					   if(result!=TRUE) Print("LastError = ", GetLastError());                  
                  else OrderPrint();
                  return(0);
					}
  				}
			 }
	  	  }
   	}
      cnt--;
   }   

      if (!IsTesting()) 
      {
	     if (myOrderType==3 && OpenOrders<1) { text=text + "\nTIADA KONDISI UTK OPEN ORDER"; }
	     //else { text= text + "\n                         "; }
	     Comment("HARGA TERAKHIR=",LastPrice," OPEN ODER YG LEPAS=",PreviousOpenOrders,"\nBUKA LAGI=",ContinueOpening," JENISORDER=",myOrderType,"\nLOT=",lotsi,text);
      }

      if (OpenOrders<1)
         OpenMarketOrders();
      else
         if (SetLimitOrders) OpenLimitOrders();
         else OpenMarketOrders();

//----
   return(0);
  }
//+------------------------------------------------------------------+


void OpenMarketOrders()
{         
   int cnt=0;      
      if (myOrderType==1 && ContinueOpening) 
      {	      
	     if ((Bid-LastPrice)>=Pips*Point || OpenOrders<1) 
	     {	     		
		    SellPrice=Bid;				
		    LastPrice=0;
		    if (TakeProfit==0) { tp=0; }
		    else { tp=SellPrice-TakeProfit*Point; }	
		    if (StopLoss==0) { sl=0; }
		    else { sl=SellPrice+StopLoss*Point;  }
		    if (OpenOrders!=0) 
		    {
			      mylotsi=lotsi;			
			      for(cnt=0;cnt<OpenOrders;cnt++)
			      {
				     if (MaxTrades>12) { mylotsi=NormalizeDouble(mylotsi*multiply,2); }
				     else { mylotsi=NormalizeDouble(mylotsi*multiply,2); }
			      }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }			    
		    OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,slippage,sl,tp,"MyMEFx EA"+MagicNumber,MagicNumber,0,ArrowsColor);		    		    
		    return(0);
	     }
	     
	  //   Sleep(6000);   ////aku letak
        //      RefreshRates(); 
      }
      
      if (myOrderType==2 && ContinueOpening) 
      {
	     if ((LastPrice-Ask)>=Pips*Point || OpenOrders<1) 
	     {			      
		    BuyPrice=Ask;
		    LastPrice=0;
		    if (TakeProfit==0) { tp=0; }
		    else { tp=BuyPrice+TakeProfit*Point; }	
		    if (StopLoss==0)  { sl=0; }
		    else { sl=BuyPrice-StopLoss*Point; }
		    if (OpenOrders!=0) {
			   mylotsi=lotsi;			
			   for(cnt=0;cnt<OpenOrders;cnt++)
			   {
				  if (MaxTrades>12) { mylotsi=NormalizeDouble(mylotsi*multiply,2); }
				  else { mylotsi=NormalizeDouble(mylotsi*multiply,2); }
			   }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    OrderSend(Symbol(),OP_BUY,mylotsi,BuyPrice,slippage,sl,tp,"MyMEFx EA"+MagicNumber,MagicNumber,0,ArrowsColor);		    
		    return(0);
	     }
      }   
}

void OpenLimitOrders()
{
   int cnt=0;
               
      if (myOrderType==1 && ContinueOpening) 
      {	
	     //if ((Bid-LastPrice)>=Pips*Point || OpenOrders<1) 
	     //{		
		    //SellPrice=Bid;				
		    SellPrice = LastPrice+Pips*Point;
		    LastPrice=0;
		    if (TakeProfit==0) { tp=0; }
		    else { tp=SellPrice-TakeProfit*Point; }	
		    if (StopLoss==0) { sl=0; }
		    else { sl=SellPrice+StopLoss*Point;  }
		    if (OpenOrders!=0) 
		    {
			      mylotsi=lotsi;			
			      for(cnt=0;cnt<OpenOrders;cnt++)
			      {
				     if (MaxTrades>12) { mylotsi=NormalizeDouble(mylotsi*multiply,2); }
				     else { mylotsi=NormalizeDouble(mylotsi*multiply,2); }
			      }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    OrderSend(Symbol(),OP_SELLLIMIT,mylotsi,SellPrice,slippage,sl,tp,"MyMEFx EA"+MagicNumber,MagicNumber,0,ArrowsColor);		    		    
		    return(0);
	     //}
      }
      
      if (myOrderType==2 && ContinueOpening) 
      {
	     //if ((LastPrice-Ask)>=Pips*Point || OpenOrders<1) 
	     //{		
		    //BuyPrice=Ask;
		    BuyPrice=LastPrice-Pips*Point;
		    LastPrice=0;
		    if (TakeProfit==0) { tp=0; }
		    else { tp=BuyPrice+TakeProfit*Point; }	
		    if (StopLoss==0)  { sl=0; }
		    else { sl=BuyPrice-StopLoss*Point; }
		    if (OpenOrders!=0) {
			   mylotsi=lotsi;			
			   for(cnt=0;cnt<OpenOrders;cnt++)
			   {
				  if (MaxTrades>12) { mylotsi=NormalizeDouble(mylotsi*multiply,2); }
				  else { mylotsi=NormalizeDouble(mylotsi*multiply,2); }
			   }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    OrderSend(Symbol(),OP_BUYLIMIT,mylotsi,BuyPrice,slippage,sl,tp,"MyMEFx EA"+MagicNumber,MagicNumber,0,ArrowsColor);		    
		    return(0);
	     //}
      }   

}

void DeleteAllObjects()
{
 int    obj_total=ObjectsTotal();
 string name;
 for(int i=0;i<obj_total;i++)
 {
  name=ObjectName(i);
  if (name!="")
   ObjectDelete(name);
 }
 ObjectDelete("FLP_txt");
 ObjectDelete("P_txt");
}

// 16
int OpenOrdersBasedOnSTOCH()
{
 int myOrderType=3;
 double modest;
  switch (stochlinemode)
  {  
     case 1:
       modest=MODE_MAIN;
       break; 	
     case 2:
       modest=MODE_SIGNAL;
       break; 
     default: 
        modest=MODE_MAIN;
        break;
  }
  
 double mamode;
  switch (stochMAmode)
  {  
     case 1:
       modest=MODE_SMA;
       break; 	
     case 2:
       modest=MODE_LWMA;
       break; 
            case 3:
       modest=MODE_EMA;
       break; 
     default: 
        modest=MODE_SMA;
        break;
  }
   //double  previousstoch, currentstoch, signalstoch;
  // double  stochk0,stochd0, stochk1,stochd1;
   //---- long Stochastic indicator
  // signalstoch   = iStochastic (NULL,Stoch_TF,K_Period,D_Period,Slow_Period,mamode,0,MODE_SIGNAL,1);
   //currentstoch  = iStochastic(NULL,Stoch_TF,K_Period,D_Period,Slow_Period,mamode,0,modest,1);
   //previousstoch = iStochastic(NULL,Stoch_TF,K_Period,D_Period,Slow_Period,mamode,0,modest,2);
   
  double stochk0 = iStochastic(Symbol(),Stoch_TF,K_Period,D_Period,Slow_Period,mamode, 0, MODE_MAIN, 0);
  double stochd0 = iStochastic(Symbol(),Stoch_TF,K_Period,D_Period,Slow_Period,mamode, 0, MODE_SIGNAL, 0);
  double stochk1 = iStochastic(Symbol(), Stoch_TF,K_Period,D_Period,Slow_Period,mamode, 0, MODE_MAIN, 1);
  double stochd1 = iStochastic(Symbol(), Stoch_TF,K_Period,D_Period,Slow_Period,mamode, 0, MODE_SIGNAL, 1);
 //---- lot setting and modifications
//Sell order
        //  if(previousstoch>H_level && currentstoch<H_level)
         //if(previousstoch>currentstoch && currentstoch > H_level)  
         //if(previousstoch>H_level && previousstoch>currentstoch && currentstoch<H_level)
         if (stochk1 <= stochd1 && stochk0 > stochd0 && stochd0<=L_level)
         //if(previousstoch>H_level && signalstoch > currentstoch)
 {
  myOrderType=1;
 }
  
//buy order
         // if(previousstoch<L_level && currentstoch>L_level)
  //if(previousstoch<currentstoch && currentstoch < L_level)
    //if(previousstoch<L_level && previousstoch<currentstoch && currentstoch>L_level)
    if(stochk1 >= stochd1 && stochk0 < stochd0 && stochd0>=H_level)
            // if(previousstoch<L_level && signalstoch < currentstoch)
    
 {
  myOrderType=2;
 }

 return(myOrderType);
}

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