ea_daytripper_03

Author: Ron Thompson

This script is designed to automatically trade on the Forex market based on a moving average indicator. Here's the breakdown:

Overall Goal: The script aims to identify potential buying or selling opportunities by comparing the current price of an asset to its moving average. It then automatically places trades based on these signals.

User-Defined Settings: The script starts by allowing the user to customize a few key parameters:

  • Lots: This determines the size of the trades the script will make. It's essentially how much of your account balance you're willing to risk on each trade.
  • MovingAvg: This is the period for calculating the moving average. A larger number means the average is calculated over a longer period, making it smoother and less sensitive to short-term price fluctuations.
  • filter: This setting acts as a buffer zone around the moving average. The price has to move a certain distance beyond the moving average before the script considers it a valid signal. This helps to avoid false signals caused by minor price fluctuations.
  • TakeProfit: This sets the price at which an open trade will automatically close with a profit. It's a way to lock in gains once the price moves in your favor.
  • StopLoss: This sets the price at which an open trade will automatically close to limit your losses if the price moves against you.

How it Works:

  1. Initialization: The script starts by initializing all of its user configurations

  2. Checking the Market: Before placing any trades, the script performs a few checks:

    • Account Balance: Ensures there's enough available money in your trading account to place the trade.
    • Market History: Verifies that there's enough historical data available to calculate the moving average properly.
    • Market Activity: Checks if a new price bar has been formed, preventing the script from placing redundant orders
  3. Calculating the Moving Average: The script calculates a moving average (MA) using the asset's opening prices and the period specified by the user. It calculates not just the current MA but also the MA from the previous time period.

  4. Generating Trading Signals: It compares the current moving average to the previous moving average. If the current moving average is above the previous one (plus the filter buffer), it signals a potential "buy" opportunity. If the current moving average is below the previous one (minus the filter buffer), it signals a potential "sell" opportunity.

  5. Managing Existing Trades: Before placing new trades, the script checks if there are any existing trades open for the same asset. If there are, and a counter-indicator signal is generated (called CCI), it closes those trades to realize any accumulated gains or minimize losses.

  6. Setting Take Profit and Stop Loss: Before sending a trade, the script calculates take profit and stop loss levels based on user-defined pip value.

  7. Placing Orders: Based on the "buy" or "sell" signals, the script automatically places orders to buy or sell the asset. It sets the trade size according to the "Lots" parameter and includes the specified Stop Loss and Take Profit levels to manage risk and potential profits.

In Summary: The script automates trading decisions based on the relationship between the current price and its moving average. It uses user-defined settings to customize the trading strategy, manage risk, and define profit targets. It essentially takes away the need for manual monitoring and order placement, allowing the script to trade automatically according to the set rules.

Price Data Components
Orders Execution
Checks for the total of open ordersIt Closes Orders by itself It automatically opens orders when conditions are reached
Indicators Used
Moving average indicatorCommodity channel index
5 Views
0 Downloads
0 Favorites

Profitability Reports

AUD/USD Oct 2024 - Jan 2025
84.00 %
Total Trades 1592
Won Trades 0
Lost trades 0
Win Rate 0.00 %
Expected payoff -1.86
Gross Profit 15874.50
Gross Loss -18842.70
Total Net Profit -2968.20
-100%
-50%
0%
50%
100%
GBP/USD Oct 2024 - Jan 2025
20.00 %
Total Trades 635
Won Trades 132
Lost trades 503
Win Rate 0.21 %
Expected payoff -14.57
Gross Profit 2254.10
Gross Loss -11504.20
Total Net Profit -9250.10
-100%
-50%
0%
50%
100%
NZD/USD Oct 2024 - Jan 2025
64.00 %
Total Trades 1590
Won Trades 361
Lost trades 1229
Win Rate 0.23 %
Expected payoff -4.13
Gross Profit 11532.00
Gross Loss -18096.30
Total Net Profit -6564.30
-100%
-50%
0%
50%
100%
ea_daytripper_03
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+-------------------+
//| 1MA Expert        |
//+-------------------+
#property copyright "Ron Thompson"
#property link      "http://www.lightpatch.com/forex"

// User Input
extern double Lots = 0.1;
extern double MovingAvg=10;
extern double filter=0;
extern int   TakeProfit=0;
extern int   StopLoss=0;

// Global scope
      double barmove0 = 0;
      double barmove1 = 0;
       int  risingcnt = 0;
       int fallingcnt = 0;
       int periodcnt  = 0;



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//|------------------------------------------------------------------|

int init()
  {
   return(0);
  }


//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }


//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {

   int     cnt=0;
   double  cMA=0, pMA=0;
   double p=Point();
   double slA,slB,tpA,tpB;
   double cCI=0;
      
   bool    rising=false;
   bool   falling=false;

   // Error checking
   if(AccountFreeMargin()<(1000*Lots))        {return(0);}
   if(Bars<100)                               {return(0);}
   if(barmove0==Open[0] && barmove1==Open[1]) {return(0);}

   // bars moved, update current position
   barmove0=Open[0];
   barmove1=Open[1];
   
   cMA=iMA(Symbol(), 0, MovingAvg, 0, MODE_LWMA, PRICE_OPEN, 0);
   pMA=iMA(Symbol(), 0, MovingAvg, 0, MODE_LWMA, PRICE_OPEN, 1);
   cCI=iCCI(Symbol(), 0, 30, 1,0);

   if (pMA+(filter*p)<cMA) {rising=true;  falling=false;}
   if (pMA-(filter*p)>cMA) {rising=false; falling=true;}
   
   for(cnt=0;cnt<OrdersTotal();cnt++)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol())
        {
         if (OrderType()==0)
           {
            //bought=true;
            if (cCI<0) OrderClose(OrderTicket(),Lots,Bid,0,White);
           }
         if (OrderType()==1) 
           {
            //sold=true;
            if (cCI>0) OrderClose(OrderTicket(),Lots,Ask,0,Red);
           }

        }
     }

   if (TakeProfit==0)
     {
      tpA=0;
      tpB=0;
     }
      else
     {
      tpA=Ask+(p*TakeProfit);
      tpB=Bid-(p*TakeProfit);
     }
     
   if (StopLoss==0)
     {
      slA=0;
      slB=0;
     }
      else
     {
      slA=Ask-(p*StopLoss);
      slB=Bid+(p*StopLoss);
     }
     

   if (rising)  
     {
      OrderSend(Symbol(),OP_BUY,Lots,Ask,3,slA,tpA,"1MA Buy",11123,0,White);
     }
   if (falling)
     {
      OrderSend(Symbol(),OP_SELL,Lots,Bid,3,slB,tpB,"1MA Sell",11321,0,Red);
     }

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