[ea]goldfish_v06g_Ron_MT4

Author: Ron Thompson
Orders Execution
Checks for the total of open ordersIt automatically opens orders when conditions are reachedIt can change open orders parameters, due to possible stepping strategy
0 Views
0 Downloads
0 Favorites

Profitability Reports

GBP/CAD Oct 2024 - Jan 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%
GBP/USD Oct 2024 - Jan 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%
[ea]goldfish_v06g_Ron_MT4
#property copyright "Ron Thompson"
#property link      "http://www.lightpatch.com/forex"

// This EA is NEVER to be SOLD individually 
// This EA is NEVER to be INCLUDED as part of a collection that is SOLD

//
// goldfish (flopping around like a goldfish out of water)
//

#property copyright "Ron Thompson"
#property link      "http://www.ForexMT4.com/"

// generic user input
extern double Lots=0.1;
extern int TrailStop=30;

// start the flopping at a LONG position
bool FSell=false;  // where to go next
bool FBuy=true;    // for Future Buy/Sell

datetime bartime;
int      bartick=0;
int    Slippage=2;

// File handling
int handle=0;

// naming and numbering
double   MagicNumber  = 200512062015;
string   TradeComment = "goldfish";



//+------------------------------------+
//| Custom init (usually empty on EAs) |
//|------------------------------------|
// Called ONCE when EA is added to chart
// or expert is re-compiled
int init()
  {
   Comment(TradeComment);
  }


//+------------------------------------+
//| Custom deinit(usually empty on EAs)|
//+------------------------------------+
// Called ONCE when EA is removed from chart
int deinit()
  {
   Comment(" ");
  }


//+------------------------------------+
//| EA main code                       |
//+------------------------------------+
// Called EACH TICK

int start()
  {

   double   p=Point;
   double   spread=Ask-Bid;
   int      cnt=0;

   int  OpenOrders=0;   
 
   double gainloss;
   
   double  SL;
   double  TP;
   
   // use bar movement to prevent multiple orders per bar
   if(bartime!=Time[0])
     {
      bartime=Time[0];
      bartick++;
     }

   for(cnt=0; cnt<OrdersTotal(); cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         OpenOrders++;
        }
     }

   //initial direction and catch any stoploss that we missed
   if (OpenOrders==0)
     {
      if (FBuy==true && FSell==false)
        {
		   SL=Ask-(TrailStop*p);
		   TP=0;
         OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,SL,TP,TradeComment+"BUY",MagicNumber,White);
         FBuy=false;
         FSell=true;
        }

      if (FBuy==false && FSell==true)
        {
		   SL=Bid+(TrailStop*p);
		   TP=0;
         OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP,TradeComment+"SELL ",MagicNumber,Red);
         FBuy=true;
         FSell=false;
        }
     }
     
   // Trailing stop
   for(cnt=0; cnt<OrdersTotal(); cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {

         if(OrderType()==OP_BUY)
           {
            gainloss=Bid-OrderStopLoss();

            if ( gainloss > (TrailStop*p) )
              {
               SL=Bid-(TrailStop*p);
               TP=OrderTakeProfit();
               OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP, White);
              }
           }//buy

         if(OrderType()==OP_SELL)
           {
            gainloss=OrderStopLoss()-Ask;

            if ( gainloss > (TrailStop*p) )
              {
               SL=Ask+(TrailStop*p);
               TP=OrderTakeProfit();
               OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP, Red);
              }
           }//sell
           
        } // if(OrderSymbol)
        
     } // for

  } // start()




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