For strategy tester only. Demo/Live trading requires more order handling code to check for errors and act accordingly.
PHP Code
//+------------------------------------------------------------------+ //| SupersiganlEA.mq4 //+------------------------------------------------------------------+ #property copyright "Copyright © 2011, Whatever" #property link "http://www.??????.com" // Input Parameters extern double Lots = 0.1; extern double Slippage = 2.0; extern double TakeProfit = 30; extern double StopLoss = 20; extern int MagicNr=9502; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { double ArrowUp, ArrowDown; static int iBuyTicket=-1; static int iSellTicket=-1; // Get Supersignal state ArrowUp = iCustom(NULL,0,"supersignals",1,1); ArrowDown = iCustom(NULL,0,"supersignals",0,1); // Open Buy order if previous bar has arrow up signal if (ArrowUp!=EMPTY_VALUE && iBuyTicket<0) { iBuyTicket=OrderSend(Symbol(),OP_BUY,Lots, Ask, Slippage, 0, 0, "Supersignal", MagicNr, NULL, LimeGreen); } // Open Sell order if previous bar has arrow down signal if (ArrowDown!=EMPTY_VALUE && iSellTicket<0) { iSellTicket=OrderSend(Symbol(),OP_SELL,Lots, Bid, Slippage, 0, 0, "Supersignal", MagicNr, NULL, LimeGreen); } // Check SL and TP for BUY ticket if (OrderSelect( iBuyTicket, SELECT_BY_TICKET)==True) { // Close position if SL is Hit if (dPips(Bid,OrderOpenPrice())<=-StopLoss) if ( OrderClose(iBuyTicket,Lots,Bid,Slippage)==True) iBuyTicket=-1; // Close position if TP is Hit if (dPips(Bid,OrderOpenPrice())>=TakeProfit) if ( OrderClose(iBuyTicket,Lots,Bid,Slippage)==True) iBuyTicket=-1; //Print("Buy. Current Pips=",dPips(OrderOpenPrice(),Bid)); } // Check SL and TP for SELL ticket if (OrderSelect( iSellTicket, SELECT_BY_TICKET)==True) { // Close position if SL is Hit if (dPips(OrderOpenPrice(),Ask)>=StopLoss) if ( OrderClose(iSellTicket,Lots,Ask,Slippage)==True) iSellTicket=-1; // Close position if TP is Hit if (dPips(OrderOpenPrice(),Ask)<=-TakeProfit) if ( OrderClose(iSellTicket,Lots,Ask,Slippage)==True) iSellTicket=-1; //Print("Sell. Current Pips=",dPips(OrderOpenPrice(),Bid)); } return(0); } //------------------------------------------------------------ // function: dPips() // Description: Convert a price difference to pips. //------------------------------------------------------------- double dPips(double dPrice1,double dPrice2,bool bAbs=false) { double dPipValue=(dPrice1-dPrice2)/Point; if (bAbs) return( MathAbs(dPipValue)); else return(dPipValue); }
Attached File(s)