#define KEY_LEFT 37 #define KEY_UP 38 #define KEY_RIGHT 39 #define KEY_DOWN 40 //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnInit() { Comment("PRESS ' UP ARROW ' TO DISPLAY BOTH ORDERS"+ " "+"\nPRESS ' DOWN ARROW ' TO CLOSE BOTH ORDERS" " "+"\nPRESS ' LEFT ARROW ' TO CLOSE BUY AND PLACE NEW BUY ORDERS" " "+"\nPRESS ' RIGHT ARROW ' TO CLOSE SELL AND PLACE NEW SELL ORDERS" " "+"\nMOUSE CLICK ON CHART TO PLACE BUY OR SELL ORDER" ); } //+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ bool Points; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void OnChartEvent(const int id, const long &lparam, const double &dparam, const string &sparam) { if(id==CHARTEVENT_CLICK) { int result_message=MessageBox("BUY ORDER TO BE PLACED PRESS YES ELSE PRESS NO FOR SELL ORDER ?","Warning",MB_YESNOCANCEL); if(result_message==IDYES) { if(OrdersTotal()<2) { Points=OrderSend(Symbol(),0,0.1,OrderOpenPrice(),3,0,0,"AUTO BUY",0,0,clrNONE); OrderPrint(); GlobalVariableSet("BUY VOLUME",OrderLots()); } } if(result_message==IDNO) { if(OrdersTotal()<2) { Points=OrderSend(Symbol(),1,0.1,OrderOpenPrice(),3,0,0,"AUTO SELL",0,0,clrNONE); OrderPrint(); GlobalVariableSet("SELL VOLUME",OrderLots()); } } if(OrdersTotal()>=2 && result_message!=IDCANCEL) { MessageBox("NOT POSSIBLE TO PLACE ORDER THERE IS 2 OR MORE ORDERS PRESENT"); } } if(id==CHARTEVENT_KEYDOWN) { if(lparam==KEY_UP) { BOTH_ORDERS_EXECUTED(); } if(lparam==KEY_DOWN) { CLOSE_ALL_RECORDS(); } if(lparam==KEY_LEFT) { BUY_CLOSE_THEN_NEW_BUY(); } if(lparam==KEY_RIGHT) { SELL_CLOSE_THEN_SELL(); } } } //+------------------------------------------------------------------+ void BOTH_ORDERS_EXECUTED() { if(OrdersTotal()==0) { GlobalVariableSet(AccountNumber(),AccountBalance()+10); Points=OrderSend(Symbol(),0,0.1,OrderOpenPrice(),3,0,0,"AUTO BUY",0,0,clrNONE); OrderPrint(); GlobalVariableSet("BUY VOLUME",OrderLots()); Points=OrderSend(Symbol(),1,0.1,OrderOpenPrice(),3,0,0,"AUTO SELL",0,0,clrNONE); OrderPrint(); GlobalVariableSet("SELL VOLUME",OrderLots()); } if(OrdersTotal()>0) {MessageBox("WILL NOT EXECUTE THERE IS "+OrdersTotal()+" RECORD");} } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void CLOSE_ALL_RECORDS() { if(AccountProfit()>0) { Points=OrderSelect(0,SELECT_BY_POS); int TN1=OrderTicket(); Points=OrderSelect(1,SELECT_BY_POS); int TN2=OrderTicket(); Points=OrderCloseBy(TN1,TN2,clrNONE); OrderPrint(); } if(AccountProfit()<0) {MessageBox("NOT SATISFIED");} } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void BUY_CLOSE_THEN_NEW_BUY() { double BV; Points=OrderSelect(0,SELECT_BY_POS); if(OrderProfit()>=10 && OrderType()==OP_BUY) { BV=OrderLots(); Points=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,clrNONE); OrderPrint(); Points=OrderSend(Symbol(),0,BV-0.01,OrderOpenPrice(),3,0,0,"AUTO BUY",0,0,clrNONE); OrderPrint(); } //---------------------------------------------- Points=OrderSelect(1,SELECT_BY_POS); if(OrderProfit()>=10 && OrderType()==OP_BUY) { BV=OrderLots(); Points=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,clrNONE); OrderPrint(); Points=OrderSend(Symbol(),0,BV-0.01,OrderOpenPrice(),3,0,0,"AUTO BUY",0,0,clrNONE); OrderPrint(); } if(OrderProfit()<10) {MessageBox("CONDITION NOT MET FOR BUY ORDER");} } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void SELL_CLOSE_THEN_SELL() { double VS; Points=OrderSelect(0,SELECT_BY_POS); if(OrderProfit()>=10 && OrderType()==OP_SELL) { VS=OrderLots(); Points=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,clrNONE); OrderPrint(); Points=OrderSend(Symbol(),1,VS-0.01,OrderOpenPrice(),3,0,0,"AUTO SELL",0,0,clrNONE); OrderPrint(); } //--------------------------------------------------------------------- Points=OrderSelect(1,SELECT_BY_POS); if(OrderProfit()>=10 && OrderType()==OP_SELL) { VS=OrderLots(); Points=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),3,clrNONE); OrderPrint(); Points=OrderSend(Symbol(),1,VS-0.01,OrderOpenPrice(),3,0,0,"AUTO SELL",0,0,clrNONE); OrderPrint(); } MessageBox("CONDITION NOT MET FOR SELL ORDER"); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+