#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()
Sample
Analysis
Market Information Used:
Series array that contains open time of each bar
Indicator Curves created:
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Checks for the total of open orders
It automatically opens orders when conditions are reached
It can change open orders parameters, due to possible stepping strategy
Other Features: