GoblinFibo1.2.A

Author: Copyright � 2005, Alejandro Galindo
Price Data Components
Series array that contains open time of each bar
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
Miscellaneous
It issuies visual alerts to the screen
0 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
43.00 %
Total Trades 1033
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -7.27
Gross Profit 5761.00
Gross Loss -13271.90
Total Net Profit -7510.90
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
33.00 %
Total Trades 362
Won Trades 158
Lost trades 204
Win Rate 0.44 %
Expected payoff -12.84
Gross Profit 2300.80
Gross Loss -6950.00
Total Net Profit -4649.20
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
23.00 %
Total Trades 197
Won Trades 80
Lost trades 117
Win Rate 0.41 %
Expected payoff -18.43
Gross Profit 1106.50
Gross Loss -4737.20
Total Net Profit -3630.70
-100%
-50%
0%
50%
100%
GoblinFibo1.2.A
//+-----------------------------------------------------------------------+
//| Goblin.mq4 Rel.2                                                 |
//| Original 10Point 3.mq4 Copyright © 2005, Alejandro Galindo            |
//| http://elCactus.com                                                   |
//|                                                                       |
//| Modified ver. of 10points 3_dynamic_stop to provide multiple options  |
//| for better trend detection using customized Jurik based indicators.   |
//|                                                                       |
//| bluto @ www.forex-tsd.com; 11/22/2006                                 |
//+-----------------------------------------------------------------------+

#property copyright "Copyright © 2005, Alejandro Galindo"
#property link      "http://elCactus.com"

extern double    TakeProfit = 32;           // Profit Goal for the latest order opened
extern double    Lots = 0.1;                // First order will be for this lot size
extern double    InitialStop = 1;           // StopLoss
extern double    TrailingStop = 17;         // Pips to trail the StopLoss

extern bool      FiboProgression=True;      // Set True for Fibonacci sequence instead of Martingale for lot increases -Tross
extern int       MaxTrades=13;              // Maximum number of orders to open
extern int       Pips=18;                   // Distance in Pips from one order to another
extern int       SecureProfit=10;           // If profit made is bigger than SecureProfit we close the orders
extern int       AccountProtection=0;       // If one the account protection will be enabled, 0 is disabled
extern int       OrderstoProtect=0;         // This number subtracted from MaxTrades is the number of open orders to enable the account protection.
                                            // Example: (MaxTrades=10) minus (OrderstoProtect=3)=7 orders need to be open before account protection is enabled.
                                            
extern double    EquityProtectionLevel;     // Min. equity to preserve in the event things go bad; all orders for Symbol/Magic will be closed.
extern double    MaxLossPerOrder;           // Max. loss tolerance per order; once reached, order will be closed. 
                                  
extern int       ReverseCondition=0;        // If one the decision to go long/short will be reversed
extern int       StartYear=2005;            // Year to start (only for backtest)
extern int       StartMonth=1;              // Month to start (only for backtest)
extern int       EndYear=2050;              // Year to stop trading (backtest and live)
extern int       EndMonth=12;               // Month to stop trading (backtest and live)
// extern int    EndHour=22;                // Not used for now
// extern int    EndMinute=30;              // Not used for now
extern int       mm=0;                      // if 1, the lots size will increase based on account size
extern int       risk=12;                   // risk to calculate the lots size (only if mm is enabled)
extern int       AccountisNormal=0;         // Zero if account is not mini/micro                            
extern int       Magic = 123987;            // Magic number for the orders placed

                                
int              OpenOrders=0, cnt=0;
int              slippage=5;
double           sl=0, tp=0;
double           BuyPrice=0, SellPrice=0;
double           lotsi=0, mylotsi=0;
int              mode=0, myOrderType=0;
bool             ContinueOpening=True;
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;
string           text="", text2="";
double           DnTrendVal=0,UpTrendVal=0,TrendVal=0;
string           TrendTxt="analyzing...";
int              RSX_Period=17;
int              trendtype=0;
bool             AllowTrading=true;


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//---- 

   if (AllowTrading==false) {return(0);}
   
   if (AccountisNormal==1)
   {
	  if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000); }
		else { lotsi=Lots; }
   } else {  // then is mini
    if (mm!=0) { lotsi=MathCeil(AccountBalance()*risk/10000)/10; }
		else { lotsi=Lots; }
   }
   
// Added optional provision to specify maximum loss per order; primordial risk management at it's finest. 
   
   
   if (MathAbs(MaxLossPerOrder) > 0)
    {
     for(cnt=OrdersTotal();cnt>=0;cnt--) 
      {
       RefreshRates();
       OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
       if (OrderSymbol() == Symbol())
        {
         if (OrderType() == OP_BUY && OrderMagicNumber() == Magic && OrderProfit() <=  MathAbs(MaxLossPerOrder) * (-1)) { OrderClose(OrderTicket(),OrderLots(),Bid,slippage,White); }
         if (OrderType() == OP_SELL && OrderMagicNumber() == Magic && OrderProfit() <= MathAbs(MaxLossPerOrder) * (-1)) { OrderClose(OrderTicket(),OrderLots(),Ask,slippage,White); }
        }
      }
    }

// Added Minimum Equity Level to protect to protect from being wiped out in the event things really get wicked...more elegant risk control stuff.
      
   if(EquityProtectionLevel > 0 && AccountEquity() <= EquityProtectionLevel)
     {
      AllowTrading = false;
      Print("Min. Equity Level Reached - Trading Halted For ",Symbol());
      Alert("Min. Equity Level Reached - Trading Halted For ",Symbol());
      for(cnt=OrdersTotal();cnt>=0;cnt--)
       {
	     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  	  mode=OrderType();
		  if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) 
		   {
		    if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue); }
			 if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red); }
			 return(0);
		   }
	    }
     }      

   if (lotsi>100){ lotsi=100; }
   
   OpenOrders=0;
   for(cnt=0;cnt<OrdersTotal();cnt++)   
   {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic)
	  {				
	  	  OpenOrders++;
	  }
   }     
   
   if (OpenOrders<1) 
   {
	  if (TimeYear(CurTime())<StartYear) { return(0);  }
	  if (TimeMonth(CurTime())<StartMonth) { return(0); }
	  if (TimeYear(CurTime())>EndYear) { return(0); }
	  if (TimeMonth(CurTime())>EndMonth ) { return(0); }
   }
   
   
   double PipValue = MarketInfo(Symbol(),MODE_TICKVALUE);
   if (PipValue==0) { PipValue=5; }
   
   if (PreviousOpenOrders>OpenOrders) 
   {	  
	  for(cnt=OrdersTotal();cnt>=0;cnt--)
	  {
	     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  	  mode=OrderType();
		  if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) 
		  {
			if (mode==OP_BUY) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Blue); }
			if (mode==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),slippage,Red); }
			return(0);
		 }
	  }
   }

   PreviousOpenOrders=OpenOrders;
   if (OpenOrders>=MaxTrades) 
   {
	  ContinueOpening=False;
   } else {
	  ContinueOpening=True;
   }

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

   if (OpenOrders<1) 
   {
     myOrderType=OpenOrdersBasedOnTrendRSX();
 	  if (ReverseCondition==1)
	  {
	  	  if (myOrderType==1) { myOrderType=2; }
		  else { if (myOrderType==2) { myOrderType=1; } }
	  }
   }
   
   
   Check_Trend();

   // if we have opened positions we take care of them
   for(cnt=OrdersTotal();cnt>=0;cnt--)
   {
     OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) 
	  {	
	  	  if (OrderType()==OP_SELL) 
	  	  {			
	  	  	  if (TrailingStop>0) 
			  {
				  if (OrderOpenPrice()-Ask>=(TrailingStop+Pips)*Point) 
				  {						
					 if (OrderStopLoss()>(Ask+Point*TrailingStop))
					 {			
					    OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderClosePrice()-TakeProfit*Point-TrailingStop*Point,800,Purple);
	  					 return(0);	  					
	  				 }
	  			  }
			  }
	  	  }
   
	  	  if (OrderType()==OP_BUY)
	  	  {
	  		 if (TrailingStop>0) 
	  		 {
			   if (Bid-OrderOpenPrice()>=(TrailingStop+Pips)*Point) 
				{
					if (OrderStopLoss()<(Bid-Point*TrailingStop)) 
					{					   
					   OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderClosePrice()+TakeProfit*Point+TrailingStop*Point,800,Yellow);
                  return(0);
					}
  				}
			 }
	  	  }
   	}
   }
   
   Profit=0;
   LastTicket=0;
   LastType=0;
	LastClosePrice=0;
	LastLots=0;	
	for(cnt=0;cnt<OrdersTotal();cnt++)
	{
	  OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
	  if (OrderSymbol()==Symbol() && OrderMagicNumber() == Magic) 
	  {			
	  	   LastTicket=OrderTicket();
			if (OrderType()==OP_BUY) { LastType=OP_BUY; }
			if (OrderType()==OP_SELL) { LastType=OP_SELL; }
			LastClosePrice=OrderClosePrice();
			LastLots=OrderLots();
			if (LastType==OP_BUY) 
			{
				//Profit=Profit+(Ord(cnt,VAL_CLOSEPRICE)-Ord(cnt,VAL_OPENPRICE))*PipValue*Ord(cnt,VAL_LOTS);				
				if (OrderClosePrice()<OrderOpenPrice()) 
					{ Profit=Profit-(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; }
				if (OrderClosePrice()>OrderOpenPrice()) 
					{ Profit=Profit+(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; }
			}
			if (LastType==OP_SELL) 
			{
				//Profit=Profit+(Ord(cnt,VAL_OPENPRICE)-Ord(cnt,VAL_CLOSEPRICE))*PipValue*Ord(cnt,VAL_LOTS);
				if (OrderClosePrice()>OrderOpenPrice()) 
					{ Profit=Profit-(OrderClosePrice()-OrderOpenPrice())*OrderLots()/Point; }
				if (OrderClosePrice()<OrderOpenPrice()) 
					{ Profit=Profit+(OrderOpenPrice()-OrderClosePrice())*OrderLots()/Point; }
			}
			//Print(Symbol,":",Profit,",",LastLots);
	  }
   }
	
	Profit=Profit*PipValue;
	text2="Profit: $"+DoubleToStr(Profit,2)+" +/-";
   if (OpenOrders>=(MaxTrades-OrderstoProtect) && AccountProtection==1) 
   {	    
	     //Print(Symbol,":",Profit);
	     if (Profit>=SecureProfit) 
	     {
	        OrderClose(LastTicket,LastLots,LastClosePrice,slippage,Yellow);		 
	        ContinueOpening=False;
	        return(0);
	     }
   }

      if (!IsTesting()) 
      {
	     if (myOrderType==3) { text="No conditions to open trades"; }
	     else { text="                         "; }
	     Comment("LastPrice=",LastPrice," Previous open orders=",PreviousOpenOrders,"   Trend Direction: ",TrendTxt,"  Slope == ",TrendVal,"\nContinue opening=",ContinueOpening," OrderType=",myOrderType,"\n",text2,"\nLots=",lotsi,"\n",text);
      }

      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 (InitialStop==0) { sl=0; }
		    else { sl=NormalizeDouble(SellPrice+InitialStop*Point + (MaxTrades-OpenOrders)*Pips*Point, Digits);  }
		    if (OpenOrders!=0) 
		    {
			   mylotsi=lotsi;			
			   for(cnt=1;cnt<=OpenOrders;cnt++)
			   {
			     if (FiboProgression)  
			       mylotsi=MathRound(MathPow(1.6180339,cnt+1)/MathSqrt(5))*lotsi;  // Fibonacci progression by Tross
              else  
                mylotsi=NormalizeDouble(mylotsi*2,2);   // Martingale progression
			   }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    OrderSend(Symbol(),OP_SELL,mylotsi,SellPrice,slippage,sl,tp,"RF1",Magic,0,Red);		    		    
		    return(0);
	     }
      }
      
      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 (InitialStop==0)  { sl=0; }
		    else { sl=NormalizeDouble(BuyPrice-InitialStop*Point - (MaxTrades-OpenOrders)*Pips*Point, Digits); }
		    if (OpenOrders!=0) {
			   mylotsi=lotsi;			
			   for(cnt=1;cnt<=OpenOrders;cnt++)
			   {
			     if (FiboProgression)  
			       mylotsi=MathRound(MathPow(1.6180339,cnt+1)/MathSqrt(5))*lotsi;  // Fibonacci progression by Tross
              else  
                mylotsi=NormalizeDouble(mylotsi*2,2);   // Martingale progression
			   }
		    } else { mylotsi=lotsi; }
		    if (mylotsi>100) { mylotsi=100; }
		    OrderSend(Symbol(),OP_BUY,mylotsi,BuyPrice,slippage,sl,tp,"RF1",Magic,0,Blue);		    
		    return(0);
	     }
      }   

   return(0);
  }
  
//+---------------------------------------- End of mainline order processing logic  ---------------------------------+


int OpenOrdersBasedOnTrendRSX()
{
      int myOrderType=3;
   
      Check_Trend();
         
      double rsxcurr = iCustom(Symbol(),Period(),"Turbo_JRSX",RSX_Period,0,0);
      double rsxprev = iCustom(Symbol(),Period(),"Turbo_JRSX",RSX_Period,0,1);
      if ((rsxcurr > rsxprev) && (trendtype == 2 || trendtype == 3)) { myOrderType = 2; }
      if ((rsxcurr < rsxprev) && (trendtype == 2 || trendtype == 1)) { myOrderType = 1; }
      return(myOrderType);
     
}

void Check_Trend()

{
  UpTrendVal = iCustom(Symbol(),Period(), "Turbo_JVEL",7,-100,0,0);
  DnTrendVal = iCustom(Symbol(),Period(), "Turbo_JVEL",7,-100,1,0);
  TrendVal = (UpTrendVal + DnTrendVal);
  Comment("LastPrice=",LastPrice," Previous open orders=",PreviousOpenOrders,"   Trend Direction: ",TrendTxt,"  Slope == ",TrendVal,"\nContinue opening=",ContinueOpening," OrderType=",myOrderType,"\n",text2,"\nLots=",lotsi,"\n",text);
  if(TrendVal <= -0.09)
      {
       trendtype = 1;
       TrendTxt = "Strong Downtrend";
      } 
  if(TrendVal > -0.09 && TrendVal < 0)
      {
       trendtype = 2;
       TrendTxt = "Weak Downtrend/Ranging";
      }
  if(TrendVal > 0 && TrendVal < 0.09)
      {
       trendtype = 2;
       TrendTxt = "Weak Uptrend/Ranging";
      } 
  if(TrendVal >= 0.09)
      {
       trendtype = 3;
       TrendTxt = "Strong Uptrend";  
      }
  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 ---