//+------------------------------------------------------------------+ //| BrijonSingleTester.mq4 //+------------------------------------------------------------------+ extern int TP=15; extern double MarginRatio=0.025; extern double PositionSize=0.1; extern int MagicNObase = 10000; // this is a stupid part that has to be manually set when attaching EA to a chart. extern int DDistCriteria = 100; // determine if the Dist is profittable and safe w/o drawdown. extern int HDistCriteria = 15; // determine if the Dist is profittable and safe w/o drawdown. extern int breath = 2; extern int SessionStart = 21; extern int SessionEnd = 6; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { double PendingCap, DWL, HWL; int DDist, HDist; PendingCap = Risk(); if (PendingCap <= MarginRatio && ( Hour()>=SessionStart || Hour()<=SessionEnd ) ) // 1. Verify sizing; 2. trade only in Asian Morning. { Print("Current Positions take ", PendingCap, " capital; OK to Trade!"); DWL = WLcollector(1440); // 1440 minute = 1 day HWL = WLcollector(60); // 60 minute = 1 hour if (Ask < DWL) { DDist = (-Ask+DWL)/Point; HDist = (-Ask+HWL)/Point; } else if (Bid > DWL) { DDist = (-DWL+Bid)/Point; HDist = (-HWL+Bid)/Point; } if (DDist>DDistCriteria&&HDist>HDistCriteria ) { placetrades(DWL); } } // PendingCap if, highest if return(0); } // End of 'Start' section //+------------------------------------------------------------------+ double Risk() //output the ratio of position/capital { double riskratio; riskratio = AccountMargin()/AccountFreeMargin(); return(riskratio); } //+------------------------------------------------------------------+ double WLcollector(int MAtimeframe) { double ma5=iMA(NULL,MAtimeframe,5,0,MODE_SMA,PRICE_CLOSE,0); double ma7=iMA(NULL,MAtimeframe,7,0,MODE_SMA,PRICE_CLOSE,0); double ma22=iMA(NULL,MAtimeframe,22,0,MODE_SMA,PRICE_CLOSE,0); double WLoutput = (ma5+ma7+ma22)/3; if (Symbol()=="GBPUSD") { double ma34=iMA(NULL,MAtimeframe,34,0,MODE_SMA,PRICE_CLOSE,0); WLoutput = (ma5+ma7+ma22+ma34)/4; } return(WLoutput); } //+------------------------------------------------------------------+ void placetrades(double DailyWL) { int ticket; int spread=MarketInfo(Symbol(),MODE_SPREAD); if (Ask < DailyWL) { ticket=OrderSend(Symbol(),OP_BUY,PositionSize,Ask,4,0,Ask+(TP+spread+breath)*Point,"Brijon Long Trade",MagicNObase,0,Blue); // Ask - Mountain*Point if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {Print("BUY order opened : ",OrderOpenPrice());} else {Print("Error opening BUY order : ",GetLastError());} } } else if (Bid > DailyWL) { ticket=OrderSend(Symbol(),OP_SELL,PositionSize,Bid,4,0,Bid-(TP+spread+breath)*Point,"Brijon Short Trade",MagicNObase,0,Blue); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) {Print("SELL order opened : ",OrderOpenPrice());} else {Print("Error opening SELL order : ",GetLastError());} } } } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
It automatically opens orders when conditions are reached
Other Features: