Navigation´╝ÜHome > Content >

2MAX_v01.mq4

Time: 2017-05-04 | Download file:2MAX_v01.mq4

/*
+--------+
|2MAX    |
+--------+

Theory of operation
Long term MA against short term MA

TIME FRAME
==========
trying M15

PAIRS
=====
GBPUSD

ENTRY LONG
==========
Fast cross above slow

ENTRY SHORT
===========
Fast cross below slow

EXIT
====
Stop and Reverse

MONEY MANAGEMENT
================
none

RISK MANAGEMENT
===============
none

FAILURE MANAGEMENT
==================
GetLastError on every transaction


VERSION HISTORY
===============
01    - initial concept

*/


// variables declared here are GLOBAL in scope

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

// user input
extern double Lots=0.1;               // how many lots to trade at a time 
extern int    Slippage=2;             // how many pips of slippage can you tolorate
extern int    MASlow=6;
extern int    MAFast=89;
extern double ProfitMade=999;          // how much money do you expect to make
extern double LossLimit=999;           // how much loss can you tolorate
extern double TrailStop=999;          // trailing stop (999=no trailing stop)
extern int    PLBreakEven=999;        // set break even when this many pips are made (999=off)
extern int    StartHour=0;            // your local time to start making trades
extern int    StopHour=24;            // your local time to stop making trades
extern int    BasketProfit=9999;      // if equity reaches this level, close trades
extern int    BasketLoss=9999;        // if equity reaches this negative level, close trades
extern string FileName="2MAXLog";

// naming and numbering
int      MagicNumber  = 200604052129; // allows multiple experts to trade on same account
string   TradeComment = "2MAX_01_";   // comment so multiple EAs can be seen in Account History

// Bar handling
datetime bartime=0;                   // used to determine when a bar has moved
int      bartick=0;                   // number of times bars have moved
int      objtick=0;                   // used to draw objects on the chart

// Trade control
bool TradeAllowed=true;               // used to manage trades


// Min/Max tracking
double maxOrders;
double maxEquity;
double minEquity;




//+-------------+
//| Custom init |
//|-------------+
// Called ONCE when EA is added to chart or recompiled

int init()
  {
   int    i;
   string o;
   //remove the old objects 
   for(i=0; i=StartHour && Hour()<=StopHour)
        {
         TradeAllowed=true;
        }
     }


   OrdersPerSymbol=0;
   for(cnt=OrdersTotal();cnt>=0;cnt--)
     {
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
      if( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber)
        {
         OrdersPerSymbol++;
         if(OrderType()==OP_BUY) {OrdersBUY++;}
         if(OrderType()==OP_SELL){OrdersSELL++;}
        }
     }
   if(OrdersPerSymbol>maxOrders) maxOrders=OrdersPerSymbol;

     
   //+-----------------------------+
   //| Insert your indicator here  |
   //| And set either BUYme or     |
   //| SELLme true to place orders |
   //+-----------------------------+
   
   CmaS=iMA(Symbol(),0,MASlow,0,MODE_SMA,PRICE_OPEN,0);
   PmaS=iMA(Symbol(),0,MASlow,0,MODE_SMA,PRICE_OPEN,1);

   CmaF=iMA(Symbol(),0,MAFast,0,MODE_LWMA,PRICE_OPEN,0);
   PmaF=iMA(Symbol(),0,MAFast,0,MODE_LWMA,PRICE_OPEN,1);
   
   ObjectDelete("xCmaS");
   ObjectCreate("xCmaS", OBJ_TEXT, 0, Time[0], CmaS);
   ObjectSetText("xCmaS","+",15,"Arial",White);

   ObjectDelete("xCmaF");
   ObjectCreate("xCmaF", OBJ_TEXT, 0, Time[0], CmaF);
   ObjectSetText("xCmaF","+",15,"Arial",White);

   ObjectDelete("xPmaS");
   ObjectCreate("xPmaS", OBJ_TEXT, 0, Time[1], PmaS);
   ObjectSetText("xPmaS","+",15,"Arial",White);

   ObjectDelete("xPmaF");
   ObjectCreate("xPmaF", OBJ_TEXT, 0, Time[1], PmaF);
   ObjectSetText("xPmaF","+",15,"Arial",White);

   
   
   if(TradeAllowed && PmaFCmaS)
     {
      CloseEverything();
      //BUYme=true;
      
     }
     
   if(TradeAllowed && PmaF>PmaS && CmaF0)
     {
      FileSeek(myhandle,0,SEEK_END);
      FileWrite(myhandle, mydata);
      FileClose(myhandle);
     }
  } 

Recommend