//+------------------------------------------------------------------+ //| Day Trading_PAMXA.mq4 | //| Copyright © 2009, SMERJ ORG | //| http://smerj.ucoz.org | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, SMERJ ORG" #property link "http://smerj.ucoz.org" extern double TakeProfit = 25; extern double Lots = 0; extern double TrailingStop = 0; extern double StopLoss = 50; extern bool UseMM = true; extern bool MicroAcct = false; extern double Risk = 30; double var_96 = 0; string var_240 = ""; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { double stoc2k_0; double AO; double adx_0, adx_1; int cnt, ticket, total; //server Time Comment(var_240,"\nServer Time = ",TimeToStr(TimeCurrent(),TIME_MINUTES)); // initial data checks if(Bars<10) { Print("bars less than 10"); return(0); } if(TakeProfit<10) { Print("TakeProfit less than 10"); return(0); } // to simplify the coding and speed up access AO=iAO(NULL,0,150); adx_0=iADX(NULL,0,14,PRICE_TYPICAL,MODE_SIGNAL,0); adx_1=iADX(NULL,0,14,PRICE_TYPICAL,MODE_SIGNAL,1); stoc2k_0=iStochastic(NULL,0,5,3,3,MODE_SMA,NULL,MODE_MAIN,0); // identifying open orders total=OrdersTotal(); if(total<1) { if(AccountFreeMargin()<(1000*Lots)) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return(0); } // check for long position (BUY) possibility if(AO<0 && adx_0 >= Ask && adx_1<adx_0 && stoc2k_0<20) { ticket=OrderSend(Symbol(),OP_BUY,LotsOptimized(),Ask,3,0,Ask+TakeProfit*Point,0,0,Green); if(ticket>0) Print("Day Trading_PAMXA Buying : ", Symbol()); { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } return(0); } // check for short position (SELL) possibility if(AO>0 && adx_0 >= Ask && adx_1<adx_0 && stoc2k_0>20) { ticket=OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,Bid-TakeProfit*Point,0,0,Red); if(ticket>0) Print("Day Trading_PAMXA Selling : ", Symbol()); { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice()); } return(0); } return(0); } // control of open orders for(cnt=0;cnt<total;cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderType()<=OP_SELL && OrderSymbol()==Symbol()) { if(OrderType()==OP_BUY) { // long positions if(AO>0 && adx_0 >= Ask && adx_1<adx_0 && stoc2k_0>70) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); return(0); } // check for trailing stop if(TrailingStop>0) { if(Bid-OrderOpenPrice()>Point*TrailingStop) { if(OrderStopLoss()<Bid-Point*TrailingStop) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); return(0); } } } } else // short positions { if(AO<0 && adx_0 >= Ask && adx_1<adx_0 && stoc2k_0<35) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); return(0); } // check for trailing stop if(TrailingStop>0) { if((OrderOpenPrice()-Ask)>(Point*TrailingStop)) { if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0)) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red); return(0); } } } } } } return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ double LotsOptimized() { if (UseMM == false) return(Lots); double lots = Lots; int ordtotal = OrdersHistoryTotal(); int losscnt = 0; double var_LotsOptimized_16 = 0; int digits = 1; if (MarketInfo(Symbol(),MODE_LOTSTEP) == 1.0) digits = 1; if (MicroAcct == true) digits = 2; lots = NormalizeDouble(AccountFreeMargin() * Risk / 100.0 / 1000.0,digits); if (var_96 > 0.0) { for (int i = ordtotal - 1; i >= 0; i--) { if (OrderSelect(i,SELECT_BY_POS,MODE_HISTORY) == 0) { Print("Error in history!"); break; } if ((OrderSymbol() != Symbol()) || (OrderType() > OP_SELL)) continue; if (OrderProfit() > 0.0) break; if (OrderProfit() < 0.0) losscnt++; } if (losscnt > 1) lots = NormalizeDouble(lots - lots * losscnt / var_96,1); } if ((lots < 0.1) && (MicroAcct == false)) lots = 0.1; if ((lots < 0.01) && (MicroAcct == true)) lots = 0.01; if (lots > 50.0) lots = 50; return(lots); }
Sample
Analysis
Market Information Used:
Indicator Curves created:
Indicators Used:
Bill Williams Awesome oscillator
Movement directional index
Stochastic oscillator
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It Closes Orders by itself
It can change open orders parameters, due to possible stepping strategy
Checks for the total of closed orders
Other Features: